### Question:
ByteRangeInputStream extends InputStream { @Override public void close() throws IOException { this.src.close(); } ByteRangeInputStream(InputStream src, long limit, String rangeHeader); @Override int read(); @Override int read(byte[] buf); @Override int read(byte[] buf, int offset, int length); @Override int available(); @Override void close(); @Override long skip(long skip); final long offset; final long length; final String contentRange; }### Answer:
@Test public void testGoodRangeHeaders() throws IOException { String [] inputs = new String[]{"bytes=0-9","bytes=0","bytes=-10", "bytes=-12", "bytes=0-"}; for (String input: inputs) { ByteRangeInputStream test = new ByteRangeInputStream(NullInputStream.NULL_STREAM, 10, input); try { assertEquals("bad offset of " + test.offset + " for " + input, 0, test.offset); assertEquals("bad length of " + test.length + " for " + input, 10, test.length); assertEquals("bytes 0-9/10", test.contentRange); } finally { test.close(); } } inputs = new String[]{"bytes=1-9","bytes=1","bytes=-9","bytes=1-12","bytes=1-"}; for (String input: inputs) { ByteRangeInputStream test = new ByteRangeInputStream(NullInputStream.NULL_STREAM, 10, input); try { assertEquals("bad offset of " + test.offset + " for " + input, 1, test.offset); assertEquals("bad length of " + test.length + " for " + input, 9, test.length); assertEquals("bytes 1-9/10", test.contentRange); } finally { test.close(); } } inputs = new String[]{"bytes= 1-9 ","bytes= 1","bytes= - 9","bytes = 1-12","bytes= 1 - "}; for (String input: inputs) { ByteRangeInputStream test = new ByteRangeInputStream(NullInputStream.NULL_STREAM, 10, input); try { assertEquals("bad offset of " + test.offset + " for " + input, 1, test.offset); assertEquals("bad length of " + test.length + " for " + input, 9, test.length); assertEquals("bytes 1-9/10", test.contentRange); } finally { test.close(); } } String input = "bytes=2-6"; ByteRangeInputStream test = new ByteRangeInputStream(NullInputStream.NULL_STREAM, 10, input); try { assertEquals("bad offset of " + test.offset + " for " + input, 2, test.offset); assertEquals("bad length of " + test.length + " for " + input, 5, test.length); assertEquals("bytes 2-6/10", test.contentRange); } finally { test.close(); } input = "bytes=2-2"; test = new ByteRangeInputStream(NullInputStream.NULL_STREAM, 10, input); try { assertEquals("bad offset of " + test.offset + " for " + input, 2, test.offset); assertEquals("bad length of " + test.length + " for " + input, 1, test.length); assertEquals("bytes 2-2/10", test.contentRange); } finally { test.close(); } }