use of java.io.OutputStreamWriter in project pinot by linkedin.
the class PerfBenchmarkDriver method postQuery.
public JSONObject postQuery(String query, String optimizationFlags) throws Exception {
JSONObject requestJson = new JSONObject();
requestJson.put("pql", query);
if (optimizationFlags != null && !optimizationFlags.isEmpty()) {
requestJson.put("debugOptions", "optimizationFlags=" + optimizationFlags);
}
long start = System.currentTimeMillis();
URLConnection conn = new URL(_brokerBaseApiUrl + "/query").openConnection();
conn.setDoOutput(true);
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"))) {
String requestString = requestJson.toString();
writer.write(requestString);
writer.flush();
StringBuilder stringBuilder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
}
long totalTime = System.currentTimeMillis() - start;
String responseString = stringBuilder.toString();
JSONObject responseJson = new JSONObject(responseString);
responseJson.put("totalTime", totalTime);
if (_verbose && (responseJson.getLong("numDocsScanned") > 0)) {
LOGGER.info("requestString: {}", requestString);
LOGGER.info("responseString: {}", responseString);
}
return responseJson;
}
}
use of java.io.OutputStreamWriter in project pinot by linkedin.
the class PostQueryCommand method run.
public String run() throws Exception {
if (_brokerHost == null) {
_brokerHost = NetUtil.getHostAddress();
}
LOGGER.info("Executing command: " + toString());
final JSONObject json = new JSONObject();
json.put("pql", _query);
String brokerUrl = "http://" + _brokerHost + ":" + _brokerPort;
final URLConnection conn = new URL(brokerUrl + "/query").openConnection();
conn.setDoOutput(true);
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));
String request = json.toString();
writer.write(request, 0, request.length());
writer.flush();
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
final StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}
use of java.io.OutputStreamWriter in project jersey by jersey.
the class UnsafeCharsInUriTest method sendGetRequestOverSocket.
private String sendGetRequestOverSocket(final URI baseUri, final String requestLine) throws IOException {
// Low level approach with sockets is used, because common Java HTTP clients are using java.net.URI,
// which fails when unencoded curly bracket is part of the URI
final Socket socket = new Socket(baseUri.getHost(), baseUri.getPort());
final PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), Charset.forName("ISO-8859-1"))));
pw.println(requestLine);
// http request should end with a blank line
pw.println();
pw.flush();
final BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8")));
String lastLine = null;
String line;
while ((line = br.readLine()) != null) {
// read the response and remember the last line
lastLine = line;
}
pw.close();
br.close();
return lastLine;
}
use of java.io.OutputStreamWriter in project ormlite-android by j256.
the class OrmLiteConfigUtil method writeConfigFile.
/**
* Write a configuration file to an output stream with the configuration for classes.
*/
public static void writeConfigFile(OutputStream outputStream, Class<?>[] classes) throws SQLException, IOException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream), 4096);
try {
writeHeader(writer);
for (Class<?> clazz : classes) {
writeConfigForTable(writer, clazz);
}
// NOTE: done is here because this is public
System.out.println("Done.");
} finally {
writer.close();
}
}
use of java.io.OutputStreamWriter in project eweb4j-framework by laiweiwei.
the class PetControlTest method testFreeMarker.
@Test
public void testFreeMarker() throws Exception {
Configuration cfg = new Configuration();
// 指定模板从何处加载的数据源,这里设置成一个文件目录。
cfg.setDirectoryForTemplateLoading(new File("src/test/java/test/ftl"));
// 指定模板如何检索数据模型
cfg.setObjectWrapper(new DefaultObjectWrapper());
Map root = new HashMap();
root.put("user", "Big Joe");
Map latest = new HashMap();
root.put("latestProduct", latest);
latest.put("url", "produces/greenmouse.html");
latest.put("name", "green mouse");
Template template = cfg.getTemplate("hello.html");
Writer out = new OutputStreamWriter(System.out);
template.process(root, out);
out.flush();
}
Aggregations