Example usage for java.io OutputStream flush

List of usage examples for java.io OutputStream flush

Introduction

In this page you can find the example usage for java.io OutputStream flush.

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes this output stream and forces any buffered output bytes to be written out.

Usage

From source file:Main.java

public static void writeSCSocketBytes(OutputStream os, byte[] buffer, int len) throws Exception {
    os.write(buffer, 0, len);//from   w ww  .j a  v  a 2s . c  om
    os.flush();
}

From source file:Main.java

public static void sendData(byte[] bytes, BluetoothSocket socket) throws IOException {
    OutputStream out = socket.getOutputStream();
    out.write(bytes, 0, bytes.length);/*  w  w  w.  j  av a2s . c om*/
    out.flush();
    out.close();
}

From source file:Main.java

static void close(OutputStream outputStream) {
    if (outputStream != null) {
        try {/*ww  w .java2s .  co m*/
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            // Do nothing
        }
    }
}

From source file:Main.java

public static void writeFile(File file, byte[] data) throws IOException {
    OutputStream out = new FileOutputStream(file);
    try {// w w  w  . ja  v  a 2  s .  co  m
        out.write(data);
        out.flush();
        out.close();
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            // Do nothing.
        }
    }
}

From source file:com.scorpio4.util.io.StreamCopy.java

public static void copy(InputStream input, OutputStream output) throws IOException {
    IOUtils.copy(input, output);//w  ww  .  ja  va  2  s  .  com
    output.flush();
}

From source file:Main.java

public static void savePicture(byte[] picture) throws IOException {

    OutputStream out = null;
    try {//  w  w  w. j av  a 2 s.com
        out = new FileOutputStream(PICTURE_TEMP_PATH);
        out.write(picture);
        out.flush();

    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:Main.java

public static String tests(String cmd) {
    OutputStream out = process.getOutputStream();

    try {/*ww  w  .  ja  v a2s . com*/

        out.write(cmd.getBytes());
        out.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static String getPosthtml(String posturl, String postData, String encode) {

    String html = "";
    URL url;/*from   ww  w.j  ava  2 s  . co m*/
    try {
        url = new URL(posturl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setRequestProperty("User-Agent", userAgent);

        String postDataStr = postData;
        byte[] bytes = postDataStr.getBytes("utf-8");
        connection.setRequestProperty("Content-Length", "" + bytes.length);
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Cache-Control", "no-cache");
        connection.setDoOutput(true);
        connection.setReadTimeout(timeout);
        connection.setFollowRedirects(true);
        connection.connect();
        OutputStream outStrm = connection.getOutputStream();
        outStrm.write(bytes);
        outStrm.flush();
        outStrm.close();
        InputStream inStrm = connection.getInputStream();

        BufferedReader br = new BufferedReader(new InputStreamReader(inStrm, encode));

        String temp = "";
        while ((temp = br.readLine()) != null) {
            html += (temp + '\n');
        }
        br.close();
        connection.disconnect();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return html;

}

From source file:Main.java

private static void killProcess(String packageName) {
    OutputStream out = process.getOutputStream();
    String cmd = "am force-stop " + packageName + " \n";
    try {/*ww  w.j a v a2s.com*/
        out.write(cmd.getBytes());
        out.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Yak_Hax.Yak_Hax_Mimerme.PostRequest.java

public static String PostBodyRequest(String URL, String JSONRaw, String UserAgent) throws IOException {
    String type = "application/json";
    URL u = new URL(URL);
    HttpURLConnection conn = (HttpURLConnection) u.openConnection();
    conn.setDoOutput(true);/*from w w  w  . j  a  v  a 2 s  .c o m*/
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", type);
    conn.setRequestProperty("User-Agent", UserAgent);
    OutputStream os = conn.getOutputStream();
    os.write(JSONRaw.getBytes());
    os.flush();
    os.close();

    String response = null;
    DataInputStream input = new DataInputStream(conn.getInputStream());
    while (null != ((response = input.readLine()))) {
        input.close();
        return response;
    }
    return null;
}