Here you can find the source of getChars(Reader r)
Reader
it can be locale-correct by creating a FileReader (for example) that uses UTF-8 or some other charset.
Parameter | Description |
---|---|
r | the <code>Reader</code> to obtain textual data from |
Parameter | Description |
---|---|
IOException | an exception |
char
private static String getChars(Reader r) throws IOException
//package com.java2s; /*//from w ww .j a va 2 s .c o m * Copyright (c) 2014 tabletoptool.com team. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * rptools.com team - initial implementation * tabletoptool.com team - further development */ import java.io.IOException; import java.io.Reader; import java.io.StringWriter; public class Main { /** * Because this method takes a <code>Reader</code> it can be locale-correct by * creating a FileReader (for example) that uses UTF-8 or some other charset. * * @param r the <code>Reader</code> to obtain textual data from * @return an array of <code>char</code> * @throws IOException */ private static String getChars(Reader r) throws IOException { if (r == null) { throw new IllegalArgumentException("Reader cannot be null"); } try (StringWriter sw = new StringWriter(10 * 1024)) { char[] c = new char[4096]; while (true) { int read = r.read(c); if (read == -1) { break; } sw.write(c, 0, read); } return sw.toString(); } } }