Package org.apache.lucene.store
Class ByteBuffersDataInput
- java.lang.Object
-
- org.apache.lucene.store.DataInput
-
- org.apache.lucene.store.ByteBuffersDataInput
-
- All Implemented Interfaces:
java.lang.Cloneable,RandomAccessInput,Accountable
public final class ByteBuffersDataInput extends DataInput implements Accountable, RandomAccessInput
-
-
Field Summary
Fields Modifier and Type Field Description private intblockBitsprivate intblockMaskprivate java.nio.ByteBuffer[]blocksprivate java.nio.FloatBuffer[]floatBuffersprivate java.nio.LongBuffer[]longBuffersprivate longoffsetprivate longposprivate longsize-
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE
-
-
Constructor Summary
Constructors Constructor Description ByteBuffersDataInput(java.util.List<java.nio.ByteBuffer> buffers)Read data from a set of contiguous buffers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intblockIndex(long pos)private intblockOffset(long pos)private intblockSize()(package private) static intdetermineBlockPage(java.util.List<java.nio.ByteBuffer> buffers)private static voidensureAssumptions(java.util.List<java.nio.ByteBuffer> buffers)private java.nio.FloatBuffergetFloatBuffer(long pos)private java.nio.LongBuffergetLongBuffer(long pos)private static booleanisPowerOfTwo(int v)longposition()longramBytesUsed()Return the memory usage of this object in bytes.bytereadByte()Reads and returns a single byte.bytereadByte(long pos)Reads a byte at the given position in the filevoidreadBytes(byte[] arr, int off, int len)Reads a specified number of bytes into an array at the specified offset.voidreadBytes(java.nio.ByteBuffer buffer, int len)Reads exactlylenbytes into the given buffer.voidreadFloats(float[] arr, int off, int len)Reads a specified number of floats into an array at the specified offset.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 filelongreadLong()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[] arr, int off, int len)Read a specified number of longs.shortreadShort()Reads 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 position)longsize()voidskipBytes(long numBytes)Skip overnumBytesbytes.ByteBuffersDataInputslice(long offset, long length)private static java.util.List<java.nio.ByteBuffer>sliceBufferList(java.util.List<java.nio.ByteBuffer> buffers, long offset, long length)java.lang.StringtoString()-
Methods inherited from class org.apache.lucene.store.DataInput
clone, readBytes, readInts, readMapOfStrings, readSetOfStrings, readString, readVInt, readVLong, readZInt, readZLong
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
-
-
-
Field Detail
-
blocks
private final java.nio.ByteBuffer[] blocks
-
floatBuffers
private final java.nio.FloatBuffer[] floatBuffers
-
longBuffers
private final java.nio.LongBuffer[] longBuffers
-
blockBits
private final int blockBits
-
blockMask
private final int blockMask
-
size
private final long size
-
offset
private final long offset
-
pos
private long pos
-
-
Constructor Detail
-
ByteBuffersDataInput
public ByteBuffersDataInput(java.util.List<java.nio.ByteBuffer> buffers)
Read data from a set of contiguous buffers. All data buffers except for the last one must have an identical remaining number of bytes in the buffer (that is a power of two). The last buffer can be of an arbitrary remaining length.
-
-
Method Detail
-
size
public long size()
-
ramBytesUsed
public long ramBytesUsed()
Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-
readByte
public byte readByte() throws java.io.EOFExceptionDescription copied from class:DataInputReads and returns a single byte.- Specified by:
readBytein classDataInput- Throws:
java.io.EOFException- See Also:
DataOutput.writeByte(byte)
-
readBytes
public void readBytes(java.nio.ByteBuffer buffer, int len) throws java.io.EOFExceptionReads exactlylenbytes into the given buffer. The buffer must have enough remaining limit.If there are fewer than
lenbytes in the input,EOFExceptionis thrown.- Throws:
java.io.EOFException
-
readBytes
public void readBytes(byte[] arr, int off, int len) throws java.io.EOFExceptionDescription copied from class:DataInputReads a specified number of bytes into an array at the specified offset.- Specified by:
readBytesin classDataInput- Parameters:
arr- the array to read bytes intooff- the offset in the array to start storing byteslen- the number of bytes to read- Throws:
java.io.EOFException- See Also:
DataOutput.writeBytes(byte[],int)
-
readShort
public short readShort() throws java.io.IOExceptionDescription copied from class:DataInputReads two bytes and returns a short (LE byte order).- Overrides:
readShortin classDataInput- Throws:
java.io.IOException- See Also:
DataOutput.writeShort(short),BitUtil.VH_LE_SHORT
-
readInt
public int readInt() throws java.io.IOExceptionDescription copied from class:DataInputReads four bytes and returns an int (LE byte order).- Overrides:
readIntin classDataInput- Throws:
java.io.IOException- See Also:
DataOutput.writeInt(int),BitUtil.VH_LE_INT
-
readLong
public long readLong() throws java.io.IOExceptionDescription copied from class:DataInputReads eight bytes and returns a long (LE byte order).- Overrides:
readLongin classDataInput- Throws:
java.io.IOException- See Also:
DataOutput.writeLong(long),BitUtil.VH_LE_LONG
-
readByte
public byte readByte(long pos)
Description copied from interface:RandomAccessInputReads a byte at the given position in the file- Specified by:
readBytein interfaceRandomAccessInput- See Also:
DataInput.readByte()
-
readShort
public short readShort(long pos)
Description copied from interface:RandomAccessInputReads a short (LE byte order) at the given position in the file- Specified by:
readShortin interfaceRandomAccessInput- See Also:
DataInput.readShort(),BitUtil.VH_LE_SHORT
-
readInt
public int readInt(long pos)
Description copied from interface:RandomAccessInputReads an integer (LE byte order) at the given position in the file- Specified by:
readIntin interfaceRandomAccessInput- See Also:
DataInput.readInt(),BitUtil.VH_LE_INT
-
readLong
public long readLong(long pos)
Description copied from interface:RandomAccessInputReads a long (LE byte order) at the given position in the file- Specified by:
readLongin interfaceRandomAccessInput- See Also:
DataInput.readLong(),BitUtil.VH_LE_LONG
-
readFloats
public void readFloats(float[] arr, int off, int len) throws java.io.EOFExceptionDescription copied from class:DataInputReads a specified number of floats into an array at the specified offset.- Overrides:
readFloatsin classDataInput- Parameters:
arr- the array to read bytes intooff- the offset in the array to start storing floatslen- the number of floats to read- Throws:
java.io.EOFException
-
readLongs
public void readLongs(long[] arr, int off, int len) throws java.io.EOFExceptionDescription copied from class:DataInputRead a specified number of longs.
-
getFloatBuffer
private java.nio.FloatBuffer getFloatBuffer(long pos)
-
getLongBuffer
private java.nio.LongBuffer getLongBuffer(long pos)
-
position
public long position()
-
seek
public void seek(long position) throws java.io.EOFException- Throws:
java.io.EOFException
-
skipBytes
public void skipBytes(long numBytes) throws java.io.IOExceptionDescription copied from class:DataInputSkip overnumBytesbytes. This method may skip bytes in whatever way is most optimal, and may not have the same behavior as reading the skipped bytes. In general, negativenumBytesare not supported.
-
slice
public ByteBuffersDataInput slice(long offset, long length)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
blockIndex
private final int blockIndex(long pos)
-
blockOffset
private final int blockOffset(long pos)
-
blockSize
private int blockSize()
-
isPowerOfTwo
private static final boolean isPowerOfTwo(int v)
-
ensureAssumptions
private static void ensureAssumptions(java.util.List<java.nio.ByteBuffer> buffers)
-
determineBlockPage
static int determineBlockPage(java.util.List<java.nio.ByteBuffer> buffers)
-
sliceBufferList
private static java.util.List<java.nio.ByteBuffer> sliceBufferList(java.util.List<java.nio.ByteBuffer> buffers, long offset, long length)
-
-