Search in sources :

Example 16 with BufferedWriter

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

the class TestConfiguration method testGetClass.

public void testGetClass() throws IOException {
    out = new BufferedWriter(new FileWriter(CONFIG));
    startConfig();
    appendProperty("test.class1", "java.lang.Integer");
    appendProperty("test.class2", " java.lang.Integer ");
    endConfig();
    Path fileResource = new Path(CONFIG);
    conf.addResource(fileResource);
    assertEquals("java.lang.Integer", conf.getClass("test.class1", null).getCanonicalName());
    assertEquals("java.lang.Integer", conf.getClass("test.class2", null).getCanonicalName());
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 17 with BufferedWriter

use of java.io.BufferedWriter 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 18 with BufferedWriter

use of java.io.BufferedWriter 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 19 with BufferedWriter

use of java.io.BufferedWriter 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 20 with BufferedWriter

use of java.io.BufferedWriter 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)

Aggregations

BufferedWriter (java.io.BufferedWriter)1557 IOException (java.io.IOException)726 FileWriter (java.io.FileWriter)706 File (java.io.File)629 OutputStreamWriter (java.io.OutputStreamWriter)603 FileOutputStream (java.io.FileOutputStream)291 BufferedReader (java.io.BufferedReader)206 Writer (java.io.Writer)138 InputStreamReader (java.io.InputStreamReader)124 PrintWriter (java.io.PrintWriter)117 ArrayList (java.util.ArrayList)102 FileNotFoundException (java.io.FileNotFoundException)101 Test (org.junit.Test)99 Path (org.apache.hadoop.fs.Path)80 FileReader (java.io.FileReader)78 OutputStream (java.io.OutputStream)65 StringWriter (java.io.StringWriter)58 Path (java.nio.file.Path)58 Date (java.util.Date)57 FileInputStream (java.io.FileInputStream)54