Java Utililty Methods Reader Read All

List of utility methods to do Reader Read All

Description

The list of methods to do Reader Read All are organized into topic(s).

Method

voidReadAll_Variant1(Reader rd, Writer wr)
Read Al Variant
if (rd == null) {
    throw new Exception("Reader not specified");
if (wr == null) {
    throw new Exception("Writer not specified");
char[] buf = new char[2048];
int nread = 0; 
...
StringreadAllChars(Reader reader)
read All Chars
char[] buffer = new char[2048];
StringBuilder builder = new StringBuilder();
while (true) {
    int read = reader.read(buffer);
    if (read == -1) {
        break;
    builder.append(buffer, 0, read);
...
char[]readAllChars(Reader reader)
Reads all characters from a reader.
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();
StringreadAllCharsAndClose(Reader reader)
read All Chars And Close
try {
    return readAllChars(reader);
} finally {
    safeClose(reader);
CharArrayWriterreadAllCharsFromReader(Reader reader)
Reads and returns all chars from given reader until an EOF is read.
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();
StringreadAllFrom(final Reader reader)
reads all lines in a reader into a single string
final StringBuilder buffer = new StringBuilder();
final char[] inputBuffer = new char[1024];
int readlen;
while ((readlen = reader.read(inputBuffer)) != -1) {
    buffer.append(inputBuffer, 0, readlen);
reader.close();
return buffer.toString();
...
ListreadAllLines(final BufferedReader br)
Read all lines from a reader.
final List<String> allLines = new ArrayList<>();
for (;;) {
    final String line = br.readLine();
    if (line == null) {
        break;
    allLines.add(line);
return allLines;
StringreadAllQuietly(Reader reader)
read All Quietly
try {
    return readAll(reader);
} catch (IOException e) {
    throw new RuntimeException();
StringreadAllToString(Reader reader)
Reads all from a Reader into a String.
char buf[] = new char[4096];
StringBuilder strBuffer = new StringBuilder();
int size = 0;
try {
    while ((size = reader.read(buf)) != -1) {
        strBuffer.append(buf, 0, size);
} finally {
...