@LimitedPrivate("Filesystems")
@Unstable
public final class VectoredReadUtils
extends java.lang.Object
| Modifier and Type | Method | Description |
|---|---|---|
static boolean |
isOrderedDisjoint(java.util.List<? extends FileRange> input,
int chunkSize,
int minimumSeek) |
Is the given input list.
|
static java.util.List<CombinedFileRange> |
mergeSortedRanges(java.util.List<? extends FileRange> sortedRanges,
int chunkSize,
int minimumSeek,
int maxSize) |
Merge sorted ranges to optimize the access from the underlying file
system.
|
static void |
readInDirectBuffer(FileRange range,
java.nio.ByteBuffer buffer,
Function4RaisingIOE<java.lang.Long,byte[],java.lang.Integer,java.lang.Integer,java.lang.Void> operation) |
Read bytes from stream into a byte buffer using an
intermediate byte array.
|
static java.util.concurrent.CompletableFuture<java.nio.ByteBuffer> |
readRangeFrom(PositionedReadable stream,
FileRange range,
java.util.function.IntFunction<java.nio.ByteBuffer> allocate) |
Synchronously reads a range from the stream dealing with the combinations
of ByteBuffers buffers and PositionedReadable streams.
|
static void |
readVectored(PositionedReadable stream,
java.util.List<? extends FileRange> ranges,
java.util.function.IntFunction<java.nio.ByteBuffer> allocate) |
This is the default implementation which iterates through the ranges
to read each synchronously, but the intent is that subclasses
can make more efficient readers.
|
static long |
roundDown(long offset,
int chunkSize) |
Calculates floor value of offset based on chunk size.
|
static long |
roundUp(long offset,
int chunkSize) |
Calculates the ceiling value of offset based on chunk size.
|
static java.nio.ByteBuffer |
sliceTo(java.nio.ByteBuffer readData,
long readOffset,
FileRange request) |
Slice the data that was read to the user's request.
|
static java.util.List<? extends FileRange> |
sortRangeList(java.util.List<? extends FileRange> input) |
Sort the input ranges by offset; no validation is done.
|
static FileRange[] |
sortRanges(java.util.List<? extends FileRange> input) |
Sort the input ranges by offset; no validation is done.
|
static java.util.List<? extends FileRange> |
validateAndSortRanges(java.util.List<? extends FileRange> input,
java.util.Optional<java.lang.Long> fileLength) |
Validate a list of ranges (including overlapping checks) and
return the sorted list.
|
static <T extends FileRange> |
validateRangeRequest(T range) |
Validate a single range.
|
static void |
validateVectoredReadRanges(java.util.List<? extends FileRange> ranges) |
Validate a list of vectored read ranges.
|
public static <T extends FileRange> T validateRangeRequest(T range) throws java.io.EOFException
T - range typerange - range to validate.java.lang.IllegalArgumentException - the range length is negative or other invalid condition
is met other than the those which raise EOFException or NullPointerException.java.io.EOFException - the range offset is negativejava.lang.NullPointerException - if the range is null.public static void validateVectoredReadRanges(java.util.List<? extends FileRange> ranges) throws java.io.EOFException
ranges - list of ranges.java.io.EOFException - any EOF exception.public static void readVectored(PositionedReadable stream, java.util.List<? extends FileRange> ranges, java.util.function.IntFunction<java.nio.ByteBuffer> allocate) throws java.io.EOFException
FileRange.getData().stream - the stream to read the data fromranges - the byte ranges to readallocate - the byte buffer allocationjava.lang.IllegalArgumentException - if there are overlapping ranges or a range is invalidjava.io.EOFException - the range offset is negativepublic static java.util.concurrent.CompletableFuture<java.nio.ByteBuffer> readRangeFrom(PositionedReadable stream, FileRange range, java.util.function.IntFunction<java.nio.ByteBuffer> allocate) throws java.io.EOFException
stream - the stream to read fromrange - the range to readallocate - the function to allocate ByteBuffersjava.lang.IllegalArgumentException - the range is invalid other than by offset or being null.java.io.EOFException - the range offset is negativejava.lang.NullPointerException - if the range is null.public static void readInDirectBuffer(FileRange range, java.nio.ByteBuffer buffer, Function4RaisingIOE<java.lang.Long,byte[],java.lang.Integer,java.lang.Integer,java.lang.Void> operation) throws java.io.IOException
(position, buffer, buffer-offset, length): Void
position:= the position within the file to read data.
buffer := a buffer to read fully `length` bytes into.
buffer-offset := the offset within the buffer to write data
length := the number of bytes to read.
The passed in function MUST block until the required length of
data is read, or an exception is thrown.range - range to readbuffer - buffer to fill.operation - operation to use for reading data.java.io.IOException - any IOE.public static boolean isOrderedDisjoint(java.util.List<? extends FileRange> input, int chunkSize, int minimumSeek)
input - the list of input ranges.chunkSize - the size of the chunks that the offset and end must align to.minimumSeek - the minimum distance between ranges.public static long roundDown(long offset,
int chunkSize)
offset - file offset.chunkSize - file chunk size.public static long roundUp(long offset,
int chunkSize)
offset - file offset.chunkSize - file chunk size.public static java.util.List<? extends FileRange> validateAndSortRanges(java.util.List<? extends FileRange> input, java.util.Optional<java.lang.Long> fileLength) throws java.io.EOFException
Two ranges overlap when the start offset of second is less than the end offset of first. End offset is calculated as start offset + length.
input - input listfileLength - file length if knownjava.lang.IllegalArgumentException - if there are overlapping ranges or
a range element is invalid (other than with negative offset)java.io.EOFException - if the last range extends beyond the end of the file supplied
or a range offset is negativepublic static java.util.List<? extends FileRange> sortRangeList(java.util.List<? extends FileRange> input)
input - input ranges.@Stable public static FileRange[] sortRanges(java.util.List<? extends FileRange> input)
This method is used externally and must be retained with the signature unchanged.
input - input ranges.public static java.util.List<CombinedFileRange> mergeSortedRanges(java.util.List<? extends FileRange> sortedRanges, int chunkSize, int minimumSeek, int maxSize)
sortedRanges - already sorted list of ranges based on offset.chunkSize - round the start and end points to multiples of chunkSizeminimumSeek - the smallest gap that we should seek over in bytesmaxSize - the largest combined file range in bytespublic static java.nio.ByteBuffer sliceTo(java.nio.ByteBuffer readData,
long readOffset,
FileRange request)
readData - the buffer with the readDatareadOffset - the offset in the file for the readDatarequest - the user's requestCopyright © 2008–2025 Apache Software Foundation. All rights reserved.