Search in sources :

Example 46 with Writer

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

the class TestMRIntermediateDataEncryption method createInput.

private void createInput(FileSystem fs, int numMappers, int numLines) throws Exception {
    fs.delete(INPUT_DIR, true);
    for (int i = 0; i < numMappers; i++) {
        OutputStream os = fs.create(new Path(INPUT_DIR, "input_" + i + ".txt"));
        Writer writer = new OutputStreamWriter(os);
        for (int j = 0; j < numLines; j++) {
            // Create sorted key, value pairs.
            int k = j + 1;
            String formattedNumber = String.format("%09d", k);
            writer.write(formattedNumber + " " + formattedNumber + "\n");
        }
        writer.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 47 with Writer

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

the class TestLogsCLI method createContainerLogInLocalDir.

private static void createContainerLogInLocalDir(Path appLogsDir, ContainerId containerId, FileSystem fs, List<String> logTypes) throws Exception {
    Path containerLogsDir = new Path(appLogsDir, containerId.toString());
    if (fs.exists(containerLogsDir)) {
        fs.delete(containerLogsDir, true);
    }
    assertTrue(fs.mkdirs(containerLogsDir));
    for (String logType : logTypes) {
        Writer writer = new FileWriter(new File(containerLogsDir.toString(), logType));
        writer.write(logMessage(containerId, logType));
        writer.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileWriter(java.io.FileWriter) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) FileWriter(java.io.FileWriter)

Example 48 with Writer

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

the class TestMapReduceLazyOutput method createInput.

public void createInput(FileSystem fs, int numMappers) throws Exception {
    for (int i = 0; i < numMappers; i++) {
        OutputStream os = fs.create(new Path(INPUTPATH, "text" + i + ".txt"));
        Writer wr = new OutputStreamWriter(os);
        for (String inp : INPUTLIST) {
            wr.write(inp + "\n");
        }
        wr.close();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 49 with Writer

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

the class TestStreamingBadRecords method createInput.

private void createInput() throws Exception {
    OutputStream os = getFileSystem().create(new Path(getInputDir(), "text.txt"));
    Writer wr = new OutputStreamWriter(os);
    //increasing the record size so that we have stream flushing
    String prefix = new String(new byte[20 * 1024]);
    for (int i = 1; i <= INPUTSIZE; i++) {
        String str = "" + i;
        int zerosToPrepend = 3 - str.length();
        for (int j = 0; j < zerosToPrepend; j++) {
            str = "0" + str;
        }
        wr.write(prefix + "hey" + str + "\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 50 with Writer

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

the class ConfServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (!HttpServer.isInstrumentationAccessAllowed(getServletContext(), request, response)) {
        return;
    }
    String format = request.getParameter(FORMAT_PARAM);
    if (null == format) {
        format = FORMAT_XML;
    }
    if (FORMAT_XML.equals(format)) {
        response.setContentType("text/xml; charset=utf-8");
    } else if (FORMAT_JSON.equals(format)) {
        response.setContentType("application/json; charset=utf-8");
    }
    Writer out = response.getWriter();
    try {
        writeResponse(getConfFromContext(), out, format);
    } catch (BadFormatException bfe) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, bfe.getMessage());
    }
    out.close();
}
Also used : Writer(java.io.Writer)

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