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 is, OutputStream os)
Copy data from an InputStream to an OutputStream.
copyStream(is, os, false);
voidcopyStream(InputStream is, OutputStream os)
Copy a stream, using a buffer
copyStream(is, os, new byte[BUFSIZ]);
voidcopyStream(InputStream is, OutputStream os)
Copy the data read from the specified input stream to the specified output stream.
byte[] bytes = new byte[TEMP_BUFFER_SIZE];
while (true) {
    int n = is.read(bytes);
    if (n <= 0)
        break;
    os.write(bytes, 0, n);
longcopyStream(InputStream is, OutputStream os)
Copy contents of one stream onto another
return copyStream(is, os, 8192);
voidcopyStream(InputStream is, OutputStream os)
Copies data.
copyStream(is, os, 1024);
voidCopyStream(InputStream is, OutputStream os)
Copy Stream
final int buffer_size = 1024;
try {
    byte[] bytes = new byte[buffer_size];
    for (;;) {
        int count = is.read(bytes, 0, buffer_size);
        if (count == -1)
            break;
        os.write(bytes, 0, count);
...
voidcopyStream(InputStream is, OutputStream os)
copy Stream
try {
    final int bufSize = 4096;
    byte[] buf = new byte[bufSize];
    int cnt = 0;
    while ((cnt = is.read(buf)) > 0) {
        os.write(buf, 0, cnt);
} catch (IOException ex) {
...
voidcopyStream(InputStream is, OutputStream os, boolean closeInput)
copy Stream
try {
    byte[] bytes = new byte[4096];
    int numBytes;
    while ((numBytes = is.read(bytes)) != -1) {
        os.write(bytes, 0, numBytes);
} finally {
    if (closeInput) {
...
voidcopyStream(InputStream is, OutputStream os, int bufferSize)
Copy input stream to output stream without closing streams.
assert is != null : "input stream is null";
assert os != null : "output stream is null";
byte[] buff = new byte[bufferSize];
int rc;
while ((rc = is.read(buff)) != -1)
    os.write(buff, 0, rc);
os.flush();
voidcopyStream(InputStream is, OutputStream os, long maxLength)
copy Stream
try {
    final int bufSize = 4096;
    byte[] buf = new byte[bufSize];
    int cnt = 0;
    while ((cnt = is.read(buf)) > 0) {
        os.write(buf, 0, cnt);
        maxLength -= cnt;
        if (maxLength < bufSize) {
...