FileReferenceData { public abstract int nextContent(ByteBuffer bb); FileReferenceData(FileReference fileReference, String filename, Type type); FileReference fileReference(); String filename(); Type type(); ByteBuffer content(); abstract int nextContent(ByteBuffer bb); abstract long xxhash(); abstract long size(); abstract void close();  }
@Test public void testDataBlob() { String content = "blob"; FileReferenceData fileReferenceData = new FileReferenceDataBlob(new FileReference("ref"), "foo", FileReferenceData.Type.compressed, Utf8.toBytes(content)); ByteBuffer byteBuffer = ByteBuffer.allocate(100); assertEquals(4, fileReferenceData.nextContent(byteBuffer)); assertEquals(content, Utf8.toString(Arrays.copyOfRange(byteBuffer.array(), 0, 4))); assertEquals(-1, fileReferenceData.nextContent(byteBuffer)); }
@Test public void testLargerDataBlob() { String content = "blobbblubbblabb"; FileReferenceData fileReferenceData = new FileReferenceDataBlob(new FileReference("ref"), "foo", FileReferenceData.Type.compressed, Utf8.toBytes(content)); ByteBuffer byteBuffer = ByteBuffer.allocate(10); assertEquals(10, fileReferenceData.nextContent(byteBuffer)); assertEquals(content.substring(0,10), Utf8.toString(Arrays.copyOfRange(byteBuffer.array(), 0, 10))); byteBuffer.flip(); assertEquals(5, fileReferenceData.nextContent(byteBuffer)); assertEquals(content.substring(10,15), Utf8.toString(Arrays.copyOfRange(byteBuffer.array(), 0, 5))); assertEquals(-1, fileReferenceData.nextContent(byteBuffer)); }