Java OutputStream Write copyBytes(InputStream inputStream, OutputStream outputStream, int size)

Here you can find the source of copyBytes(InputStream inputStream, OutputStream outputStream, int size)

Description

copy Bytes

License

Open Source License

Declaration

static public void copyBytes(InputStream inputStream, OutputStream outputStream, int size) throws IOException 

Method Source Code


//package com.java2s;
/*//w  w  w .  j  av a2s .c  om
 * Copyright 2014.
 * Distributed under the terms of the GPLv3 License.
 *
 * Authors:
 *      Clemens Zeidler <czei002@aucklanduni.ac.nz>
 */

import java.io.*;

public class Main {
    static public int BUFFER_SIZE = 8 * 1024;

    static public void copyBytes(InputStream inputStream, OutputStream outputStream, int size) throws IOException {
        int bufferLength = BUFFER_SIZE;
        byte[] buf = new byte[bufferLength];
        int bytesRead = 0;
        while (bytesRead < size) {
            int requestedBunchSize = Math.min(size - bytesRead, bufferLength);
            int read = inputStream.read(buf, 0, requestedBunchSize);
            bytesRead += read;
            outputStream.write(buf, 0, read);
        }
    }
}

Related

  1. copyBytes(InputStream in, OutputStream out, int buffSize, boolean close)
  2. copyBytes(InputStream input, int size, OutputStream output)
  3. copyBytes(InputStream is, DataOutputStream[] os, long numBytes)
  4. copyBytes(InputStream is, OutputStream bytes)
  5. copyBytes(InputStream iStream, OutputStream oStream)
  6. copyBytesAndClose(final InputStream is, final OutputStream os)