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));
}
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();
}
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();
}
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);
}
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);
}
}
Aggregations