use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testNullValueProperties.
public void testNullValueProperties() throws Exception {
Configuration conf = new Configuration();
conf.setAllowNullValueProperties(true);
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("attr", "value", true);
appendProperty("attr", "", true);
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
assertEquals("value", conf.get("attr"));
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testCommentsInValue.
public void testCommentsInValue() throws IOException {
out = new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("my.comment", "this <!--comment here--> contains a comment");
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
//two spaces one after "this", one before "contains"
assertEquals("this contains a comment", conf.get("my.comment"));
}
use of java.io.FileWriter in project hadoop by apache.
the class TestConfiguration method testRelativeIncludes.
public void testRelativeIncludes() throws Exception {
tearDown();
String relConfig = new File("./tmp/test-config.xml").getAbsolutePath();
String relConfig2 = new File("./tmp/test-config2.xml").getAbsolutePath();
new File(new File(relConfig).getParent()).mkdirs();
out = new BufferedWriter(new FileWriter(relConfig2));
startConfig();
appendProperty("a", "b");
endConfig();
out = new BufferedWriter(new FileWriter(relConfig));
startConfig();
// Add the relative path instead of the absolute one.
addInclude(new File(relConfig2).getName());
appendProperty("c", "d");
endConfig();
// verify that the includes file contains all properties
Path fileResource = new Path(relConfig);
conf.addResource(fileResource);
assertEquals(conf.get("a"), "b");
assertEquals(conf.get("c"), "d");
// Cleanup
new File(relConfig).delete();
new File(relConfig2).delete();
new File(new File(relConfig).getParent()).delete();
}
use of java.io.FileWriter in project flink by apache.
the class CommonTestUtils method createTempFile.
/**
* Creates a temporary file that contains the given string.
* The file is written with the platform's default encoding.
*
* <p>The temp file is automatically deleted on JVM exit.
*
* @param contents The contents to be written to the file.
* @return The temp file URI.
*/
public static String createTempFile(String contents) throws IOException {
File f = File.createTempFile("flink_test_", ".tmp");
f.deleteOnExit();
try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) {
out.write(contents);
}
return f.toURI().toString();
}
use of java.io.FileWriter in project flink by apache.
the class YarnTestBase method writeYarnSiteConfigXML.
public static File writeYarnSiteConfigXML(Configuration yarnConf) throws IOException {
tmp.create();
File yarnSiteXML = new File(tmp.newFolder().getAbsolutePath() + "/yarn-site.xml");
try (FileWriter writer = new FileWriter(yarnSiteXML)) {
yarnConf.writeXml(writer);
writer.flush();
}
return yarnSiteXML;
}
Aggregations