Java Utililty Methods InputStream to OutputStream

List of utility methods to do InputStream to OutputStream

Description

The list of methods to do InputStream to OutputStream are organized into topic(s).

Method

voidcopyStreams(InputStream from, OutputStream to, int blockSize)
The base for all other methods in this class.
byte[] buffer = new byte[blockSize];
int bytesRead;
while ((bytesRead = from
        .read(buffer) ) != -1 ) {
    to.write(buffer, 0, bytesRead);
from.close();
to.close();
...
voidcopyStreams(InputStream in, OutputStream out)
copy Streams
byte[] b = new byte[8192];
int r;
while ((r = in.read(b)) >= 0)
    out.write(b, 0, r);
booleancopyStreams(InputStream in, OutputStream out)
The actual procedure of copying Streams (like binary files)
if (in == null || out == null)
    return false;
try {
    byte[] buf = new byte[4096];
    int len;
    while ((len = in.read(buf)) > 0)
        out.write(buf, 0, len);
    in.close();
...
voidcopyStreams(InputStream in, OutputStream out)
Copy all data from in to out in 4096 byte chunks.
if (in == null || out == null) {
    throw new IllegalArgumentException();
final byte[] buffer = new byte[4096];
int len;
while (-1 != (len = in.read(buffer, 0, buffer.length))) {
    out.write(buffer, 0, len);
voidcopyStreams(InputStream in, OutputStream out, int buf)
Copy the input from one stream to the output of another until EOF.
copyStreams(in, out, buf, -1);
intcopyStreams(InputStream input, OutputStream output)
Copies bytes from one stream to another
return copyStreams(input, output, -1);
voidcopyStreams(InputStream inputStream, OutputStream outputStream)
Copy the input stream to the output stream
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) >= 0) {
    outputStream.write(buffer, 0, length);
voidcopyStreams(InputStream is, OutputStream os)
copy is to os.
byte[] bytearray = new byte[COPY_BUF_SIZE];
int len = 0;
while ((len = is.read(bytearray)) != -1) {
    os.write(bytearray, 0, len);
voidcopyStreams(InputStream source, OutputStream destination)

Copies the data from the given InputStream to the given OutputStream .

copyStreams(source, destination, true, true);
voidcopyStreams(InputStream source, OutputStream target)
Copies the contents of the source stream to the target stream.
byte[] buffer = new byte[128];
int i = source.read(buffer);
while (i != -1) {
    target.write(buffer, 0, i);
    i = source.read(buffer);