@Test public void readMoreThenLength() throws Exception { InputStream is = new UsbFileInputStream(file); int read = is.read(new byte[200]); assertEquals(123, read); read = is.read(new byte[200]); assertEquals(-1, read); }
@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);  }