@Test public void readInt() throws Exception { InputStream is = new UsbFileInputStream(file); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { ByteBuffer buffer = invocation.getArgument(1); buffer.put((byte) 1); return null; } }).when(file).read(any(Long.class), any(ByteBuffer.class)); for (int i = 0; i < 20; i++) { int b = is.read(); assertEquals(1, b); verify(file, times(i + 1)).read(longCaptor.capture(), byteBufferCaptor.capture()); assertEquals(i, longCaptor.getValue().longValue()); assertNotNull(byteBufferCaptor.getValue()); } }
@Override public int read() throws IOException { if(currentByteOffset >= file.getLength()) { return -1; } ByteBuffer buffer = ByteBuffer.allocate(512); buffer.limit(1); file.read(currentByteOffset, buffer); currentByteOffset++; buffer.flip(); return buffer.get(); }
UsbFileInputStream extends InputStream { @Override public int read() throws IOException { if(currentByteOffset >= file.getLength()) { return -1; } ByteBuffer buffer = ByteBuffer.allocate(512); buffer.limit(1); file.read(currentByteOffset, buffer); currentByteOffset++; buffer.flip(); return buffer.get(); } }
UsbFileInputStream extends InputStream { @Override public int read() throws IOException { if(currentByteOffset >= file.getLength()) { return -1; } ByteBuffer buffer = ByteBuffer.allocate(512); buffer.limit(1); file.read(currentByteOffset, buffer); currentByteOffset++; buffer.flip(); return buffer.get(); } UsbFileInputStream(UsbFile file); }
UsbFileInputStream extends InputStream { @Override public int read() throws IOException { if(currentByteOffset >= file.getLength()) { return -1; } ByteBuffer buffer = ByteBuffer.allocate(512); buffer.limit(1); file.read(currentByteOffset, buffer); currentByteOffset++; buffer.flip(); return buffer.get(); } UsbFileInputStream(UsbFile file); @Override int available(); @Override int read(); @Override void close(); @Override int read(byte[] buffer); @Override int read(byte[] buffer, int byteOffset, int byteCount); @Override long skip(long byteCount); }
UsbFileInputStream extends InputStream { @Override public int read() throws IOException { if(currentByteOffset >= file.getLength()) { return -1; } ByteBuffer buffer = ByteBuffer.allocate(512); buffer.limit(1); file.read(currentByteOffset, buffer); currentByteOffset++; buffer.flip(); return buffer.get(); } UsbFileInputStream(UsbFile file); @Override int available(); @Override int read(); @Override void close(); @Override int read(byte[] buffer); @Override int read(byte[] buffer, int byteOffset, int byteCount); @Override long skip(long byteCount);  }