Class FilePosition
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.FilePosition
Provides functionality related to tracking the position within a file.
The file is accessed through an in memory buffer. The absolute position within
the file is the sum of start offset of the buffer within the file and the relative
offset of the current access location within the buffer.
A file is made up of equal sized blocks. The last block may be of a smaller size.
The size of a buffer associated with this file is typically the same as block size.
-
Constructor Summary
ConstructorsConstructorDescriptionFilePosition(long fileSize, int blockSize) Constructs an instance ofFilePosition. -
Method Summary
Modifier and TypeMethodDescriptionlongabsolute()Gets the current absolute position within this file.intGets the id of the current block.buffer()booleanDetermines whether the current buffer has been fully read.longGets the start of the current block's absolute offset.data()voidincrementBytesRead(int n) voidMarks the current position as invalid.booleanDetermines whether the current block is the last block in this file.booleanisValid()Determines if the current position is valid.booleanisWithinCurrentBuffer(long pos) Determines whether the given absolute position lies within the current buffer.intintintintrelative()Gets the current position within this file relative to the start of the associated buffer.booleansetAbsolute(long pos) If the givenposlies within the current buffer, updates the current position to the specified value and returns true; otherwise returns false without changing the position.voidsetData(BufferData bufferData, long startOffset, long readOffset) Associates a buffer with this file.toString()
-
Constructor Details
-
FilePosition
public FilePosition(long fileSize, int blockSize) Constructs an instance ofFilePosition.- Parameters:
fileSize- size of the associated file.blockSize- size of each block within the file.- Throws:
IllegalArgumentException- if fileSize is negative.IllegalArgumentException- if blockSize is zero or negative.
-
-
Method Details
-
setData
Associates a buffer with this file.- Parameters:
bufferData- the buffer associated with this file.startOffset- Start offset of the buffer relative to the start of a file.readOffset- Offset where reading starts relative to the start of a file.- Throws:
IllegalArgumentException- if bufferData is null.IllegalArgumentException- if startOffset is negative.IllegalArgumentException- if readOffset is negative.IllegalArgumentException- if readOffset is outside the range [startOffset, buffer end].
-
buffer
-
data
-
absolute
public long absolute()Gets the current absolute position within this file.- Returns:
- the current absolute position within this file.
-
setAbsolute
public boolean setAbsolute(long pos) If the givenposlies within the current buffer, updates the current position to the specified value and returns true; otherwise returns false without changing the position.- Parameters:
pos- the absolute position to change the current position to if possible.- Returns:
- true if the given current position was updated, false otherwise.
-
relative
public int relative()Gets the current position within this file relative to the start of the associated buffer.- Returns:
- the current position within this file relative to the start of the associated buffer.
-
isWithinCurrentBuffer
public boolean isWithinCurrentBuffer(long pos) Determines whether the given absolute position lies within the current buffer.- Parameters:
pos- the position to check.- Returns:
- true if the given absolute position lies within the current buffer, false otherwise.
-
blockNumber
public int blockNumber()Gets the id of the current block.- Returns:
- the id of the current block.
-
isLastBlock
public boolean isLastBlock()Determines whether the current block is the last block in this file.- Returns:
- true if the current block is the last block in this file, false otherwise.
-
isValid
public boolean isValid()Determines if the current position is valid.- Returns:
- true if the current position is valid, false otherwise.
-
invalidate
public void invalidate()Marks the current position as invalid. -
bufferStartOffset
public long bufferStartOffset()Gets the start of the current block's absolute offset.- Returns:
- the start of the current block's absolute offset.
-
bufferFullyRead
public boolean bufferFullyRead()Determines whether the current buffer has been fully read.- Returns:
- true if the current buffer has been fully read, false otherwise.
-
incrementBytesRead
public void incrementBytesRead(int n) -
numBytesRead
public int numBytesRead() -
numSingleByteReads
public int numSingleByteReads() -
numBufferReads
public int numBufferReads() -
toString
-