/** * Open a file for input with the default charset. * * @param file The file to open. * @param compression The compression mode. * @return A reader opened on the file. * @throws IOException if there was an error opening the file. * @see #openInput(java.io.File, Charset, CompressionMode) */ public static Reader openInput(File file, CompressionMode compression) throws IOException { return openInput(file, Charset.defaultCharset(), compression); }
/** * Open a reader with automatic compression and the default character set. * * @param file The file to open. * @return A reader opened on the input file. * @throws IOException if there is an error opening the file. * @see #openInput(File, Charset, CompressionMode) * @see CompressionMode#AUTO * @see Charset#defaultCharset() */ @SuppressWarnings("unused") public static Reader openInput(File file) throws IOException { return openInput(file, Charset.defaultCharset(), CompressionMode.AUTO); }
@Test public void testGzipFile() throws IOException { File file = tmpdir.newFile("uncompressed.txt.gz"); Writer out = LKFileUtils.openOutput(file); try { out.write("hello\n"); } finally { out.close(); } Reader in = LKFileUtils.openInput(file, CompressionMode.GZIP); try { char[] buffer = new char[6]; in.read(buffer); assertThat(new String(buffer), equalTo("hello\n")); } finally { out.close(); } }
@Test public void testUncompressedFile() throws IOException { File file = tmpdir.newFile("uncompressed.txt"); Writer out = LKFileUtils.openOutput(file); try { out.write("hello\n"); } finally { out.close(); } Reader in = LKFileUtils.openInput(file, CompressionMode.NONE); try { char[] buffer = new char[6]; in.read(buffer); assertThat(new String(buffer), equalTo("hello\n")); } finally { out.close(); } }
@Test public void testXZFile() throws IOException { File file = tmpdir.newFile("uncompressed.txt.xz"); Writer out = LKFileUtils.openOutput(file); try { out.write("hello\n"); } finally { out.close(); } Reader in = LKFileUtils.openInput(file, CompressionMode.XZ); try { char[] buffer = new char[6]; in.read(buffer); assertThat(new String(buffer), equalTo("hello\n")); } finally { out.close(); } }
/** * Open a file for input with the default charset. * * @param file The file to open. * @param compression The compression mode. * @return A reader opened on the file. * @throws IOException if there was an error opening the file. * @see #openInput(java.io.File, Charset, CompressionMode) */ public static Reader openInput(File file, CompressionMode compression) throws IOException { return openInput(file, Charset.defaultCharset(), compression); }
/** * Open a reader with automatic compression and the default character set. * * @param file The file to open. * @return A reader opened on the input file. * @throws IOException if there is an error opening the file. * @see #openInput(File, Charset, CompressionMode) * @see CompressionMode#AUTO * @see Charset#defaultCharset() */ @SuppressWarnings("unused") public static Reader openInput(File file) throws IOException { return openInput(file, Charset.defaultCharset(), CompressionMode.AUTO); }