Source:
public void testCompressedRead() throws IOException { final String first = "First line"; final String second = "Second line"; File tempFile = File.createTempFile("TextInputFormatTest", ".compressed", temporaryFolder.getRoot()); tempFile.setWritable(true); try (PrintStream ps = new PrintStream(tempFile)) { ps.println(first); ps.println(second); } TextInputFormat inputFormat = new TextInputFormat(new Path(tempFile.toURI().toString())); TextInputFormat.registerInflaterInputStreamFactory( "compressed", new InflaterInputStreamFactory<InputStream>() { @Override public InputStream create(InputStream in) throws IOException { return in; } @Override public Collection<String> getCommonFileExtensions() { return Collections.singletonList("compressed"); } }); Configuration parameters = new Configuration(); inputFormat.configure(parameters); FileInputSplit[] splits = inputFormat.createInputSplits(1); assertThat("expected at least one input split", splits.length, greaterThanOrEqualTo(1)); inputFormat.open(splits[0]); try { assertFalse(inputFormat.reachedEnd()); String result = inputFormat.nextRecord(""); assertNotNull("Expecting first record here", result); assertEquals(first, result); assertFalse(inputFormat.reachedEnd()); Long currentOffset = inputFormat.getCurrentState(); inputFormat.close(); inputFormat = new TextInputFormat(new Path(tempFile.toURI().toString())); inputFormat.configure(parameters); inputFormat.reopen(splits[0], currentOffset); assertFalse(inputFormat.reachedEnd()); result = inputFormat.nextRecord(result); assertNotNull("Expecting second record here", result); assertEquals(second, result); assertTrue(inputFormat.reachedEnd() || null == inputFormat.nextRecord(result)); } finally { inputFormat.close(); } }

Target:
public void testCompressedRead() throws IOException { TextInputFormat.registerInflaterInputStreamFactory( "compressed", new InflaterInputStreamFactory<InputStream>() { @Override public InputStream create(InputStream in) { return in; } @Override public Collection<String> getCommonFileExtensions() { return Collections.singletonList("compressed"); } }); final String first = "First line"; final String second = "Second line"; File tempFile = File.createTempFile("TextInputFormatTest", ".compressed", temporaryFolder.getRoot()); tempFile.setWritable(true); try (PrintStream ps = new PrintStream(tempFile)) { ps.println(first); ps.println(second); } TextInputFormat inputFormat = new TextInputFormat(new Path(tempFile.toURI().toString())); Configuration parameters = new Configuration(); inputFormat.configure(parameters); FileInputSplit[] splits = inputFormat.createInputSplits(1); assertThat("expected at least one input split", splits.length, greaterThanOrEqualTo(1)); inputFormat.open(splits[0]); try { assertFalse(inputFormat.reachedEnd()); String result = inputFormat.nextRecord(""); assertNotNull("Expecting first record here", result); assertEquals(first, result); assertFalse(inputFormat.reachedEnd()); Long currentOffset = inputFormat.getCurrentState(); inputFormat.close(); inputFormat = new TextInputFormat(new Path(tempFile.toURI().toString())); inputFormat.configure(parameters); inputFormat.reopen(splits[0], currentOffset); assertFalse(inputFormat.reachedEnd()); result = inputFormat.nextRecord(result); assertNotNull("Expecting second record here", result); assertEquals(second, result); assertTrue(inputFormat.reachedEnd() || null == inputFormat.nextRecord(result)); } finally { inputFormat.close(); } }