Java InputStream to OutputStream copyStream(InputStream input, OutputStream output, int length)

Here you can find the source of copyStream(InputStream input, OutputStream output, int length)

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(InputStream input, OutputStream output, int length) throws IOException 

Method Source Code


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

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

public class Main {
    public static void copyStream(InputStream input, OutputStream output, int length) throws IOException {
        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;/*from  w w  w  .  ja  v a 2 s  .c  o m*/
        }
    }
}

Related

  1. copyStream(InputStream input, OutputStream output)
  2. copyStream(InputStream input, OutputStream output)
  3. copyStream(InputStream input, OutputStream output, boolean closeStreams)
  4. copyStream(InputStream input, OutputStream output, boolean closeStreams)
  5. copyStream(InputStream input, OutputStream output, int bufferSize)
  6. copyStream(InputStream inputStream, OutputStream outputStream)
  7. copyStream(InputStream inputStream, OutputStream outputStream)
  8. copyStream(InputStream inStream, OutputStream outStream)
  9. copyStream(InputStream inStream, OutputStream outStream)