use of java.io.FileWriter in project camel by apache.
the class FileConsumerBeginRenameStrategyTest method testRenameFileExists.
public void testRenameFileExists() throws Exception {
// create a file in inprogress to let there be a duplicate file
File file = new File("target/inprogress");
file.mkdirs();
FileWriter fw = new FileWriter("target/inprogress/london.txt");
try {
fw.write("I was there once in London");
fw.flush();
} finally {
fw.close();
}
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello London");
template.sendBodyAndHeader("file:target/reports", "Hello London", Exchange.FILE_NAME, "london.txt");
mock.assertIsSatisfied();
}
use of java.io.FileWriter in project camel by apache.
the class FileConsumerCommitRenameStrategyTest method testRenameFileExists.
public void testRenameFileExists() throws Exception {
// create a file in done to let there be a duplicate file
File file = new File("target/done");
file.mkdirs();
FileWriter fw = new FileWriter("target/done/london.txt");
try {
fw.write("I was there once in London");
fw.flush();
} finally {
fw.close();
}
MockEndpoint mock = getMockEndpoint("mock:report");
mock.expectedBodiesReceived("Hello London");
template.sendBodyAndHeader("file:target/reports", "Hello London", Exchange.FILE_NAME, "london.txt");
mock.assertIsSatisfied();
oneExchangeDone.matchesMockWaitTime();
// content of file should be Hello London
String content = IOConverter.toString(new File("target/done/london.txt"), null);
assertEquals("The file should have been renamed replacing any existing files", "Hello London", content);
}
use of java.io.FileWriter in project camel by apache.
the class S3ComponentFileTest method setup.
@Before
public void setup() throws Exception {
super.setUp();
testFile = FileUtil.createTempFile("test", "file");
FileWriter writer = new FileWriter(testFile);
writer.write("This is my bucket content.");
writer.close();
}
use of java.io.FileWriter in project groovy by apache.
the class DomToGroovy method main.
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: DomToGroovy infilename [outfilename]");
System.exit(1);
}
Document document = null;
try {
document = parse(args[0]);
} catch (Exception e) {
System.out.println("Unable to parse input file '" + args[0] + "': " + e.getMessage());
System.exit(1);
}
PrintWriter writer = null;
if (args.length < 2) {
writer = new PrintWriter(System.out);
} else {
try {
writer = new PrintWriter(new FileWriter(new File(args[1])));
} catch (IOException e) {
System.out.println("Unable to create output file '" + args[1] + "': " + e.getMessage());
System.exit(1);
}
}
DomToGroovy converter = new DomToGroovy(writer);
converter.out.incrementIndent();
writer.println("#!/bin/groovy");
writer.println();
writer.println("// generated from " + args[0]);
writer.println("System.out << new groovy.xml.StreamingMarkupBuilder().bind {");
converter.print(document);
writer.println("}");
writer.close();
}
use of java.io.FileWriter in project groovy by apache.
the class CompilerPerformanceTest method main.
public static void main(String[] args) throws Exception {
List<File> sources = new ArrayList<>();
List<URL> classpath = new ArrayList<>();
boolean isCp = false;
for (String arg : args) {
if ("-cp".equals(arg)) {
isCp = true;
} else if (isCp) {
classpath.add(new File(arg).toURI().toURL());
} else {
sources.add(new File(arg));
}
}
ScriptCompilationExecuter executer = new ScriptCompilationExecuter(sources.toArray(new File[sources.size()]), classpath);
System.out.println("Using Groovy " + GROOVY_VERSION);
DescriptiveStatistics stats = new DescriptiveStatistics();
for (int i = 0; i < WARMUP + REPEAT; i++) {
if (i < WARMUP) {
System.out.println("Warmup #" + (i + 1));
} else {
System.out.println("Round #" + (i - WARMUP));
}
long dur = executer.execute();
System.gc();
System.out.printf("Compile time = %dms%n", dur);
if (i >= WARMUP) {
stats.addValue((double) dur);
}
}
System.out.println("Compilation took " + stats.getMean() + "ms ± " + stats.getStandardDeviation() + "ms");
FileWriter wrt = new FileWriter(new File("target/compilation-stats.csv"), true);
wrt.append(String.format("%s;%s;%s\n", GROOVY_VERSION, stats.getMean(), stats.getStandardDeviation()));
wrt.close();
}
Aggregations