Here you can find the source of readAllCharsFromReader(Reader reader)
public static CharArrayWriter readAllCharsFromReader(Reader reader) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Bruno Medeiros and other Contributors. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . ja v a2s . c o m*/ * Bruno Medeiros - initial implementation *******************************************************************************/ import java.io.CharArrayWriter; import java.io.IOException; import java.io.Reader; public class Main { public static final int EOF = -1; /** Reads and returns all chars from given reader until an EOF is read. * Closes reader afterwards. */ public static CharArrayWriter readAllCharsFromReader(Reader reader) throws IOException { try { final int BUFFER_SIZE = 1024; char[] buffer = new char[BUFFER_SIZE]; CharArrayWriter chars = new CharArrayWriter(); int read; while ((read = reader.read(buffer)) != EOF) { chars.write(buffer, 0, read); } return chars; } finally { reader.close(); } } }