in gshell/gshell-wrapper/src/main/java/org/apache/servicemix/kernel/gshell/wrapper/InstallCommand.java [222:258]
private void copyResourceTo(File outFile, String resource, boolean text) throws Exception {
if( !outFile.exists() ) {
io.out.println("Creating file: @|green "+outFile.getPath()+"|");
InputStream is = InstallCommand.class.getResourceAsStream(resource);
try {
if( text ) {
// Read it line at a time so that we can use the platform line ending when we write it out.
PrintStream out = new PrintStream(new FileOutputStream(outFile));
try {
Scanner scanner = new Scanner(is);
while (scanner.hasNextLine() ) {
String line = scanner.nextLine();
io.out.println("writing: "+line);
out.println(line);
}
} finally {
safeClose(out);
}
} else {
// Binary so just write it out the way it came in.
FileOutputStream out = new FileOutputStream(outFile);
try {
int c=0;
while((c=is.read())>=0) {
out.write(c);
}
} finally {
safeClose(out);
}
}
} finally {
safeClose(is);
}
} else {
io.out.println("@|red File allready exists|. Move it out of the way if you want it re-created: "+outFile.getPath()+"");
}
}