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 appendStreamToStream(InputStream is, OutputStream os) throws IOException {
    final byte[] buffer = new byte[256];
    try {// www. j  av  a  2 s. com
        int n;
        while ((n = is.read(buffer)) != -1) {
            os.write(buffer, 0, n);
        }
    } finally {
        is.close();
    }
}

From source file:Main.java

private static long copyStream(InputStream input, OutputStream output) throws IOException {
    byte[] buffer = new byte[1024];
    long count = 0;
    int n = 0;//from   w  w w .ja v  a 2s .  c o  m
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
        count += n;
    }
    return count;
}

From source file:Main.java

/**
 * <p>Copies the data from the {@link InputStream} into a {@link OutputStream}</p>
 *
 * @param input  data source stream./*from  w  w w  .  java  2s .com*/
 * @param output target stream.
 *
 * @throws IOException if error happened.
 */
public static void copyStream(InputStream input, OutputStream output) throws IOException {
    byte[] buffer = new byte[BUFFER_SIZE];
    int bytesRead;
    while ((bytesRead = input.read(buffer)) != -1) {
        output.write(buffer, 0, bytesRead);
    }
}

From source file:Main.java

public static long copyLarge(InputStream input, OutputStream output) throws IOException {
    byte[] buffer = new byte[1024 * 4];
    long count = 0;
    int n = 0;//www . j ava2  s  . c o  m
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
        count += n;
    }
    return count;
}

From source file:Utils.java

private static void copyStreams(InputStream input, OutputStream output) throws IOException {
    int count;// w  w  w .  j a va 2s  .  c o  m
    byte data[] = new byte[1024];
    while ((count = input.read(data, 0, 1024)) != -1) {
        output.write(data, 0, count);
    }
}

From source file:Main.java

public static void writeStream(InputStream inputStream, OutputStream outputStream) {
    byte[] buffer = new byte[1024];
    int len = 0;/*  www . j  av a  2 s.  com*/
    try {
        while ((len = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, len);
        }
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

private static int copy(InputStream input, OutputStream output) throws IOException {
    byte[] buffer = new byte[1024 * 4];
    int count = 0;
    int n = 0;/*from  w w  w .  ja  v  a 2 s .c o m*/
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
        count += n;
    }
    return count;
}

From source file:Main.java

public static void streamToStream(InputStream is, OutputStream os) throws IOException {
    final byte[] buffer = new byte[256];
    try {//from  w ww.j  av a2s  .co  m
        int n;
        while ((n = is.read(buffer)) != -1) {
            os.write(buffer, 0, n);
        }
    } finally {
        os.flush();
        os.close();
        is.close();
    }
}

From source file:Main.java

public static File getFileFromInputStream(File file, InputStream ins) throws IOException {
    OutputStream os = new FileOutputStream(file);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
        os.write(buffer, 0, bytesRead);
    }//from  w w  w . j a va 2  s.  co m
    os.close();
    ins.close();
    return file;
}

From source file:Main.java

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