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

intcopyStream(final InputStream inputStream, final OutputStream outputStream)
copy Stream
int result = 0;
final byte[] buf = new byte[BUFFER];
for (;;) {
    final int numRead = inputStream.read(buf);
    if (numRead == -1) {
        break;
    outputStream.write(buf, 0, numRead);
...
voidcopyStream(final InputStream is, final OutputStream os)
copy Stream
byte[] buf = new byte[16 * 1024];
while (true) {
    int len = is.read(buf);
    if (len <= 0) {
        break;
    os.write(buf, 0, len);
booleancopyStream(final InputStream is, final OutputStream os)
Copy a stream to another location
try {
    final byte[] buf = new byte[1024];
    int len;
    while ((len = is.read(buf)) > 0) {
        os.write(buf, 0, len);
    is.close();
    os.close();
...
longcopyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
Copies the length of bytes from the inputstream to the outputStream.
long bytesProcessed = 0;
byte[] buf = new byte[bufferSize];
int bytesReadOut = 0;
while (((amount == null) || (bytesProcessed < amount.longValue())) && (bytesReadOut > -1)) {
    int bytesToRead = bufferSize;
    if (amount != null) {
        long bytesLeft = amount.longValue() - bytesProcessed;
        if ((bytesLeft < bytesToRead)) {
...
longcopyStream(final InputStream source, final OutputStream target)
Copies the supplied InputStream to the provided OutputStream .
long size = 0L;
try {
    final byte[] buffer = new byte[BUFFER_SIZE];
    int length;
    while ((length = source.read(buffer, 0, buffer.length)) >= 0) {
        size += length;
        target.write(buffer, 0, length);
    return size;
} finally {
    close(source);
    close(target);
voidcopyStream(final InputStream src, OutputStream dest)
Writes the content of an input stream to an output stream
byte[] buffer = new byte[1024];
int read = 0;
while ((read = src.read(buffer)) > -1) {
    dest.write(buffer, 0, read);
dest.flush();
voidcopyStream(final OutputStream to, final InputStream from)
Copy one stream to another until the input stream has no more data.
final byte[] buf = new byte[BUF_SIZE];
int len = from.read(buf);
while (len > 0) {
    to.write(buf, 0, len);
    len = from.read(buf);
voidcopyStream(InputStream fis, OutputStream fos)
copy Stream
try {
    byte[] buffer = new byte[0xFFFF];
    for (int len; (len = fis.read(buffer)) != -1;)
        fos.write(buffer, 0, len);
} catch (IOException e) {
    System.err.println(e);
} finally {
    if (fis != null) {
...
longcopyStream(InputStream from, OutputStream to)
copy Stream
long total = 0;
byte[] buf = new byte[2048];
while (true) {
    int r = from.read(buf);
    if (r == -1) {
        break;
    to.write(buf, 0, r);
...
intcopyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut)
copy Stream
try {
    int written = 0;
    byte[] buffer = new byte[16 * 1024];
    int len;
    while ((len = in.read(buffer)) != -1) {
        out.write(buffer, 0, len);
        written += len;
    return written;
} finally {
    try {
        if (closeIn) {
            in.close();
    } finally {
        if (closeOut) {
            out.close();