Java InputStream to OutputStream copyStream(InputStream in, OutputStream out, int len)

Here you can find the source of copyStream(InputStream in, OutputStream out, int len)

Description

copy Stream

License

Open Source License

Declaration

static void copyStream(InputStream in, OutputStream out, int len) throws IOException 

Method Source Code

//package com.java2s;
/*//from  w ww .j av  a  2  s. c  o  m
 * Copyright (c) Nmote Ltd. 2004-2015. All rights reserved. 
 * See LICENSE doc in a root of project folder for additional information.
 */

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

public class Main {
    static void copyStream(InputStream in, OutputStream out, int len) throws IOException {
        byte[] buffer = new byte[4096];
        for (int i = 0; i < len;) {
            int toRead = Math.min(buffer.length, len - i);
            int r = in.read(buffer, 0, toRead);
            if (r < 0) {
                throw new EOFException();
            }
            i += r;
            out.write(buffer, 0, r);
        }
    }

    static void copyStream(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[4096];
        for (;;) {
            int r = in.read(buffer);
            if (r < 0) {
                break;
            }
            out.write(buffer, 0, r);
        }
    }
}

Related

  1. copyStream(InputStream in, OutputStream out)
  2. copyStream(InputStream in, OutputStream out, boolean closeIn, boolean closeOut)
  3. copyStream(InputStream in, OutputStream out, boolean closeOut)
  4. copyStream(InputStream in, OutputStream out, int bufferSize)
  5. copyStream(InputStream in, OutputStream out, int bufsize)
  6. copyStream(InputStream in, OutputStream out, JarEntry entry)
  7. copyStream(InputStream in, OutputStream out, long maxLen)
  8. copyStream(InputStream in, OutputStream out, String end)
  9. copyStream(InputStream input, OutputStream output)