public final class VectoredReadUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isOrderedDisjoint(List<? extends FileRange> input,
int chunkSize,
int minimumSeek)
Is the given input list.
|
static List<CombinedFileRange> |
mergeSortedRanges(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(int length,
ByteBuffer buffer,
Function4RaisingIOE<Integer,byte[],Integer,Integer,Void> operation)
Read bytes from stream into a byte buffer using an
intermediate byte array.
|
static CompletableFuture<ByteBuffer> |
readRangeFrom(PositionedReadable stream,
FileRange range,
IntFunction<ByteBuffer> allocate)
Synchronously reads a range from the stream dealing with the combinations
of ByteBuffers buffers and PositionedReadable streams.
|
static void |
readVectored(PositionedReadable stream,
List<? extends FileRange> ranges,
IntFunction<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 ceil value of offset based on chunk size.
|
static ByteBuffer |
sliceTo(ByteBuffer readData,
long readOffset,
FileRange request)
Slice the data that was read to the user's request.
|
static FileRange[] |
sortRanges(List<? extends FileRange> input)
Sort the input ranges by offset.
|
static List<? extends FileRange> |
validateNonOverlappingAndReturnSortedRanges(List<? extends FileRange> input)
Check if the input ranges are overlapping in nature.
|
static void |
validateRangeRequest(FileRange range)
Validate a single range.
|
static void |
validateVectoredReadRanges(List<? extends FileRange> ranges)
Validate a list of vectored read ranges.
|
public static void validateRangeRequest(FileRange range) throws EOFException
range - file range.EOFException - any EOF Exception.public static void validateVectoredReadRanges(List<? extends FileRange> ranges) throws EOFException
ranges - list of ranges.EOFException - any EOF exception.public static void readVectored(PositionedReadable stream, List<? extends FileRange> ranges, IntFunction<ByteBuffer> allocate)
FileRange.getData().stream - the stream to read the data fromranges - the byte ranges to readallocate - the byte buffer allocationpublic static CompletableFuture<ByteBuffer> readRangeFrom(PositionedReadable stream, FileRange range, IntFunction<ByteBuffer> allocate)
stream - the stream to read fromrange - the range to readallocate - the function to allocate ByteBufferspublic static void readInDirectBuffer(int length,
ByteBuffer buffer,
Function4RaisingIOE<Integer,byte[],Integer,Integer,Void> operation)
throws IOException
length - number of bytes to read.buffer - buffer to fill.operation - operation to use for reading data.IOException - any IOE.public static boolean isOrderedDisjoint(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 List<? extends FileRange> validateNonOverlappingAndReturnSortedRanges(List<? extends FileRange> input)
input - list if input ranges.public static FileRange[] sortRanges(List<? extends FileRange> input)
input - input ranges.public static List<CombinedFileRange> mergeSortedRanges(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 ByteBuffer sliceTo(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–2023 Apache Software Foundation. All rights reserved.