/** * @see #inputStreamReadeOf(InputStream, String) */ public static InputStreamReader inputStreamReadeOf(final InputStream input) throws UnsupportedEncodingException { return inputStreamReadeOf(input, encoding()); }
/** * Copies {@link InputStream} to {@link Writer} using buffer and specified encoding. * * @see #copy(Reader, Writer, int) */ public static <T extends Writer> T copy(final InputStream input, final T output, final String encoding, final int count) throws IOException { copy(inputStreamReadeOf(input, encoding), output, count); return output; }
/** * Reads lines from source {@link File} with specified encoding and returns lines as {@link String}s in array. * * @param file {@link File} to read. * @param encoding Endoing to use. * @return array of Strings which represents lines in the {@link File}. * @throws IOException if {@link File} does not exist or is not a {@link File} or there is an issue reading * the {@link File}. */ public static String[] readLines(final File file, final String encoding) throws IOException { checkExists(file); checkIsFile(file); List<String> list = new ArrayList<>(); InputStream in = streamOf(file, encoding); try { BufferedReader br = new BufferedReader(StreamUtil.inputStreamReadeOf(in, encoding)); String strLine; while ((strLine = br.readLine()) != null) { list.add(strLine); } } finally { StreamUtil.close(in); } return list.toArray(new String[0]); }
/** * @see #inputStreamReadeOf(InputStream, String) */ public static InputStreamReader inputStreamReadeOf(final InputStream input) throws UnsupportedEncodingException { return inputStreamReadeOf(input, encoding()); }
/** * Copies {@link InputStream} to {@link Writer} using buffer and specified encoding. * * @see #copy(Reader, Writer, int) */ public static <T extends Writer> T copy(final InputStream input, final T output, final String encoding, final int count) throws IOException { copy(inputStreamReadeOf(input, encoding), output, count); return output; }
/** * Reads lines from source {@link File} with specified encoding and returns lines as {@link String}s in array. * * @param file {@link File} to read. * @param encoding Endoing to use. * @return array of Strings which represents lines in the {@link File}. * @throws IOException if {@link File} does not exist or is not a {@link File} or there is an issue reading * the {@link File}. */ public static String[] readLines(final File file, final String encoding) throws IOException { checkExists(file); checkIsFile(file); List<String> list = new ArrayList<>(); InputStream in = streamOf(file, encoding); try { BufferedReader br = new BufferedReader(StreamUtil.inputStreamReadeOf(in, encoding)); String strLine; while ((strLine = br.readLine()) != null) { list.add(strLine); } } finally { StreamUtil.close(in); } return list.toArray(new String[0]); }