Here you can find the source of copyStream(Reader input, Writer output)
Parameter | Description |
---|---|
input | source of data. |
output | destination of data. |
Parameter | Description |
---|---|
IOException | if any errors occur during copying process. |
public static void copyStream(Reader input, Writer output) throws IOException
//package com.java2s; import java.io.*; public class Main { /**/* ww w. j av a 2s .com*/ * Coping data(character type) from {@code input} reader to {@code output} writer. * * @param input source of data. * @param output destination of data. * @throws IOException if any errors occur during copying process. */ public static void copyStream(Reader input, Writer output) throws IOException { copyStream(input, output, 4096); } /** * Coping data(binary type) from {@code input} stream to {@code output} stream. * * @param input input source of data. * @param output destination of data. * @throws IOException if any errors occur during copying process. */ public static void copyStream(InputStream input, OutputStream output) throws IOException { copyStream(input, output, 4096); } /** * Coping data(character type) from {@code input} reader to {@code output} writer. * * @param input input source of data. * @param output destination of data. * @param buffersize size of buffer with is using for data copy. * @throws IOException if any errors occur during copying process. * @throws IllegalArgumentException if {@code buffersize} less then 1. */ public static void copyStream(Reader input, Writer output, int buffersize) throws IOException, IllegalArgumentException { if (buffersize < 1) { throw new IllegalArgumentException( "buffersize must be greater than 0"); } char[] buffer = new char[buffersize]; int n; while ((n = input.read(buffer)) >= 0) { output.write(buffer, 0, n); } } /** * Coping data(binary type) from {@code input} stream to {@code output} stream. * * @param input input source of data. * @param output destination of data. * @param buffersize size of buffer with is using for data copy. * @throws IOException if any errors occur during copying process. * @throws IllegalArgumentException if {@code buffersize} less then 1. */ public static void copyStream(InputStream input, OutputStream output, int buffersize) throws IOException, IllegalArgumentException { if (buffersize < 1) { throw new IllegalArgumentException( "buffersize must be greater than 0"); } byte[] buffer = new byte[buffersize]; int n; while ((n = input.read(buffer)) >= 0) { output.write(buffer, 0, n); } } }