public static ByteBufferIndexInput newInstance(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, BufferCleaner cleaner, boolean trackClones) { final WeakIdentityMap<ByteBufferIndexInput,Boolean> clones = trackClones ? WeakIdentityMap.<ByteBufferIndexInput,Boolean>newConcurrentHashMap() : null; if (buffers.length == 1) { return new SingleBufferImpl(resourceDescription, buffers[0], length, chunkSizePower, cleaner, clones); } else { return new DefaultImpl(resourceDescription, buffers, length, chunkSizePower, cleaner, clones); } }
ByteBufferIndexInput(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, BufferCleaner cleaner, WeakIdentityMap<ByteBufferIndexInput,Boolean> clones) { super(resourceDescription); this.buffers = buffers; this.length = length; this.chunkSizePower = chunkSizePower; this.chunkSizeMask = (1L << chunkSizePower) - 1L; this.clones = clones; this.cleaner = cleaner; assert chunkSizePower >= 0 && chunkSizePower <= 30; assert (length >>> chunkSizePower) < Integer.MAX_VALUE; }
DefaultImpl(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, BufferCleaner cleaner, WeakIdentityMap<ByteBufferIndexInput,Boolean> clones) { super(resourceDescription, buffers, length, chunkSizePower, cleaner, clones); try { seek(0L); } catch (IOException ioe) { throw new AssertionError(ioe); } }
SingleBufferImpl(String resourceDescription, ByteBuffer buffer, long length, int chunkSizePower, BufferCleaner cleaner, WeakIdentityMap<ByteBufferIndexInput,Boolean> clones) { super(resourceDescription, new ByteBuffer[] { buffer }, length, chunkSizePower, cleaner, clones); this.curBufIndex = 0; this.curBuf = buffer; buffer.position(0); }
WithOffsetImpl(String resourceDescription, ByteBuffer[] buffers, int offset, long length, int chunkSizePower, BufferCleaner cleaner, WeakIdentityMap<ByteBufferIndexInput,Boolean> clones) { super(resourceDescription, buffers, length, chunkSizePower, cleaner, clones); this.offset = offset; try { seek(0L); } catch (IOException ioe) { throw new AssertionError(ioe); } }