Search in sources :

Example 26 with FileWriter

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"));
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 27 with FileWriter

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"));
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 28 with FileWriter

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();
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 29 with FileWriter

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

Example 30 with FileWriter

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

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