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

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

Description

copy Stream

License

Open Source License

Declaration

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

Method Source Code


//package com.java2s;
/* ===============================================================================
 *
 * Part of the InfoglueIDE Project /*from  w ww. j a  v  a  2 s. c o  m*/
 *
 * ===============================================================================
 *
 * Copyright (C) Stefan Sik 2007
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2, as published by the
 * Free Software Foundation. See the file LICENSE.html for more information.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
 *
 * ===============================================================================
 */

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

public class Main {
    private static final int DEFAULT_CHUNKSIZE = 4096;

    public static void copyStream(InputStream in, OutputStream out, int chunkSize) throws IOException {
        byte b[] = new byte[chunkSize];
        int inumber = 0;
        int cnt = 0;
        while (true) {
            inumber = in.read(b);
            cnt += inumber;
            if (inumber <= 0)
                break;
            out.write(b, 0, inumber);
            out.flush();
        }
    }

    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        copyStream(in, out, DEFAULT_CHUNKSIZE);
    }
}

Related

  1. copyStream(InputStream in, OutputStream out)
  2. copyStream(InputStream in, OutputStream out)
  3. copyStream(InputStream in, OutputStream out)
  4. copyStream(InputStream in, OutputStream out)
  5. copyStream(InputStream in, OutputStream out)
  6. copyStream(InputStream in, OutputStream out)
  7. copyStream(InputStream in, OutputStream out, boolean closeIn, boolean closeOut)
  8. copyStream(InputStream in, OutputStream out, boolean closeOut)
  9. copyStream(InputStream in, OutputStream out, int bufferSize)