Java Reader Read All readAllQuietly(Reader reader)

Here you can find the source of readAllQuietly(Reader reader)

Description

read All Quietly

License

Common Public License

Declaration

public static String readAllQuietly(Reader reader) 

Method Source Code


//package com.java2s;
/*//from www  . j a  v a  2  s. co m
 * Author: David Corbin
 *
 * Copyright (c) 2005 RubyPeople.
 *
 * This file is part of the Ruby Development Tools (RDT) plugin for eclipse. 
 * RDT is subject to the "Common Public License (CPL) v 1.0". You may not use
 * RDT except in compliance with the License. For further information see 
 * org.rubypeople.rdt/rdt.license.
 */

import java.io.IOException;

import java.io.Reader;

public class Main {
    public static String readAllQuietly(Reader reader) {
        try {
            return readAll(reader);
        } catch (IOException e) {
            throw new RuntimeException();
        }
    }

    public static String readAll(Reader reader) throws IOException {
        StringBuffer result = new StringBuffer();
        char[] buffer = new char[1024];
        while (true) {
            int bytesRead = reader.read(buffer);
            if (bytesRead <= 0)
                return result.toString();
            result.append(buffer, 0, bytesRead);
        }
    }
}

Related

  1. readAllChars(Reader reader)
  2. readAllCharsAndClose(Reader reader)
  3. readAllCharsFromReader(Reader reader)
  4. readAllFrom(final Reader reader)
  5. readAllLines(final BufferedReader br)
  6. readAllToString(Reader reader)