Search in sources :

Example 1 with FileWriter

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();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FileWriter(java.io.FileWriter) File(java.io.File)

Example 2 with FileWriter

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FileWriter(java.io.FileWriter) File(java.io.File)

Example 3 with FileWriter

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();
}
Also used : FileWriter(java.io.FileWriter) Before(org.junit.Before)

Example 4 with FileWriter

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();
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 5 with FileWriter

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();
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL)

Aggregations

FileWriter (java.io.FileWriter)1776 File (java.io.File)1056 IOException (java.io.IOException)741 BufferedWriter (java.io.BufferedWriter)705 PrintWriter (java.io.PrintWriter)285 Test (org.junit.Test)222 Writer (java.io.Writer)162 FileReader (java.io.FileReader)121 BufferedReader (java.io.BufferedReader)107 ArrayList (java.util.ArrayList)101 FileNotFoundException (java.io.FileNotFoundException)68 Date (java.util.Date)61 Properties (java.util.Properties)61 FileOutputStream (java.io.FileOutputStream)58 HashMap (java.util.HashMap)53 StringWriter (java.io.StringWriter)50 Path (org.apache.hadoop.fs.Path)49 FileInputStream (java.io.FileInputStream)47 Map (java.util.Map)33 OutputStreamWriter (java.io.OutputStreamWriter)31