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

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

Description

Copies the contents of the InputStream into the OutputStream.

License

Open Source License

Declaration

public static void copyStream(InputStream input, OutputStream output) 

Method Source Code

//package com.java2s;
/**//w w w  . j  a  v  a2  s.c o  m
 * Copyright (c) 2005-2007 Intalio inc.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Intalio inc. - initial API and implementation
 */

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

public class Main {
    /**
     * Copies the contents of the <code>InputStream</code> into the <code>OutputStream</code>.
     */
    public static void copyStream(InputStream input, OutputStream output) {
        try {
            byte[] bytes = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = input.read(bytes)) >= 0) {
                output.write(bytes, 0, bytesRead);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. copyStream(InputStream input, OutputStream output)
  2. copyStream(InputStream input, OutputStream output)
  3. copyStream(InputStream input, OutputStream output)
  4. copyStream(InputStream input, OutputStream output)
  5. copyStream(InputStream input, OutputStream output)
  6. copyStream(InputStream input, OutputStream output)
  7. copyStream(InputStream input, OutputStream output)
  8. copyStream(InputStream input, OutputStream output)
  9. copyStream(InputStream input, OutputStream output, boolean closeStreams)