@Test public void readErrorCasesTest() throws IOException { byte[] in = new byte[1024]; new Random().nextBytes(in); ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(in)); InputStream dstInputStream = new ReadableStreamChannelInputStream(channel); try { dstInputStream.read(null, 0, in.length); fail("The read should have failed"); } catch (NullPointerException e) { } byte[] out = new byte[in.length]; try { dstInputStream.read(out, -1, out.length); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } try { dstInputStream.read(out, 0, -1); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } try { dstInputStream.read(out, 0, out.length + 1); fail("The read should have failed"); } catch (IndexOutOfBoundsException e) { } assertEquals("Bytes read should have been 0 because passed len was 0", 0, dstInputStream.read(out, 0, 0)); }
@Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; }
ReadableStreamChannelInputStream extends InputStream { @Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; } }
ReadableStreamChannelInputStream extends InputStream { @Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; } ReadableStreamChannelInputStream(ReadableStreamChannel readableStreamChannel); }
ReadableStreamChannelInputStream extends InputStream { @Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; } ReadableStreamChannelInputStream(ReadableStreamChannel readableStreamChannel); @Override int available(); @Override int read(); @Override int read(byte b[], int off, int len); @Override void close(); }
ReadableStreamChannelInputStream extends InputStream { @Override public int read() throws IOException { int data = -1; if (loadData()) { data = currentChunk.get() & 0xFF; reportBytesRead(1); } return data; } ReadableStreamChannelInputStream(ReadableStreamChannel readableStreamChannel); @Override int available(); @Override int read(); @Override int read(byte b[], int off, int len); @Override void close();  }