Search in sources :

Example 6 with FileWriter

use of java.io.FileWriter in project flink by apache.

the class BootstrapTools method writeConfiguration.

/**
	 * Writes a Flink YAML config file from a Flink Configuration object.
	 * @param cfg The Flink config
	 * @param file The File to write to
	 * @throws IOException
	 */
public static void writeConfiguration(Configuration cfg, File file) throws IOException {
    try (FileWriter fwrt = new FileWriter(file);
        PrintWriter out = new PrintWriter(fwrt)) {
        for (String key : cfg.keySet()) {
            String value = cfg.getString(key, null);
            out.print(key);
            out.print(": ");
            out.println(value);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 7 with FileWriter

use of java.io.FileWriter in project flink by apache.

the class FileChannelStreamsTest method testCloseAndDeleteInputView.

@Test
public void testCloseAndDeleteInputView() {
    final IOManager ioManager = new IOManagerAsync();
    try {
        MemoryManager memMan = new MemoryManager(4 * 16 * 1024, 1, 16 * 1024, MemoryType.HEAP, true);
        List<MemorySegment> memory = new ArrayList<MemorySegment>();
        memMan.allocatePages(new DummyInvokable(), memory, 4);
        FileIOChannel.ID channel = ioManager.createChannel();
        // add some test data
        try (FileWriter wrt = new FileWriter(channel.getPath())) {
            wrt.write("test data");
        }
        BlockChannelReader<MemorySegment> reader = ioManager.createBlockChannelReader(channel);
        FileChannelInputView in = new FileChannelInputView(reader, memMan, memory, 9);
        // read just something
        in.readInt();
        // close for the first time, make sure all memory returns
        in.close();
        assertTrue(memMan.verifyEmpty());
        // close again, should not cause an exception
        in.close();
        // delete, make sure file is removed
        in.closeAndDelete();
        assertFalse(new File(channel.getPath()).exists());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        ioManager.shutdown();
    }
}
Also used : IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileIOChannel(org.apache.flink.runtime.io.disk.iomanager.FileIOChannel) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) MemorySegment(org.apache.flink.core.memory.MemorySegment) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) DummyInvokable(org.apache.flink.runtime.operators.testutils.DummyInvokable) File(java.io.File) Test(org.junit.Test)

Example 8 with FileWriter

use of java.io.FileWriter in project hadoop by apache.

the class TestHardLink method makeNonEmptyFile.

private void makeNonEmptyFile(File file, String contents) throws IOException {
    FileWriter fw = new FileWriter(file);
    fw.write(contents);
    fw.close();
}
Also used : FileWriter(java.io.FileWriter)

Example 9 with FileWriter

use of java.io.FileWriter in project flink by apache.

the class CommonTestUtils method printLog4jDebugConfig.

public static void printLog4jDebugConfig(File file) throws IOException {
    try (PrintWriter writer = new PrintWriter(new FileWriter(file))) {
        writer.println("log4j.rootLogger=DEBUG, console");
        writer.println("log4j.appender.console=org.apache.log4j.ConsoleAppender");
        writer.println("log4j.appender.console.target = System.err");
        writer.println("log4j.appender.console.layout=org.apache.log4j.PatternLayout");
        writer.println("log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n");
        writer.println("log4j.logger.org.eclipse.jetty.util.log=OFF");
        writer.println("log4j.logger.org.apache.zookeeper=OFF");
        writer.flush();
    }
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 10 with FileWriter

use of java.io.FileWriter in project flink by apache.

the class WriteFormatAsCsv method write.

@Override
protected void write(String path, ArrayList<IN> tupleList) {
    try (PrintWriter outStream = new PrintWriter(new BufferedWriter(new FileWriter(path, true)))) {
        for (IN tupleToWrite : tupleList) {
            String strTuple = tupleToWrite.toString();
            outStream.println(strTuple.substring(1, strTuple.length() - 1));
        }
    } catch (IOException e) {
        throw new RuntimeException("Exception occured while writing file " + path, e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

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