@Test public void testClose_drainsBytesOnClose() throws IOException { MockInputStream mockInputStream = new MockInputStream("abc123".getBytes(StandardCharsets.UTF_8)); InputStream consumingInputStream = new ConsumingInputStream(mockInputStream); assertEquals(6, mockInputStream.getBytesToRead()); consumingInputStream.read(); assertEquals(5, mockInputStream.getBytesToRead()); consumingInputStream.close(); assertEquals(0, mockInputStream.getBytesToRead()); }
@Override public void close() throws IOException { if (!closed && in != null) { try { ByteStreams.exhaust(this); super.in.close(); } finally { this.closed = true; } } }
ConsumingInputStream extends FilterInputStream { @Override public void close() throws IOException { if (!closed && in != null) { try { ByteStreams.exhaust(this); super.in.close(); } finally { this.closed = true; } } } }
ConsumingInputStream extends FilterInputStream { @Override public void close() throws IOException { if (!closed && in != null) { try { ByteStreams.exhaust(this); super.in.close(); } finally { this.closed = true; } } } ConsumingInputStream(InputStream inputStream); }
ConsumingInputStream extends FilterInputStream { @Override public void close() throws IOException { if (!closed && in != null) { try { ByteStreams.exhaust(this); super.in.close(); } finally { this.closed = true; } } } ConsumingInputStream(InputStream inputStream); @Override void close(); }
ConsumingInputStream extends FilterInputStream { @Override public void close() throws IOException { if (!closed && in != null) { try { ByteStreams.exhaust(this); super.in.close(); } finally { this.closed = true; } } } ConsumingInputStream(InputStream inputStream); @Override void close();  }