Package io.pravega.client.segment.impl
Interface SegmentInputStream
-
- All Superinterfaces:
java.lang.AutoCloseable
public interface SegmentInputStream extends java.lang.AutoCloseable
Defines a InputStream for a single segment. Once created the offset must be provided by calling setOffset. The next read will proceed from this offset. Subsequent reads will read from where the previous one left off. (Parallel calls to read data will be serialized) Get offset can be used to store a location to revert back to that position in the future.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
bytesInBuffer()
Returns > 0 ifread(ByteBuffer, long)
can be invoked without blocking.void
close()
Closes this InputStream.java.util.concurrent.CompletableFuture<?>
fillBuffer()
Issue a request to asynchronously fill the buffer.long
getOffset()
Gets the current offset.Segment
getSegmentId()
int
read(java.nio.ByteBuffer toFill, long timeout)
If data is available this will copy bytes from an internal buffer into the buffer provided.default void
setOffset(long offset)
Sets the offset for reading from the segment.void
setOffset(long offset, boolean resendRequest)
Sets the offset for reading from the segment.
-
-
-
Method Detail
-
getSegmentId
Segment getSegmentId()
-
setOffset
default void setOffset(long offset)
Sets the offset for reading from the segment.- Parameters:
offset
- The offset to set.
-
setOffset
void setOffset(long offset, boolean resendRequest)
Sets the offset for reading from the segment.- Parameters:
offset
- The offset to set.resendRequest
- Resend the read request in-case there is an already pending read request for the offset.
-
getOffset
long getOffset()
Gets the current offset. (Passing this to setOffset in the future will reset reads to the current position in the segment.)- Returns:
- The current offset.
-
read
int read(java.nio.ByteBuffer toFill, long timeout) throws EndOfSegmentException, SegmentTruncatedException
If data is available this will copy bytes from an internal buffer into the buffer provided. If the provided buffer cannot be fully filled, it will return the data it has. If no data is available it will block until some becomes available up to the provided timeout. A caller can determine if this call will block in advance by callingbytesInBuffer()
. If a caller wants to avoid blocking they callfillBuffer()
and use the future to be notified when more data can be read without blocking.- Parameters:
toFill
- the buffer to fill.timeout
- the maximum time to block if no data is in memory.- Returns:
- The number of bytes read.
- Throws:
EndOfSegmentException
- If no data could be read because the end of the segment was reached.SegmentTruncatedException
- If the segment has been truncated beyond the current offset and data cannot be read.
-
fillBuffer
java.util.concurrent.CompletableFuture<?> fillBuffer()
Issue a request to asynchronously fill the buffer. To hopefully prevent futureread(ByteBuffer, long)
calls from blocking. Calling this multiple times is harmless.- Returns:
- A future that will be completed when there is data available to read.
-
close
void close()
Closes this InputStream. No further methods may be called after close. This will free any resources associated with the InputStream.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
bytesInBuffer
int bytesInBuffer()
Returns > 0 ifread(ByteBuffer, long)
can be invoked without blocking. Returns 0 ifread(ByteBuffer, long)
will block. Returns -1 if a call to read will throw EndOfSegmentException.- Returns:
- 0 if data read is blocking.
-
-