Java BufferedReader Create toBufferedReader(Reader reader)

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

Description

Returns the given Reader cast to a BufferedReader if possible, otherwise wraps it into a new BufferedReader .

License

Open Source License

Parameter

Parameter Description
reader a reader to convert to a buffered reader

Exception

Parameter Description
NullPointerException if the argument is null

Return

a buffered reader

Declaration

public static BufferedReader toBufferedReader(Reader reader) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import static com.google.common.base.Preconditions.*;

import java.io.BufferedReader;

import java.io.Reader;

public class Main {
    /**/*from  w  w  w .  ja  v  a2s .  com*/
     * Returns the given {@link Reader} cast to a {@link BufferedReader} if possible,
     * otherwise wraps it into a new {@link BufferedReader}.
     * 
     * @param reader a reader to convert to a buffered reader
     * @return a buffered reader
     * @throws NullPointerException if the argument is null
     */
    public static BufferedReader toBufferedReader(Reader reader) {
        checkNotNull(reader, "reader must not be null");

        if (reader instanceof BufferedReader)
            return (BufferedReader) reader;

        return new BufferedReader(reader);
    }
}

Related

  1. getReaderText(BufferedReader reader)
  2. getStreamReader(InputStream input)
  3. getStreamText(InputStream stream)
  4. toBufferedReader(final Reader reader)
  5. toBufferedReader(InputStream is, String charset)
  6. toBufferedReader(Reader reader)
  7. toBufferedReader(Reader reader)
  8. toBufferedReader(Reader reader)
  9. toBufferedReader(String s)