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);
}
}
}
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();
}
}
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();
}
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();
}
}
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);
}
}
Aggregations