Java Utililty Methods Reader Read

List of utility methods to do Reader Read

Description

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

Method

StringgetReaderAsString(Reader source)
Transforms the contents of the given Reader into a String object.
StringBuilder buffer = new StringBuilder();
char[] charBuffer = new char[1024];
int read;
while ((read = source.read(charBuffer)) != -1) {
    buffer.append(charBuffer, 0, read);
source.close();
return buffer.toString();
...
StringgetReaderContentAsString(Reader reader)
Reads the content of a Reader instance and returns it as a String.
int count;
final char[] buffer = new char[2048];
final StringBuilder out = new StringBuilder();
while ((count = reader.read(buffer, 0, buffer.length)) >= 0) {
    out.append(buffer, 0, count);
return (out.toString());
StringgetReaderContents(Reader reader)
Reads all the characters into a String.
try {
    StringBuffer result = new StringBuffer();
    char[] buffer = new char[2048];
    int read;
    while ((read = reader.read(buffer)) > -1) {
        result.append(buffer, 0, read);
    return result.toString();
...
byte[]load(InputStream input, int bufsize)
Takes the contents of an input stream and returns it as an array of bytes.
ByteArrayOutputStream stm = new ByteArrayOutputStream();
try { 
    copy(input, stm, bufsize);
    return stm.toByteArray();
finally { 
    shutdown(stm);
StringloadChars(Reader in)
Load the characters contained in specified source.
StringBuilder buffer = new StringBuilder();
char[] chars = new char[65536];
int count;
while ((count = in.read(chars, 0, chars.length)) != -1) {
    if (count > 0) {
        buffer.append(chars, 0, count);
return buffer.toString();
StringloadFully(String path)
Loads text content from the given path.
byte[] buf = readBytes(new File(path));
return new String(buf);
voidloadReader(final Reader in, final StringBuffer buffer)
Reads contents of a Reader into a string buffer.
buffer.setLength(0);
int c;
while ((c = in.read()) >= 0) {
    buffer.append((char) c);
StringloadReader(java.io.Reader in)
load Reader
StringBuilder buf = new StringBuilder(2048);
char[] chars = new char[2048];
int len;
while ((len = in.read(chars)) != -1) {
    buf.append(chars, 0, len);
return buf.toString();
StringloadResAsString(String res)
load Res As String
InputStream is = loadRes(res);
return getStreamContentAsString(is, "UTF-8");
char[]loadText(Reader reader, int length)
load Text
char[] chars = new char[length];
int count = 0;
while (count < chars.length) {
    int n = reader.read(chars, count, chars.length - count);
    if (n <= 0)
        break;
    count += n;
if (count == chars.length) {
    return chars;
} else {
    char[] newChars = new char[count];
    System.arraycopy(chars, 0, newChars, 0, count);
    return newChars;