Here you can find the source of ReadAll_Variant1(Reader rd, Writer wr)
private static void ReadAll_Variant1(Reader rd, Writer wr) throws Throwable
//package com.java2s; /*/*from ww w .j a va2 s . c o m*/ * Copyright (C) 2008-2012 Marco Guazzone * [Distributed Computing System (DCS) Group, * Computer Science Institute, * Department of Science and Technological Innovation, * University of Piemonte Orientale, * Alessandria (Italy)] * * This file is part of dcj-commons. * * dcsj-commons 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. * * dcsj-commons 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 dcsj-commons. If not, see <http://www.gnu.org/licenses/>. */ import java.io.Reader; import java.io.Writer; import java.util.Arrays; public class Main { private static void ReadAll_Variant1(Reader rd, Writer wr) throws Throwable { // preconditions if (rd == null) { throw new Exception("Reader not specified"); } if (wr == null) { throw new Exception("Writer not specified"); } //FIXME: a better way to know an optimal buf length?! char[] buf = new char[2048]; //char[] buf = new char[4096]; int nread = 0; // num of characters read // reads characters to the end while ((nread = rd.read(buf)) != -1) { // writes read characters wr.write(buf, 0, nread); //wr.flush(); // blanks the buffer Arrays.fill(buf, 0, nread, (char) 0); } wr.flush(); } }