Search in sources :

Example 96 with StringWriter

use of java.io.StringWriter in project hive by apache.

the class TestGenericMR method testKVSplitMap.

public void testKVSplitMap() throws Exception {
    final String in = "k1=v1,k2=v2\nk1=v2,k2=v3";
    final String expected = "k1\tv1\nk2\tv2\nk1\tv2\nk2\tv3\n";
    final StringWriter out = new StringWriter();
    new GenericMR().map(new StringReader(in), out, new Mapper() {

        public void map(String[] record, Output output) throws Exception {
            for (final String kvs : record[0].split(",")) {
                final String[] kv = kvs.split("=");
                output.collect(new String[] { kv[0], kv[1] });
            }
        }
    });
    assertEquals(expected, out.toString());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) NoSuchElementException(java.util.NoSuchElementException)

Example 97 with StringWriter

use of java.io.StringWriter in project hive by apache.

the class TestGenericMR method testWordCountReduce.

public void testWordCountReduce() throws Exception {
    final String in = "hello\t1\nhello\t2\nokay\t4\nokay\t6\nokay\t2";
    final StringWriter out = new StringWriter();
    new GenericMR().reduce(new StringReader(in), out, new Reducer() {

        @Override
        public void reduce(String key, Iterator<String[]> records, Output output) throws Exception {
            int count = 0;
            while (records.hasNext()) {
                count += Integer.parseInt(records.next()[1]);
            }
            output.collect(new String[] { key, String.valueOf(count) });
        }
    });
    final String expected = "hello\t3\nokay\t12\n";
    assertEquals(expected, out.toString());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) NoSuchElementException(java.util.NoSuchElementException)

Example 98 with StringWriter

use of java.io.StringWriter in project hive by apache.

the class TestGenericMR method testIdentityMap.

public void testIdentityMap() throws Exception {
    final String in = "a\tb\nc\td";
    final StringWriter out = new StringWriter();
    new GenericMR().map(new StringReader(in), out, identityMapper());
    assertEquals(in + "\n", out.toString());
}
Also used : StringWriter(java.io.StringWriter) StringReader(java.io.StringReader)

Example 99 with StringWriter

use of java.io.StringWriter in project hive by apache.

the class TestLlapWebServices method getURLResponseAsString.

private String getURLResponseAsString(String baseURL) throws IOException {
    URL url = new URL(baseURL);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
    StringWriter writer = new StringWriter();
    IOUtils.copy(conn.getInputStream(), writer, "UTF-8");
    return writer.toString();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) StringWriter(java.io.StringWriter) URL(java.net.URL)

Example 100 with StringWriter

use of java.io.StringWriter in project hive by apache.

the class InPlaceUpdate method getInPlaceProgressBar.

// [==================>>-----]
private String getInPlaceProgressBar(double percent) {
    StringWriter bar = new StringWriter();
    bar.append("[");
    int remainingChars = PROGRESS_BAR_CHARS - 4;
    int completed = (int) (remainingChars * percent);
    int pending = remainingChars - completed;
    for (int i = 0; i < completed; i++) {
        bar.append("=");
    }
    bar.append(">>");
    for (int i = 0; i < pending; i++) {
        bar.append("-");
    }
    bar.append("]");
    return bar.toString();
}
Also used : StringWriter(java.io.StringWriter)

Aggregations

StringWriter (java.io.StringWriter)3175 PrintWriter (java.io.PrintWriter)1057 Test (org.junit.Test)612 IOException (java.io.IOException)516 StringReader (java.io.StringReader)232 Writer (java.io.Writer)211 StreamResult (javax.xml.transform.stream.StreamResult)207 File (java.io.File)194 InputStreamReader (java.io.InputStreamReader)140 HashMap (java.util.HashMap)136 Transformer (javax.xml.transform.Transformer)125 InputStream (java.io.InputStream)119 Map (java.util.Map)116 ArrayList (java.util.ArrayList)106 DOMSource (javax.xml.transform.dom.DOMSource)99 BufferedReader (java.io.BufferedReader)96 ByteArrayInputStream (java.io.ByteArrayInputStream)84 Reader (java.io.Reader)77 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)75 HttpServletResponse (javax.servlet.http.HttpServletResponse)73