Java BufferedReader Create toBufferedReader(Reader reader)

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

Description

Returns the given reader if it is a BufferedReader , otherwise creates a toBufferedReader for the given reader.

License

Open Source License

Parameter

Parameter Description
reader the reader to wrap or return

Return

the given reader or a new for the given reader

Declaration

public static BufferedReader toBufferedReader(Reader reader) 

Method Source Code


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

import java.io.*;

public class Main {
    /**//from  w w  w . ja v a  2 s .  c o m
     * Returns the given reader if it is a {@link BufferedReader}, otherwise creates a toBufferedReader for the given
     * reader.
     *
     * @param reader
     *            the reader to wrap or return
     * @return the given reader or a new {@link BufferedReader} for the given reader
     * @since 2.2
     */
    public static BufferedReader toBufferedReader(Reader reader) {
        return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader);
    }
}

Related

  1. toBufferedReader(final Reader reader)
  2. toBufferedReader(InputStream is, String charset)
  3. toBufferedReader(Reader reader)
  4. toBufferedReader(Reader reader)
  5. toBufferedReader(Reader reader)
  6. toBufferedReader(String s)