Skip to content
Snippets Groups Projects
Commit f365bd84 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

first version which searches in the classpath the given file and merges

all files into one
parent 12d2890a
No related branches found
No related tags found
No related merge requests found
package teetime.framework;
import java.io.IOException;
import java.util.StringTokenizer;
import java.net.URL;
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 {
final String classpath = System.getProperty("java.class.path");
final String pathSeparator = System.getProperty("path.separator");
// System.out.println(classpath);
// System.out.println(pathSeparator);
StringTokenizer st = new StringTokenizer(classpath, pathSeparator);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());// st.nextToken());
}
PipeFactoryLoader.mergeConfigFiles("LICENSE.txt", "test.txt");
}
public static List<URL> loadResources(final String name) throws IOException {
final List<URL> list = new ArrayList<URL>();
final Enumeration<URL> systemRes = ClassLoader.getSystemClassLoader().getResources(name);
while (systemRes.hasMoreElements()) {
list.add(systemRes.nextElement());
}
return list;
}
}
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.net.URL;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
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);
......@@ -46,4 +56,37 @@ 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);
}
List<URL> files = null;
try {
files = FileSearcher.loadResources(configFileName);
} catch (IOException e) {
throw new IllegalStateException(e);
}
for (URL url : files) {
try {
InputStream is = url.openStream();
ByteStreams.copy(is, os);
is.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment