/** * Creates a new inputstream instance over the specific memory chunk. * * @param nativeMemoryChunk the native memory chunk * @param startOffset start offset within the memory chunk * @param length length of subchunk */ public NativeMemoryChunkInputStream( NativeMemoryChunk nativeMemoryChunk, int startOffset, int length) { super(); Preconditions.checkState(startOffset >= 0); Preconditions.checkState(length >= 0); mMemoryChunk = Preconditions.checkNotNull(nativeMemoryChunk); mStartOffset = startOffset; mEndOffset = startOffset + length > nativeMemoryChunk.getSize() ? nativeMemoryChunk.getSize() : startOffset + length; mOffset = startOffset; mMark = startOffset; }
// Test out the alloc method @Test public void testAlloc() throws Exception { NativeMemoryChunk c = mPool.alloc(1); Assert.assertNotNull(c); Assert.assertEquals(1, c.getSize()); Assert.assertEquals(1, mPool.alloc(1).getSize()); Assert.assertEquals(33, mPool.alloc(33).getSize()); Assert.assertEquals(32, mPool.alloc(32).getSize()); }