Java InputStream Read getInputStreamReader(InputStream in, String charset)

Here you can find the source of getInputStreamReader(InputStream in, String charset)

Description

Returns a reader for the specified input stream, using specified encoding.

License

Open Source License

Parameter

Parameter Description
in the input stream to wrap
charset the input stream to wrap

Return

a reader for this input stream

Declaration

public static Reader getInputStreamReader(InputStream in, String charset) 

Method Source Code

//package com.java2s;

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

import java.io.Reader;

import java.io.UnsupportedEncodingException;

public class Main {
    /**/*from  ww w.  j  a  v a  2 s.c  om*/
     * Returns a reader for the specified input stream, using UTF-8 encoding.
     * @param in the input stream to wrap
     * @return a reader for this input stream
     */
    public static Reader getInputStreamReader(InputStream in) {
        return getInputStreamReader(in, "UTF-8");
    }

    /**
     * Returns a reader for the specified input stream, using specified encoding.
     * @param in the input stream to wrap
     * @param charset the input stream to wrap
     * @return a reader for this input stream
     */
    public static Reader getInputStreamReader(InputStream in, String charset) {
        try {
            return new InputStreamReader(in, charset);
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex); // shouldn't happen since UTF-8 is supported by all JVMs per spec
        }
    }
}

Related

  1. getInputStreamFromClassPath(String filename)
  2. getInputStreamFromFile(File pFile)
  3. getInputStreamFromFile(final File file)
  4. getInputStreamFromZip(ZipInputStream zis, String filename)
  5. getInputStreamLength(InputStream in)
  6. getInputStreamReaderAsResource(Class clazz, String fileName)
  7. getInputStreamString(final InputStream in)
  8. getInputStreamToBytes(InputStream is)
  9. inputStreamReadBytesUntil(int endInd, InputStream is, byte[] buf, int off)