diff --git a/src/main/java/teetime/framework/FileSearcher.java b/src/main/java/teetime/framework/FileSearcher.java index cdc251017bdc0e2ea8ff5315557e5ed8334be766..adce07e3d0a0c8b9544bb93a588d5ee322137d29 100644 --- a/src/main/java/teetime/framework/FileSearcher.java +++ b/src/main/java/teetime/framework/FileSearcher.java @@ -6,15 +6,8 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; -import teetime.framework.pipe.PipeFactoryLoader; - public class FileSearcher { - public static void main(final String[] args) throws IOException { - - PipeFactoryLoader.mergeConfigFiles("LICENSE.txt", "test.txt"); - } - public static List<URL> loadResources(final String name) throws IOException { final List<URL> list = new ArrayList<URL>(); diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java index a685ee18e40f59df363ba3d05e5cb5015b9a3654..54cf5e290672af6f5defdfae508bc01242d7da90 100644 --- a/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java +++ b/src/main/java/teetime/framework/pipe/PipeFactoryLoader.java @@ -1,12 +1,9 @@ package teetime.framework.pipe; import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.util.LinkedList; import java.util.List; @@ -16,9 +13,6 @@ import org.slf4j.LoggerFactory; import teetime.framework.FileSearcher; -import com.google.common.io.ByteStreams; -import com.google.common.io.Files; - public class PipeFactoryLoader { private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryLoader.class); @@ -27,10 +21,10 @@ public class PipeFactoryLoader { // utility class } - public static List<IPipeFactory> loadFromFile(final String fileName) throws IOException { + public static List<IPipeFactory> loadFromStream(final InputStream stream) throws IOException { List<IPipeFactory> pipeFactories = new LinkedList<IPipeFactory>(); - BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName)); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream)); try { String line; while (null != (line = bufferedReader.readLine())) { @@ -57,20 +51,9 @@ public class PipeFactoryLoader { return pipeFactories; } - public static void mergeConfigFiles(final String configFileName, final String mergedFileName) { - File output = new File(mergedFileName); - FileOutputStream os; - try { - os = new FileOutputStream(output); - } catch (FileNotFoundException e1) { - throw new IllegalStateException(e1); - } - try { - Files.touch(output); - } catch (IOException e) { - throw new IllegalStateException(e); - } + public static List<IPipeFactory> mergeConfigFiles(final String configFileName) { + List<IPipeFactory> pipeFactories = new LinkedList<IPipeFactory>(); List<URL> files = null; try { @@ -81,12 +64,13 @@ public class PipeFactoryLoader { for (URL url : files) { try { InputStream is = url.openStream(); - ByteStreams.copy(is, os); + pipeFactories.addAll(loadFromStream(is)); is.close(); } catch (IOException e) { throw new IllegalStateException(e); } } + return pipeFactories; } } diff --git a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java b/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java index 44c209205e7a49b025ca61bb7a484dcc073c13a6..b829645bb57721a35a062689db945ffa2f68b4ea 100644 --- a/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java +++ b/src/main/java/teetime/framework/pipe/PipeFactoryRegistry.java @@ -1,6 +1,5 @@ package teetime.framework.pipe; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -49,13 +48,9 @@ public class PipeFactoryRegistry { public static PipeFactoryRegistry INSTANCE = new PipeFactoryRegistry(); private PipeFactoryRegistry() { - try { - List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadFromFile("conf/pipe-factories.conf"); - for (IPipeFactory pipeFactory : pipeFactories) { - this.register(pipeFactory); - } - } catch (IOException e) { - LOGGER.warn("Could not load pipe factories from file", e); + List<IPipeFactory> pipeFactories = PipeFactoryLoader.mergeConfigFiles("pipe-factories.conf"); + for (IPipeFactory pipeFactory : pipeFactories) { + this.register(pipeFactory); } }