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

voidcopyStream(InputStream input, OutputStream output)
Copy the data from an InputStream to an OutputStream without closing the stream.
copyStream(input, output, DEFAULT_BUFFER_SIZE);
voidcopyStream(InputStream input, OutputStream output)
Copies the contents of the InputStream into the OutputStream.
try {
    byte[] bytes = new byte[4096];
    int bytesRead = 0;
    while ((bytesRead = input.read(bytes)) >= 0) {
        output.write(bytes, 0, bytesRead);
} catch (IOException e) {
    throw new RuntimeException(e);
...
voidcopyStream(InputStream input, OutputStream output)
copy Stream
byte[] buf = new byte[8192];
int len;
try {
    while ((len = input.read(buf)) > 0) {
        output.write(buf, 0, len);
} catch (IOException x) {
    if (!x.getMessage().equals("Unexpected compressed block length: 1")) {
...
voidcopyStream(InputStream input, OutputStream output)
Allocates a #DEFAULT_BUFFER_SIZE byte[] for use as a temporary buffer and calls #copyStream(InputStream,OutputStream,byte[]) .
copyStream(input, output, new byte[DEFAULT_BUFFER_SIZE]);
intcopyStream(InputStream input, OutputStream output)
copy Stream
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
return count;
...
longcopyStream(InputStream input, OutputStream output, boolean closeStreams)
Copies one stream to another, optionally closing the streams.
long numBytesCopied = 0;
int bufferSize = 32768;
try {
    input = new BufferedInputStream(input, bufferSize);
    byte[] buffer = new byte[bufferSize];
    for (int bytesRead = input.read(buffer); bytesRead != -1; bytesRead = input.read(buffer)) {
        output.write(buffer, 0, bytesRead);
        numBytesCopied += bytesRead;
...
longcopyStream(InputStream input, OutputStream output, boolean closeStreams)
Copies one stream to another, optionally closing the streams.
long numBytesCopied = 0;
int bufferSize = BUFFER_SIZE;
try {
    input = new BufferedInputStream(input, bufferSize);
    byte[] buffer = new byte[bufferSize];
    for (int bytesRead = input.read(buffer); bytesRead != -1; bytesRead = input.read(buffer)) {
        output.write(buffer, 0, bytesRead);
        numBytesCopied += bytesRead;
...
voidcopyStream(InputStream input, OutputStream output, int bufferSize)
copy Stream
try {
    byte[] buf = new byte[bufferSize];
    int len;
    while ((len = input.read(buf)) > 0) {
        output.write(buf, 0, len);
} finally {
    if (input != null) {
...
voidcopyStream(InputStream input, OutputStream output, int length)
copy Stream
byte[] buffer = new byte[length];
int remaining = length;
int bytesRead;
while ((bytesRead = input.read(buffer, 0, remaining)) != -1 && remaining > 0) {
    output.write(buffer, 0, bytesRead);
    remaining -= bytesRead;
voidcopyStream(InputStream inputStream, OutputStream outputStream)
Copies all bytes in given inputStream (until EOF) to given outputStream.
copyStream(inputStream, outputStream, true);