Here you can find the source of readAll(Reader reader)
Parameter | Description |
---|---|
reader | The Reader to read the input from |
Parameter | Description |
---|---|
IOException | If there is a networking problem |
private static String readAll(Reader reader) throws IOException
//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(); } }