Search in sources :

Example 26 with Writer

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

the class TestLdapGroupsMapping method testExtractPassword.

@Test
public void testExtractPassword() throws IOException {
    File testDir = GenericTestUtils.getTestDir();
    testDir.mkdirs();
    File secretFile = new File(testDir, "secret.txt");
    Writer writer = new FileWriter(secretFile);
    writer.write("hadoop");
    writer.close();
    LdapGroupsMapping mapping = new LdapGroupsMapping();
    Assert.assertEquals("hadoop", mapping.extractPassword(secretFile.getPath()));
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 27 with Writer

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

the class TestBadRecords method createInput.

private void createInput() throws Exception {
    OutputStream os = getFileSystem().create(new Path(getInputDir(), "text.txt"));
    Writer wr = new OutputStreamWriter(os);
    for (String inp : input) {
        wr.write(inp + "\n");
    }
    wr.close();
}
Also used : Path(org.apache.hadoop.fs.Path) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 28 with Writer

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

the class RumenToSLSConverter method generateSLSLoadFile.

private static void generateSLSLoadFile(String inputFile, String outputFile) throws IOException {
    try (Reader input = new InputStreamReader(new FileInputStream(inputFile), "UTF-8")) {
        try (Writer output = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
            ObjectMapper mapper = new ObjectMapper();
            ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
            Iterator<Map> i = mapper.readValues(new JsonFactory().createParser(input), Map.class);
            while (i.hasNext()) {
                Map m = i.next();
                output.write(writer.writeValueAsString(createSLSJob(m)) + EOL);
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileOutputStream(java.io.FileOutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) OutputStreamWriter(java.io.OutputStreamWriter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) FileInputStream(java.io.FileInputStream) OutputStreamWriter(java.io.OutputStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with Writer

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

the class RumenToSLSConverter method generateSLSNodeFile.

@SuppressWarnings("unchecked")
private static void generateSLSNodeFile(String outputFile) throws IOException {
    try (Writer output = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")) {
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        for (Map.Entry<String, Set<String>> entry : rackNodeMap.entrySet()) {
            Map rack = new LinkedHashMap();
            rack.put("rack", entry.getKey());
            List nodes = new ArrayList();
            for (String name : entry.getValue()) {
                Map node = new LinkedHashMap();
                node.put("node", name);
                nodes.add(node);
            }
            rack.put("nodes", nodes);
            output.write(writer.writeValueAsString(rack) + EOL);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) OutputStreamWriter(java.io.OutputStreamWriter) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) OutputStreamWriter(java.io.OutputStreamWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Writer(java.io.Writer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap)

Example 30 with Writer

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

the class TestTaskLogAppender method testTaskLogAppender.

/**
 * test TaskLogAppender 
 */
@SuppressWarnings("deprecation")
@Test(timeout = 5000)
public void testTaskLogAppender() {
    TaskLogAppender appender = new TaskLogAppender();
    System.setProperty(TaskLogAppender.TASKID_PROPERTY, "attempt_01_02_m03_04_001");
    System.setProperty(TaskLogAppender.LOGSIZE_PROPERTY, "1003");
    appender.activateOptions();
    assertEquals(appender.getTaskId(), "attempt_01_02_m03_04_001");
    assertEquals(appender.getTotalLogFileSize(), 1000);
    assertEquals(appender.getIsCleanup(), false);
    // test writer   
    Writer writer = new StringWriter();
    appender.setWriter(writer);
    Layout layout = new PatternLayout("%-5p [%t]: %m%n");
    appender.setLayout(layout);
    Category logger = Logger.getLogger(getClass().getName());
    LoggingEvent event = new LoggingEvent("fqnOfCategoryClass", logger, Priority.INFO, "message", new Throwable());
    appender.append(event);
    appender.flush();
    appender.close();
    assertTrue(writer.toString().length() > 0);
    // test cleanup should not changed 
    appender = new TaskLogAppender();
    appender.setIsCleanup(true);
    appender.activateOptions();
    assertEquals(appender.getIsCleanup(), true);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Category(org.apache.log4j.Category) StringWriter(java.io.StringWriter) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Aggregations

Writer (java.io.Writer)1259 OutputStreamWriter (java.io.OutputStreamWriter)512 IOException (java.io.IOException)414 StringWriter (java.io.StringWriter)300 File (java.io.File)269 FileOutputStream (java.io.FileOutputStream)196 BufferedWriter (java.io.BufferedWriter)178 FileWriter (java.io.FileWriter)174 PrintWriter (java.io.PrintWriter)159 OutputStream (java.io.OutputStream)120 Test (org.junit.Test)109 InputStreamReader (java.io.InputStreamReader)71 ByteArrayOutputStream (java.io.ByteArrayOutputStream)64 BufferedReader (java.io.BufferedReader)62 Reader (java.io.Reader)62 HashMap (java.util.HashMap)59 Map (java.util.Map)59 ArrayList (java.util.ArrayList)58 InputStream (java.io.InputStream)54 Properties (java.util.Properties)39