Here you can find the source of newReader(InputStream input, Charset encoding)
Parameter | Description |
---|---|
input | the input stream |
encoding | the encoding to use when reading from the input stream |
public static Reader newReader(InputStream input, Charset encoding)
//package com.java2s; /******************************************************************************* * Copyright 2014 uniVocity Software Pty Ltd * * 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.// w ww . ja v a2s . c om ******************************************************************************/ import java.io.*; import java.nio.charset.*; public class Main { /** * Creates a {@link java.io.Reader} from an input stream * @param input the input stream * @return a {@link java.io.Reader} wrapping the given input stream */ public static Reader newReader(InputStream input) { return newReader(input, (Charset) null); } /** * Creates a {@link java.io.Reader} from an input stream * @param input the input stream * @param encoding the encoding to use when reading from the input stream * @return a {@link java.io.Reader} wrapping the given input stream */ public static Reader newReader(InputStream input, String encoding) { return newReader(input, Charset.forName(encoding)); } /** * Creates a {@link java.io.Reader} from an input stream * @param input the input stream * @param encoding the encoding to use when reading from the input stream * @return a {@link java.io.Reader} wrapping the given input stream */ public static Reader newReader(InputStream input, Charset encoding) { if (encoding != null) { return new InputStreamReader(input, encoding); } else { return new InputStreamReader(input); } } /** * Creates a {@link java.io.Reader} for a given a file * @param file the file to be read * @return a {@link java.io.Reader} for reading the given file */ public static Reader newReader(File file) { return newReader(file, (Charset) null); } /** * Creates a {@link java.io.Reader} for a given a file * @param file the file to be read * @param encoding the encoding to be used when reading from the file * @return a {@link java.io.Reader} for reading the given file */ public static Reader newReader(File file, String encoding) { return newReader(file, Charset.forName(encoding)); } /** * Creates a {@link java.io.Reader} for a given a file * @param file the file to be read * @param encoding the encoding to be used when reading from the file * @return a {@link java.io.Reader} for reading the given file */ public static Reader newReader(File file, Charset encoding) { FileInputStream input; try { input = new FileInputStream(file); } catch (FileNotFoundException e) { throw new IllegalArgumentException(e); } return newReader(input, encoding); } }