Example usage for java.io BufferedWriter write

List of usage examples for java.io BufferedWriter write

Introduction

In this page you can find the example usage for java.io BufferedWriter write.

Prototype

public void write(String s, int off, int len) throws IOException 

Source Link

Document

Writes a portion of a String.

Usage

From source file:com.linkedin.pinot.controller.helix.ControllerTest.java

public static String sendPostRequest(String urlString, String payload)
        throws UnsupportedEncodingException, IOException, JSONException {
    LOGGER.info("Sending POST to " + urlString + " with payload " + payload);
    final long start = System.currentTimeMillis();
    final URL url = new URL(urlString);
    final URLConnection conn = url.openConnection();
    conn.setDoOutput(true);/*w ww. ja va2 s.co m*/
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream(), "UTF-8"));

    writer.write(payload, 0, payload.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);
    }

    final long stop = System.currentTimeMillis();

    LOGGER.info(" Time take for Request : " + payload + " in ms:" + (stop - start));

    return sb.toString();
}

From source file:com.kylinolap.query.test.KylinTestBase.java

protected static void putTextTofile(File file, String sql) throws IOException {
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.write(sql, 0, sql.length());
    writer.close();//from   w w w .j  av  a 2 s . c  om
}