Class BlockData
java.lang.Object
org.apache.hadoop.fs.impl.prefetch.BlockData
Holds information about blocks of data in a file.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetBlockNumber(long offset) Gets the id of the block that contains the given absolute offset.intGets the size of each block.longGets the size of the associated file.intGets the number of blocks in the associated file.intgetRelativeOffset(int blockNumber, long offset) Gets the relative offset corresponding to the given block and the absolute offset.intgetSize(int blockNumber) Gets the size of the given block.longgetStartOffset(int blockNumber) Gets the start offset of the given block.org.apache.hadoop.fs.impl.prefetch.BlockData.StategetState(int blockNumber) Gets the state of the given block.booleanisLastBlock(int blockNumber) Indicates whether the given block is the last block in the associated file.booleanisValidOffset(long offset) Indicates whether the given absolute offset is valid.voidsetState(int blockNumber, org.apache.hadoop.fs.impl.prefetch.BlockData.State blockState) Sets the state of the given block to the given value.
-
Constructor Details
-
BlockData
public BlockData(long fileSize, int blockSize) Constructs an instance ofBlockData.- Parameters:
fileSize- the size of a file.blockSize- the file is divided into blocks of this size.- Throws:
IllegalArgumentException- if fileSize is negative.IllegalArgumentException- if blockSize is negative.IllegalArgumentException- if blockSize is zero or negative.
-
-
Method Details
-
getBlockSize
public int getBlockSize()Gets the size of each block.- Returns:
- the size of each block.
-
getFileSize
public long getFileSize()Gets the size of the associated file.- Returns:
- the size of the associated file.
-
getNumBlocks
public int getNumBlocks()Gets the number of blocks in the associated file.- Returns:
- the number of blocks in the associated file.
-
isLastBlock
public boolean isLastBlock(int blockNumber) Indicates whether the given block is the last block in the associated file.- Parameters:
blockNumber- the id of the desired block.- Returns:
- true if the given block is the last block in the associated file, false otherwise.
- Throws:
IllegalArgumentException- if blockNumber is invalid.
-
getBlockNumber
public int getBlockNumber(long offset) Gets the id of the block that contains the given absolute offset.- Parameters:
offset- the absolute offset to check.- Returns:
- the id of the block that contains the given absolute offset.
- Throws:
IllegalArgumentException- if offset is invalid.
-
getSize
public int getSize(int blockNumber) Gets the size of the given block.- Parameters:
blockNumber- the id of the desired block.- Returns:
- the size of the given block.
-
isValidOffset
public boolean isValidOffset(long offset) Indicates whether the given absolute offset is valid.- Parameters:
offset- absolute offset in the file..- Returns:
- true if the given absolute offset is valid, false otherwise.
-
getStartOffset
public long getStartOffset(int blockNumber) Gets the start offset of the given block.- Parameters:
blockNumber- the id of the given block.- Returns:
- the start offset of the given block.
- Throws:
IllegalArgumentException- if blockNumber is invalid.
-
getRelativeOffset
public int getRelativeOffset(int blockNumber, long offset) Gets the relative offset corresponding to the given block and the absolute offset.- Parameters:
blockNumber- the id of the given block.offset- absolute offset in the file.- Returns:
- the relative offset corresponding to the given block and the absolute offset.
- Throws:
IllegalArgumentException- if either blockNumber or offset is invalid.
-
getState
public org.apache.hadoop.fs.impl.prefetch.BlockData.State getState(int blockNumber) Gets the state of the given block.- Parameters:
blockNumber- the id of the given block.- Returns:
- the state of the given block.
- Throws:
IllegalArgumentException- if blockNumber is invalid.
-
setState
public void setState(int blockNumber, org.apache.hadoop.fs.impl.prefetch.BlockData.State blockState) Sets the state of the given block to the given value.- Parameters:
blockNumber- the id of the given block.blockState- the target state.- Throws:
IllegalArgumentException- if blockNumber is invalid.
-
getStateString
-