OakStreamingIndexFile implements OakIndexFile, AutoCloseable { @Override public void readBytes(byte[] b, int offset, int len) throws IOException { checkPositionIndexes(offset, offset + len, checkNotNull(b).length); if (len < 0 || position + len > length) { String msg = String.format("Invalid byte range request for [%s][%s], " + "position: %d, file length: %d, len: %d", dirDetails, name, position, length, len); releaseInputStream(); throw new IOException(msg); } setupInputStream(); int readCnt = ByteStreams.read(blobInputStream, b, offset, len); if (readCnt < len) { String msg = String.format("Couldn't read byte range request for [%s][%s], " + "position: %d, file length: %d, len: %d. Actual read bytes %d", dirDetails, name, position, length, len, readCnt); releaseInputStream(); throw new IOException(msg); } position += len; } OakStreamingIndexFile(String name, NodeBuilder file, String dirDetails,
                          @NotNull BlobFactory blobFactory); private  OakStreamingIndexFile(OakStreamingIndexFile that); @Override OakIndexFile clone(); @Override long length(); @Override long position(); @Override void close(); @Override boolean isClosed(); @Override void seek(long pos); @Override void readBytes(byte[] b, int offset, int len); @Override void writeBytes(final byte[] b, final int offset, final int len); @Override boolean supportsCopyFromDataInput(); @Override void copyBytes(DataInput input, final long numBytes); @Override void flush(); @Override String toString(); @Override String getName();  }
@Test public void readSanity() throws Exception { byte[] fileBytes = writeFile(); NodeBuilder fooBuilder = builder.child("foo"); try (OakStreamingIndexFile readFile = new OakStreamingIndexFile("foo", fooBuilder, "dirDetails", modeDependantBlobFactory.getNodeBuilderBlobFactory(fooBuilder)) ) { byte[] readBytes = new byte[fileBytes.length]; readFile.readBytes(readBytes, 0, fileBytes.length); assertEquals("Must read same amount of data", fileBytes.length, readBytes.length); assertTrue("Must get back same data", Arrays.equals(readBytes, fileBytes)); try { readFile.readBytes(readBytes, 0, 1); fail("Must not be able to read past stored number of bytes"); } catch (Exception ignored) { } } }