Java InputStream to OutputStream copyStream(InputStream sourceInputStream, OutputStream targetOutputStream)

Here you can find the source of copyStream(InputStream sourceInputStream, OutputStream targetOutputStream)

Description

copy Stream

License

Open Source License

Declaration

static public void copyStream(InputStream sourceInputStream, OutputStream targetOutputStream) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    static public void copyStream(InputStream sourceInputStream, OutputStream targetOutputStream) throws Exception {
        int length = 1024;
        byte[] bytes = new byte[length];
        int c;/*www  .j  a  v  a 2s.  c  o  m*/
        int total_bytes = 0;

        try {
            while ((c = sourceInputStream.read(bytes)) != -1) {
                total_bytes += c;
                targetOutputStream.write(bytes, 0, c);
            }
        } finally {
            if (sourceInputStream != null)
                try {
                    sourceInputStream.close();
                } catch (Exception e) {
                }
            if (targetOutputStream != null)
                try {
                    targetOutputStream.close();
                } catch (Exception e) {
                }
        }
    }
}

Related

  1. copyStream(InputStream is, OutputStream os, long maxLength)
  2. copyStream(InputStream source, OutputStream dest)
  3. copyStream(InputStream source, OutputStream dest)
  4. copyStream(InputStream source, OutputStream dest)
  5. copyStream(InputStream source, OutputStream destination, byte[] buffer)
  6. copyStream(InputStream sourceStream, OutputStream destinationStream)
  7. copyStream(InputStream sourceStream, OutputStream destinationStream, boolean closeInput, boolean closeOutput)
  8. copyStream(InputStream src, OutputStream dest)
  9. copyStream(InputStream src, OutputStream dest)