### Question:
InStream extends InputStream { public static InStream create(String name, ByteBuffer input, CompressionCodec codec, int bufferSize) throws IOException { if (codec == null) { return new UncompressedStream(name, input); } else { return new CompressedStream(name, input, codec, bufferSize); } }  abstract void seek(PositionProvider index); static InStream create(String name,
                                ByteBuffer input,
                                CompressionCodec codec,
                                int bufferSize);  }### Answer:
@Test public void testCorruptStream() throws Exception { OutputCollector collect = new OutputCollector(); CompressionCodec codec = new ZlibCodec(); OutStream out = new OutStream("test", 500, codec, collect); PositionCollector[] positions = new PositionCollector[1024]; for(int i=0; i < 1024; ++i) { positions[i] = new PositionCollector(); out.getPosition(positions[i]); out.write(i); } out.flush(); ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size()); collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size()); inBuf.flip(); InStream in = InStream.create("test", inBuf, codec, 100); byte[] contents = new byte[1024]; try { in.read(contents); fail(); } catch(IllegalArgumentException iae) { } inBuf.clear(); inBuf.put((byte) 32); inBuf.put((byte) 0); inBuf.flip(); in = InStream.create("test2", inBuf, codec, 300); try { in.read(); fail(); } catch (IllegalStateException ise) { } }