Search in sources :

Example 96 with InputStreamReader

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

the class MapReduceTestUtil method readOutput.

// Return output of MR job by reading from the given output directory
public static String readOutput(Path outDir, Configuration conf) throws IOException {
    FileSystem fs = outDir.getFileSystem(conf);
    StringBuffer result = new StringBuffer();
    Path[] fileList = FileUtil.stat2Paths(fs.listStatus(outDir, new Utils.OutputFileUtils.OutputFilesFilter()));
    for (Path outputFile : fileList) {
        LOG.info("Path" + ": " + outputFile);
        BufferedReader file = new BufferedReader(new InputStreamReader(fs.open(outputFile)));
        String line = file.readLine();
        while (line != null) {
            result.append(line);
            result.append("\n");
            line = file.readLine();
        }
        file.close();
    }
    return result.toString();
}
Also used : Path(org.apache.hadoop.fs.Path) InputStreamReader(java.io.InputStreamReader) Utils(org.apache.hadoop.mapred.Utils) ReflectionUtils(org.apache.hadoop.util.ReflectionUtils) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader)

Example 97 with InputStreamReader

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

the class TestMRJobClient method testListAttemptIds.

/**
   * print AttemptIds list 
   */
private void testListAttemptIds(String jobId, Configuration conf) throws Exception {
    CLI jc = createJobClient();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int exitCode = runTool(conf, jc, new String[] { "-list-attempt-ids" }, out);
    assertEquals("Exit code", -1, exitCode);
    exitCode = runTool(conf, jc, new String[] { "-list-attempt-ids", jobId, "MAP", "completed" }, out);
    assertEquals("Exit code", 0, exitCode);
    String line;
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));
    int counter = 0;
    while ((line = br.readLine()) != null) {
        LOG.info("line = " + line);
        counter++;
    }
    assertEquals(1, counter);
}
Also used : CLI(org.apache.hadoop.mapreduce.tools.CLI) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 98 with InputStreamReader

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

the class TestMRJobClient method checkHistoryJSONOutput.

private void checkHistoryJSONOutput(String jobId, ByteArrayOutputStream out) throws IOException, JSONException {
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));
    String line = org.apache.commons.io.IOUtils.toString(br);
    br.close();
    JSONObject json = new JSONObject(line);
    assertEquals(jobId, json.getString("hadoopJob"));
    out.reset();
}
Also used : InputStreamReader(java.io.InputStreamReader) JSONObject(org.codehaus.jettison.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader)

Example 99 with InputStreamReader

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

the class TestMRJobClient method checkHistoryHumanOutput.

private void checkHistoryHumanOutput(String jobId, ByteArrayOutputStream out) throws IOException, JSONException {
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));
    br.readLine();
    String line = br.readLine();
    br.close();
    assertEquals("Hadoop job: " + jobId, line);
    out.reset();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader)

Example 100 with InputStreamReader

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

the class TestMRJobClient method testListTrackers.

/**
   * print tracker list
   */
private void testListTrackers(Configuration conf) throws Exception {
    CLI jc = createJobClient();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int exitCode = runTool(conf, jc, new String[] { "-list-active-trackers", "second parameter" }, out);
    assertEquals("Exit code", -1, exitCode);
    exitCode = runTool(conf, jc, new String[] { "-list-active-trackers" }, out);
    assertEquals("Exit code", 0, exitCode);
    String line;
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray())));
    int counter = 0;
    while ((line = br.readLine()) != null) {
        LOG.info("line = " + line);
        counter++;
    }
    assertEquals(2, counter);
}
Also used : CLI(org.apache.hadoop.mapreduce.tools.CLI) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

InputStreamReader (java.io.InputStreamReader)4181 BufferedReader (java.io.BufferedReader)2938 IOException (java.io.IOException)1843 InputStream (java.io.InputStream)1083 FileInputStream (java.io.FileInputStream)767 ArrayList (java.util.ArrayList)494 URL (java.net.URL)471 File (java.io.File)448 Reader (java.io.Reader)446 Test (org.junit.Test)336 HttpURLConnection (java.net.HttpURLConnection)253 ByteArrayInputStream (java.io.ByteArrayInputStream)231 OutputStreamWriter (java.io.OutputStreamWriter)218 FileNotFoundException (java.io.FileNotFoundException)210 HashMap (java.util.HashMap)171 Socket (java.net.Socket)170 OutputStream (java.io.OutputStream)150 URLConnection (java.net.URLConnection)148 StringWriter (java.io.StringWriter)135 Path (org.apache.hadoop.fs.Path)123