Java Reader Read All readAll(Reader reader)

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

Description

Reads all input by a given Reader and converts it to a String .

License

Open Source License

Parameter

Parameter Description
reader The Reader to read the input from

Exception

Parameter Description
IOException If there is a networking problem

Return

The input as a

Declaration

private static String readAll(Reader reader) throws IOException 

Method Source Code

//package com.java2s;
/*//from ww  w.j av  a2s.  c o m
 * Copyright 2017 saftsau
 *
 * This file is part of xREL4J.
 *
 * xREL4J 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.
 *
 * xREL4J 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 xREL4J. If not, see
 * <http://www.gnu.org/licenses/>.
 */

import java.io.IOException;

import java.io.Reader;

public class Main {
    /**
     * Reads all input by a given {@link Reader} and converts it to a {@link String}.
     * 
     * @param reader The {@link Reader} to read the input from
     * @return The input as a {@link String}
     * @throws IOException If there is a networking problem
     */
    private static String readAll(Reader reader) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        int cp;
        while ((cp = reader.read()) != -1) {
            stringBuilder.append((char) cp);
        }
        return stringBuilder.toString();
    }
}

Related

  1. readAll(Reader in)
  2. readAll(Reader rd)
  3. readAll(Reader rd)
  4. readAll(Reader rd)
  5. readAll(Reader rd)
  6. readAll(Reader reader)
  7. readAll(Reader reader)
  8. ReadAll_Variant1(Reader rd, Writer wr)
  9. readAllChars(Reader reader)