Java Reader Read All readAll(Reader rd)

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

Description

read All

License

Open Source License

Declaration

public static String readAll(Reader rd) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009 xored software, Inc.  
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html  
 *
 * Contributors://from   w w w . j a v  a 2 s.c  o  m
 *     xored software, Inc. - initial API and Implementation (Alex Panchenko)
 *******************************************************************************/

import java.io.IOException;
import java.io.Reader;

public class Main {
    public static String readAll(Reader rd) {
        final StringBuilder buffer = new StringBuilder();
        char[] readBuffer = new char[2048];
        try {
            int n = rd.read(readBuffer);
            while (n > 0) {
                buffer.append(readBuffer, 0, n);
                n = rd.read(readBuffer);
            }
            return buffer.toString();
        } catch (IOException x) {
        }
        return null;
    }
}

Related

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