Here you can find the source of copyStream(InputStream source, OutputStream destination, byte[] buffer)
Parameter | Description |
---|---|
source | The stream providing the data. |
destination | The stream that takes the data. If this is null, all data from source will be read and discarded. |
buffer | The buffer to use for forwarding. If it is null, the method allocates a buffer. |
private static void copyStream(InputStream source, OutputStream destination, byte[] buffer) throws IOException
//package com.java2s; /*/*from w w w . j av a 2 s. co m*/ * Copyright 2003 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Reads all data (until EOF is reached) from the given source to the * destination stream. If the destination stream is null, all data is dropped. * It uses the given buffer to read data and forward it. If the buffer is * null, this method allocates a buffer. * * @param source The stream providing the data. * @param destination The stream that takes the data. If this is null, all * data from source will be read and discarded. * @param buffer The buffer to use for forwarding. If it is null, the method * allocates a buffer. * @exception IOException If reading from the source or writing to the * destination fails. */ private static void copyStream(InputStream source, OutputStream destination, byte[] buffer) throws IOException { if (source == null) { throw new NullPointerException("Argument \"source\" must not be null."); } if (buffer == null) { buffer = new byte[8192]; } if (destination != null) { int bytesRead; while ((bytesRead = source.read(buffer)) >= 0) { destination.write(buffer, 0, bytesRead); } } else { while (source.read(buffer) >= 0) ; } } }