Java InputStream Copy copyBytes(final InputStream is, final OutputStream os)

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

Description

Reads bytes from the given input stream and writes them to the given output stream until the end of the input stream is reached.

License

Open Source License

Parameter

Parameter Description
is the input stream
os the output stream

Exception

Parameter Description
IOException if an I/O error occurs

Declaration

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

Method Source Code

//package com.java2s;
/*/*from   w  w w  .java2  s  . co m*/
 * Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even 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, see http://www.gnu.org/licenses/
 */

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

public class Main {
    /**
     * Reads bytes from the given input stream and writes them to the given output stream until
     * the end of the input stream is reached.
     *
     * @param is the input stream
     * @param os the output stream
     * @throws IOException if an I/O error occurs
     */
    public static void copyBytes(final InputStream is, final OutputStream os) throws IOException {
        while (true) {
            final int b = is.read();
            if (b == -1) {
                break;
            }
            os.write(b);
        }
    }
}

Related

  1. copyByte(InputStream input, OutputStream output)
  2. copyBytes(DataInput in, DataOutput out, int length, byte[] buf)
  3. copyBytes(final byte[] bytes, final OutputStream outputStream)
  4. copyBytes(final InputStream in, final OutputStream out, final int buffSize, final boolean close)
  5. copyBytes(InputStream in, OutputStream out)
  6. copyBytes(InputStream in, OutputStream out, int bufferSize, boolean close)
  7. copyBytes(InputStream in, OutputStream out, int buffSize)
  8. copyLarge(final InputStream input, final OutputStream output)