Example usage for java.io OutputStream write

List of usage examples for java.io OutputStream write

Introduction

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

Prototype

public void write(byte b[], int off, int len) throws IOException 

Source Link

Document

Writes len bytes from the specified byte array starting at offset off to this output stream.

Usage

From source file:Main.java

public static void writeString(OutputStream os, String s) throws IOException {
    byte[] b = s.getBytes("UTF-8");
    writeLong(os, b.length);/*from   ww w . j  av a2 s. co  m*/
    os.write(b, 0, b.length);
}

From source file:Main.java

public static void copyAndClose(InputStream in, OutputStream out) throws IOException {
    byte[] cache = new byte[4096];
    int size;/*from  w w  w  .j a v  a2s.com*/
    while ((size = in.read(cache)) > 0) {
        out.write(cache, 0, size);
    }
    in.close();
    out.close();
}

From source file:Main.java

private static void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[8192];
    int read;//from w w w.  ja  va2s. c o m
    while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
    }
}

From source file:Main.java

public static void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;//from  www  .  j a  va  2s. c  o  m
    while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
    }
}

From source file:Main.java

private static void copy(InputStream in, OutputStream out) throws IOException {
    byte[] b = new byte[IO_BUFFER_SIZE];
    int read;//from   w ww . j  a v a2  s.co m
    while ((read = in.read(b)) != -1) {
        out.write(b, 0, read);
    }
}

From source file:Main.java

/**
 * Write string./*w ww . j a va 2  s.co m*/
 *
 * @param os the os
 * @param s the s
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void writeString(OutputStream os, String s) throws IOException {
    byte[] b = s.getBytes("UTF-8");
    writeLong(os, b.length);
    os.write(b, 0, b.length);
}

From source file:Main.java

static void copyData(InputStream from, OutputStream to) throws IOException {
    byte[] buffer = new byte[1024];
    int length;// ww w. j a va  2s  .  c o m
    while ((length = from.read(buffer)) > 0) {
        to.write(buffer, 0, length);
    }
    to.flush();
    to.close();
    from.close();
}

From source file:Utils.java

/**
 * Copy in stream to an out stream//from   w w  w.j a  v a  2s  .  c o  m
 * 
 * @param in
 * @param out
 * @throws IOException
 */
public static void copyInputStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int len = in.read(buffer);
    while (len >= 0) {
        out.write(buffer, 0, len);
        len = in.read(buffer);
    }
    in.close();
    out.close();
}

From source file:Main.java

public static void copyStream(InputStream is, OutputStream os, byte[] buffer) throws IOException {
    while (true) {
        int count = is.read(buffer);
        if (count != -1) {
            os.write(buffer, 0, count);
        } else {/*from   w ww. ja va2 s . c  o m*/
            return;
        }
    }
}

From source file:Util.java

public static void copyInputstreamToFile(InputStream in, OutputStream out) {
    try {//from  w  w  w .  j  a va2 s .  c om
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (IOException ex) {

    }
}