Java BufferedReader Create getReader(final InputStream is, final String enc)

Here you can find the source of getReader(final InputStream is, final String enc)

Description

get Reader

License

Apache License

Return

buffered reader for specified input stream.

Declaration

public static Reader getReader(final InputStream is, final String enc) throws UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/*/*w w w  . j a  va2  s  . c  om*/
 * Copyright 2006-2012 The Scriptella Project Team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedReader;

import java.io.InputStream;
import java.io.InputStreamReader;

import java.io.Reader;

import java.io.UnsupportedEncodingException;

public class Main {
    /**
     * @return buffered reader for specified input stream.
     * @see #getReader(java.io.InputStream, String, boolean)
     */
    public static Reader getReader(final InputStream is, final String enc) throws UnsupportedEncodingException {
        return getReader(is, enc, true);
    }

    /**
     * Returns reader for specified input stream and charset name.
     *
     * @param is       source input stream.
     * @param enc      charset name, null means default.
     * @param buffered true if buffered reader should be used.
     * @return reader for inputstream.
     * @throws UnsupportedEncodingException If the named charset is not supported
     */
    public static Reader getReader(final InputStream is, final String enc, final boolean buffered)
            throws UnsupportedEncodingException {
        Reader r = enc == null ? new InputStreamReader(is) : new InputStreamReader(is, enc);
        return buffered ? new BufferedReader(r) : r;
    }
}

Related

  1. getReader(File file)
  2. getReader(File file)
  3. getReader(File inFile)
  4. getReader(File queryFile)
  5. getReader(final File inputFile)
  6. getReader(final Object aReference, final String aResourceName)
  7. getReader(final String fileName)
  8. getReader(final String fileName)
  9. getReader(InputStream in)