Here you can find the source of readAllChars(Reader reader)
Parameter | Description |
---|---|
reader | the reader to read from |
Parameter | Description |
---|---|
IOException | If an I/O error occurs |
Char
's
public static char[] readAllChars(Reader reader) throws IOException
//package com.java2s; /*//from w w w.ja v a 2s. c om * Copyright 2004-2009 Luciano Vernaschi * * This file is part of MeshCMS. * * MeshCMS 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. * * MeshCMS 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 MeshCMS. If not, see <http://www.gnu.org/licenses/>. */ import java.io.CharArrayWriter; import java.io.IOException; import java.io.Reader; public class Main { /** * A standard size for buffers. */ public static final int BUFFER_SIZE = 2048; /** * Reads all characters from a reader. * * @param reader the reader to read from * * @return an array of <code>Char</code>'s * * @throws IOException If an I/O error occurs */ public static char[] readAllChars(Reader reader) throws IOException { CharArrayWriter caw = new CharArrayWriter(); char[] cbuf = new char[BUFFER_SIZE]; int n; while ((n = reader.read(cbuf)) != -1) { caw.write(cbuf, 0, n); } return caw.toCharArray(); } }