Class S3ARemoteInputStream
java.lang.Object
java.io.InputStream
org.apache.hadoop.fs.s3a.prefetch.S3ARemoteInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.hadoop.fs.CanSetReadahead,org.apache.hadoop.fs.statistics.IOStatisticsSource,org.apache.hadoop.fs.StreamCapabilities
- Direct Known Subclasses:
S3ACachingInputStream,S3AInMemoryInputStream
public abstract class S3ARemoteInputStream
extends InputStream
implements org.apache.hadoop.fs.CanSetReadahead, org.apache.hadoop.fs.StreamCapabilities, org.apache.hadoop.fs.statistics.IOStatisticsSource
Provides an
InputStream that allows reading from an S3 file.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.hadoop.fs.StreamCapabilities
org.apache.hadoop.fs.StreamCapabilities.StreamCapability -
Field Summary
Fields inherited from interface org.apache.hadoop.fs.StreamCapabilities
ABORTABLE_STREAM, DROPBEHIND, HFLUSH, HSYNC, IOSTATISTICS, IOSTATISTICS_CONTEXT, PREADBYTEBUFFER, READAHEAD, READBYTEBUFFER, UNBUFFER, VECTOREDIO, VECTOREDIO_BUFFERS_SLICED -
Constructor Summary
ConstructorsConstructorDescriptionS3ARemoteInputStream(S3AReadOpContext context, PrefetchOptions prefetchOptions, S3ObjectAttributes s3Attributes, ObjectInputStreamCallbacks client, S3AInputStreamStatistics streamStatistics) Initializes a new instance of theS3ARemoteInputStreamclass. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bytes that can read from this stream without blocking.voidclose()Closes this stream and releases all acquired resources.protected abstract booleanEnsures that a non-empty valid buffer is available for immediate reading.protected org.apache.hadoop.fs.impl.prefetch.BlockDataprotected S3AReadOpContextprotected S3ARemoteObjectgetFile()protected org.apache.hadoop.fs.impl.prefetch.FilePositionorg.apache.hadoop.fs.statistics.IOStatisticsGets the internal IO statistics.protected StringgetName()protected longprotected StringgetOffsetStr(long offset) longgetPos()Gets the current position.protected S3ARemoteObjectReaderAccess the input stream statistics.protected S3ARemoteObjectprotected S3ObjectAttributesbooleanhasCapability(String capability) Indicates whether the givencapabilityis supported by this stream.protected booleanisClosed()voidmark(int readlimit) booleanintread()intread(byte[] buffer) Reads bytes from this stream and copies them into the givenbufferstarting at the beginning (offset 0).intread(byte[] buffer, int offset, int len) Reads up tolenbytes from this stream and copies them into the givenbufferstarting at the givenoffset.voidreset()voidseek(long pos) Moves the current read position so that the next read will occur atpos.voidsetReadahead(Long readahead) Sets the number of bytes to read ahead each time.longskip(long n) protected voidprotected voidthrowIfInvalidSeek(long pos) toString()Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
S3ARemoteInputStream
public S3ARemoteInputStream(S3AReadOpContext context, PrefetchOptions prefetchOptions, S3ObjectAttributes s3Attributes, ObjectInputStreamCallbacks client, S3AInputStreamStatistics streamStatistics) Initializes a new instance of theS3ARemoteInputStreamclass.- Parameters:
context- read-specific operation context.prefetchOptions- prefetch stream specific optionss3Attributes- attributes of the S3 object being read.client- callbacks used for interacting with the underlying S3 client.streamStatistics- statistics for this stream.- Throws:
NullPointerException- if a required parameter is null.
-
-
Method Details
-
getIOStatistics
public org.apache.hadoop.fs.statistics.IOStatistics getIOStatistics()Gets the internal IO statistics.- Specified by:
getIOStatisticsin interfaceorg.apache.hadoop.fs.statistics.IOStatisticsSource- Returns:
- the internal IO statistics.
-
getS3AStreamStatistics
Access the input stream statistics. This is for internal testing and may be removed without warning.- Returns:
- the statistics for this input stream
-
setReadahead
Sets the number of bytes to read ahead each time.- Specified by:
setReadaheadin interfaceorg.apache.hadoop.fs.CanSetReadahead- Parameters:
readahead- the number of bytes to read ahead each time..
-
hasCapability
Indicates whether the givencapabilityis supported by this stream.- Specified by:
hasCapabilityin interfaceorg.apache.hadoop.fs.StreamCapabilities- Parameters:
capability- the capability to check.- Returns:
- true if the given
capabilityis supported by this stream, false otherwise.
-
available
Returns the number of bytes that can read from this stream without blocking.- Overrides:
availablein classInputStream- Throws:
IOException
-
getPos
Gets the current position.- Returns:
- the current position.
- Throws:
IOException- if there is an IO error during this operation.
-
seek
Moves the current read position so that the next read will occur atpos.- Parameters:
pos- the absolute position to seek to.- Throws:
IOException- if there an error during this operation.IllegalArgumentException- if pos is outside of the range [0, file size].
-
ensureCurrentBuffer
Ensures that a non-empty valid buffer is available for immediate reading. It returns true when at least one such buffer is available for reading. It returns false on reaching the end of the stream.- Returns:
- true if at least one such buffer is available for reading, false otherwise.
- Throws:
IOException- if there is an IO error during this operation.
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
Reads bytes from this stream and copies them into the givenbufferstarting at the beginning (offset 0). Returns the number of bytes actually copied in to the given buffer.- Overrides:
readin classInputStream- Parameters:
buffer- the buffer to copy data into.- Returns:
- the number of bytes actually copied in to the given buffer.
- Throws:
IOException- if there is an IO error during this operation.
-
read
Reads up tolenbytes from this stream and copies them into the givenbufferstarting at the givenoffset. Returns the number of bytes actually copied in to the given buffer.- Overrides:
readin classInputStream- Parameters:
buffer- the buffer to copy data into.offset- data is copied starting at this offset.len- max number of bytes to copy.- Returns:
- the number of bytes actually copied in to the given buffer.
- Throws:
IOException- if there is an IO error during this operation.
-
getFile
-
getReader
-
getS3ObjectAttributes
-
getFilePosition
protected org.apache.hadoop.fs.impl.prefetch.FilePosition getFilePosition() -
getName
-
isClosed
protected boolean isClosed() -
getNextReadPos
protected long getNextReadPos() -
getBlockData
protected org.apache.hadoop.fs.impl.prefetch.BlockData getBlockData() -
getContext
-
getS3File
-
getOffsetStr
-
close
Closes this stream and releases all acquired resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException- if there is an IO error during this operation.
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
toString
-
throwIfClosed
- Throws:
IOException
-
throwIfInvalidSeek
- Throws:
EOFException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
public void reset()- Overrides:
resetin classInputStream
-
skip
public long skip(long n) - Overrides:
skipin classInputStream
-