Search in sources :

Example 86 with StringWriter

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

the class JsonSerializer method write.

@Override
public ByteBuffer write(List<Object> data, ByteBuffer buffer) {
    Preconditions.checkArgument(data != null && data.size() == fieldNames.size(), "Invalid schema");
    StringWriter sw = new StringWriter();
    try (JsonGenerator jg = jsonFactory.createGenerator(sw)) {
        jg.writeStartObject();
        for (int i = 0; i < fieldNames.size(); ++i) {
            jg.writeFieldName(fieldNames.get(i));
            jg.writeObject(data.get(i));
        }
        jg.writeEndObject();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return ByteBuffer.wrap(sw.toString().getBytes(StandardCharsets.UTF_8));
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 87 with StringWriter

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

the class ClusterUtils method stringifyError.

public static String stringifyError(Throwable error) {
    StringWriter result = new StringWriter();
    PrintWriter printWriter = new PrintWriter(result);
    error.printStackTrace(printWriter);
    return result.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 88 with StringWriter

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

the class TestTaskLogProcessor method toString.

private String toString(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw, false);
    t.printStackTrace(pw);
    pw.close();
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 89 with StringWriter

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

the class TestMasterStatusServlet method testStatusTemplateWithServers.

@Test
public void testStatusTemplateWithServers() throws IOException {
    setupMockTables();
    List<ServerName> servers = Lists.newArrayList(ServerName.valueOf("rootserver,123,12345"), ServerName.valueOf("metaserver,123,12345"));
    Set<ServerName> deadServers = new HashSet<>(Lists.newArrayList(ServerName.valueOf("badserver,123,12345"), ServerName.valueOf("uglyserver,123,12345")));
    new MasterStatusTmpl().setMetaLocation(ServerName.valueOf("metaserver,123,12345")).setServers(servers).setDeadServers(deadServers).render(new StringWriter(), master);
}
Also used : MasterStatusTmpl(org.apache.hadoop.hbase.tmpl.master.MasterStatusTmpl) StringWriter(java.io.StringWriter) ServerName(org.apache.hadoop.hbase.ServerName) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with StringWriter

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

the class MultiThreadedUpdater method mutate.

public void mutate(Table table, Mutation m, long keyBase, byte[] row, byte[] cf, byte[] q, byte[] v) {
    long start = System.currentTimeMillis();
    try {
        m = dataGenerator.beforeMutate(keyBase, m);
        if (m instanceof Increment) {
            table.increment((Increment) m);
        } else if (m instanceof Append) {
            table.append((Append) m);
        } else if (m instanceof Put) {
            table.checkAndPut(row, cf, q, v, (Put) m);
        } else if (m instanceof Delete) {
            table.checkAndDelete(row, cf, q, v, (Delete) m);
        } else {
            throw new IllegalArgumentException("unsupported mutation " + m.getClass().getSimpleName());
        }
        totalOpTimeMs.addAndGet(System.currentTimeMillis() - start);
    } catch (IOException e) {
        failedKeySet.add(keyBase);
        String exceptionInfo;
        if (e instanceof RetriesExhaustedWithDetailsException) {
            RetriesExhaustedWithDetailsException aggEx = (RetriesExhaustedWithDetailsException) e;
            exceptionInfo = aggEx.getExhaustiveDescription();
        } else {
            StringWriter stackWriter = new StringWriter();
            PrintWriter pw = new PrintWriter(stackWriter);
            e.printStackTrace(pw);
            pw.flush();
            exceptionInfo = StringUtils.stringifyException(e);
        }
        LOG.error("Failed to mutate: " + keyBase + " after " + (System.currentTimeMillis() - start) + "ms; region information: " + getRegionDebugInfoSafe(table, m.getRow()) + "; errors: " + exceptionInfo);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Append(org.apache.hadoop.hbase.client.Append) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) StringWriter(java.io.StringWriter) Increment(org.apache.hadoop.hbase.client.Increment) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put) PrintWriter(java.io.PrintWriter)

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