use of java.io.StringWriter in project hive by apache.
the class TestHS2HttpServer 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();
}
use of java.io.StringWriter in project hive by apache.
the class TestScripts method getTemplateResult.
protected static String getTemplateResult(String command, Map<String, String> keyValues) throws IOException {
VelocityContext context = new VelocityContext();
for (String key : keyValues.keySet()) {
context.put(key, keyValues.get(key));
}
StringWriter writer = new StringWriter();
if (!Velocity.evaluate(context, writer, command, command)) {
throw new IOException("Unable to render " + command + " with " + keyValues);
}
writer.close();
return writer.toString();
}
use of java.io.StringWriter in project kafka by apache.
the class Utils method stackTrace.
/**
* Get the stack trace from an exception as a string
*/
public static String stackTrace(Throwable e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
use of java.io.StringWriter in project storm by apache.
the class TestRelNodeCompiler method testFilter.
@Test
public void testFilter() throws Exception {
String sql = "SELECT ID + 1 FROM FOO WHERE ID > 3";
TestCompilerUtils.CalciteState state = TestCompilerUtils.sqlOverDummyTable(sql);
JavaTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
LogicalProject project = (LogicalProject) state.tree();
LogicalFilter filter = (LogicalFilter) project.getInput();
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitFilter(filter, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString("> 3"));
}
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw)) {
RelNodeCompiler compiler = new RelNodeCompiler(pw, typeFactory);
// standalone mode doesn't use inputstreams argument
compiler.visitProject(project, Collections.EMPTY_LIST);
pw.flush();
Assert.assertThat(sw.toString(), containsString(" + 1"));
}
}
use of java.io.StringWriter in project storm by apache.
the class CsvSerializer method write.
@Override
public ByteBuffer write(List<Object> data, ByteBuffer buffer) {
try {
StringWriter writer = new StringWriter();
CSVPrinter printer = new CSVPrinter(writer, CSVFormat.RFC4180);
for (Object o : data) {
printer.print(o);
}
//since using StringWriter, we do not need to close it.
return ByteBuffer.wrap(writer.getBuffer().toString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations