Java InputStream to OutputStream copyStream(InputStream is, OutputStream os)

Here you can find the source of copyStream(InputStream is, OutputStream os)

Description

Copy the data read from the specified input stream to the specified output stream.

License

Apache License

Parameter

Parameter Description
is the input stream to read from.
os the output stream to write to.

Exception

Parameter Description
IOException if an I/O error occurs.

Declaration

public static void copyStream(InputStream is, OutputStream os)
        throws IOException 

Method Source Code

//package com.java2s;
/*/*from  w w  w.  j a v a 2 s.  c om*/
 * JPPF.
 * Copyright (C) 2005-2010 JPPF Team.
 * http://www.jppf.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.*;

public class Main {
    /**
     * Maximum buffer size for reading class files.
     */
    private static final int TEMP_BUFFER_SIZE = 32 * 1024;

    /**
     * Copy the data read from the specified input stream to the specified output stream. 
     * @param is the input stream to read from.
     * @param os the output stream to write to.
     * @throws IOException if an I/O error occurs.
     */
    public static void copyStream(InputStream is, OutputStream os)
            throws IOException {
        byte[] bytes = new byte[TEMP_BUFFER_SIZE];
        while (true) {
            int n = is.read(bytes);
            if (n <= 0)
                break;
            os.write(bytes, 0, n);
        }
    }
}

Related

  1. copyStream(InputStream is, OutputStream os)
  2. copyStream(InputStream is, OutputStream os)
  3. copyStream(InputStream is, OutputStream os)
  4. CopyStream(InputStream is, OutputStream os)
  5. copyStream(InputStream is, OutputStream os)
  6. copyStream(InputStream is, OutputStream os)
  7. copyStream(InputStream is, OutputStream os)
  8. copyStream(InputStream is, OutputStream os)
  9. copyStream(InputStream is, OutputStream os)