Java InputStream to OutputStream copyStream(InputStream from, OutputStream to)

Here you can find the source of copyStream(InputStream from, OutputStream to)

Description

copy Stream

License

Open Source License

Declaration

public static long copyStream(InputStream from, OutputStream to) throws IOException 

Method Source Code


//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static long copyStream(InputStream from, OutputStream to) throws IOException {
        long total = 0;
        byte[] buf = new byte[2048];
        while (true) {
            int r = from.read(buf);
            if (r == -1) {
                break;
            }//w w w .ja  v  a2s .  c  o m
            to.write(buf, 0, r);
            total += r;
        }
        return total;
    }
}

Related

  1. copyStream(final InputStream is, final OutputStream out, final Long amount, final int bufferSize)
  2. copyStream(final InputStream source, final OutputStream target)
  3. copyStream(final InputStream src, OutputStream dest)
  4. copyStream(final OutputStream to, final InputStream from)
  5. copyStream(InputStream fis, OutputStream fos)
  6. copyStream(InputStream in, boolean closeIn, OutputStream out, boolean closeOut)
  7. copyStream(InputStream in, File outputFile)
  8. copyStream(InputStream in, FileOutputStream out, IProgressMonitor monitor, int length)
  9. copyStream(InputStream in, OutputStream os)