Class ByteBufferIndexInput
- All Implemented Interfaces:
Closeable,AutoCloseable,Cloneable,RandomAccessInput
Because Java's ByteBuffer uses an int to address the values, it's necessary to access a file greater Integer.MAX_VALUE in size using multiple byte buffers.
For efficiency, this class requires that the buffers are a power-of-two (chunkSizePower
).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ByteBuffer[]protected final longprotected final intprotected ByteBufferprotected intprotected final org.apache.lucene.store.ByteBufferGuardprotected booleanprotected final long -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBufferIndexInputbuildSlice(String sliceDescription, long offset, long length) Builds the actual sliced IndexInput (may apply extra offset in subclasses).final ByteBufferIndexInputclone()Returns a clone of this stream.final voidclose()Closes the stream to further operations.longReturns the current position in this file, where the next read will occur.final longlength()The number of bytes in the file.protected ByteBufferIndexInputnewCloneInstance(String newResourceDescription, ByteBuffer[] newBuffers, int offset, long length) Factory method that creates a suitable implementation of this class for the given ByteBuffers.static ByteBufferIndexInputnewInstance(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, org.apache.lucene.store.ByteBufferGuard guard) final bytereadByte()Reads and returns a single byte.bytereadByte(long pos) Reads a byte at the given position in the filefinal voidreadBytes(byte[] b, int offset, int len) Reads a specified number of bytes into an array at the specified offset.final voidreadFloats(float[] floats, int offset, int len) Reads a specified number of floats into an array at the specified offset.final intreadInt()Reads four bytes and returns an int (LE byte order).intreadInt(long pos) Reads an integer (LE byte order) at the given position in the filevoidreadInts(int[] dst, int offset, int length) Reads a specified number of ints into an array at the specified offset.final longreadLong()Reads eight bytes and returns a long (LE byte order).longreadLong(long pos) Reads a long (LE byte order) at the given position in the filevoidreadLongs(long[] dst, int offset, int length) Read a specified number of longs.final shortReads two bytes and returns a short (LE byte order).shortreadShort(long pos) Reads a short (LE byte order) at the given position in the filevoidseek(long pos) Sets current position in this file, where the next read will occur.protected voidsetCurBuf(ByteBuffer curBuf) final ByteBufferIndexInputCreates a slice of this index input, with the given description, offset, and length.Methods inherited from class org.apache.lucene.store.IndexInput
getFullSliceDescription, randomAccessSlice, skipBytes, toStringMethods inherited from class org.apache.lucene.store.DataInput
readBytes, readMapOfStrings, readSetOfStrings, readString, readVInt, readVLong, readZInt, readZLong
-
Field Details
-
length
protected final long length -
chunkSizeMask
protected final long chunkSizeMask -
chunkSizePower
protected final int chunkSizePower -
guard
protected final org.apache.lucene.store.ByteBufferGuard guard -
buffers
-
curBufIndex
protected int curBufIndex -
curBuf
-
isClone
protected boolean isClone
-
-
Method Details
-
newInstance
public static ByteBufferIndexInput newInstance(String resourceDescription, ByteBuffer[] buffers, long length, int chunkSizePower, org.apache.lucene.store.ByteBufferGuard guard) -
setCurBuf
-
readByte
Description copied from class:DataInputReads and returns a single byte.- Specified by:
readBytein classDataInput- Throws:
IOException- See Also:
-
readBytes
Description copied from class:DataInputReads a specified number of bytes into an array at the specified offset.- Specified by:
readBytesin classDataInput- Parameters:
b- the array to read bytes intooffset- the offset in the array to start storing byteslen- the number of bytes to read- Throws:
IOException- See Also:
-
readLongs
Description copied from class:DataInputRead a specified number of longs.- Overrides:
readLongsin classDataInput- Throws:
IOException
-
readInts
Description copied from class:DataInputReads a specified number of ints into an array at the specified offset.- Overrides:
readIntsin classDataInput- Parameters:
dst- the array to read bytes intooffset- the offset in the array to start storing intslength- the number of ints to read- Throws:
IOException
-
readFloats
Description copied from class:DataInputReads a specified number of floats into an array at the specified offset.- Overrides:
readFloatsin classDataInput- Parameters:
floats- the array to read bytes intooffset- the offset in the array to start storing floatslen- the number of floats to read- Throws:
IOException
-
readShort
Description copied from class:DataInputReads two bytes and returns a short (LE byte order).- Overrides:
readShortin classDataInput- Throws:
IOException- See Also:
-
readInt
Description copied from class:DataInputReads four bytes and returns an int (LE byte order).- Overrides:
readIntin classDataInput- Throws:
IOException- See Also:
-
readLong
Description copied from class:DataInputReads eight bytes and returns a long (LE byte order).- Overrides:
readLongin classDataInput- Throws:
IOException- See Also:
-
getFilePointer
public long getFilePointer()Description copied from class:IndexInputReturns the current position in this file, where the next read will occur.- Specified by:
getFilePointerin classIndexInput- See Also:
-
seek
Description copied from class:IndexInputSets current position in this file, where the next read will occur. If this is beyond the end of the file then this will throwEOFExceptionand then the stream is in an undetermined state.- Specified by:
seekin classIndexInput- Throws:
IOException- See Also:
-
readByte
Description copied from interface:RandomAccessInputReads a byte at the given position in the file- Specified by:
readBytein interfaceRandomAccessInput- Throws:
IOException- See Also:
-
readShort
Description copied from interface:RandomAccessInputReads a short (LE byte order) at the given position in the file- Specified by:
readShortin interfaceRandomAccessInput- Throws:
IOException- See Also:
-
readInt
Description copied from interface:RandomAccessInputReads an integer (LE byte order) at the given position in the file- Specified by:
readIntin interfaceRandomAccessInput- Throws:
IOException- See Also:
-
readLong
Description copied from interface:RandomAccessInputReads a long (LE byte order) at the given position in the file- Specified by:
readLongin interfaceRandomAccessInput- Throws:
IOException- See Also:
-
length
public final long length()Description copied from class:IndexInputThe number of bytes in the file.- Specified by:
lengthin interfaceRandomAccessInput- Specified by:
lengthin classIndexInput
-
clone
Description copied from class:IndexInputReturns a clone of this stream.Clones of a stream access the same data, and are positioned at the same point as the stream they were cloned from.
Expert: Subclasses must ensure that clones may be positioned at different points in the input from each other and from the stream they were cloned from.
Warning: Lucene never closes cloned
IndexInputs, it will only callIndexInput.close()on the original object.If you access the cloned IndexInput after closing the original object, any
readXXXmethods will throwAlreadyClosedException.This method is NOT thread safe, so if the current
IndexInputis being used by one thread whilecloneis called by another, disaster could strike.- Overrides:
clonein classIndexInput
-
slice
Creates a slice of this index input, with the given description, offset, and length. The slice is seeked to the beginning.- Specified by:
slicein classIndexInput
-
buildSlice
Builds the actual sliced IndexInput (may apply extra offset in subclasses). * -
newCloneInstance
protected ByteBufferIndexInput newCloneInstance(String newResourceDescription, ByteBuffer[] newBuffers, int offset, long length) Factory method that creates a suitable implementation of this class for the given ByteBuffers. -
close
Description copied from class:IndexInputCloses the stream to further operations.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classIndexInput- Throws:
IOException
-