Class LocalDataInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.flink.core.fs.FSDataInputStream
-
- org.apache.flink.core.fs.local.LocalDataInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable,ByteBufferReadable
@Internal public class LocalDataInputStream extends FSDataInputStream implements ByteBufferReadable
TheLocalDataInputStreamclass is a wrapper class for a data input stream to the local file system.
-
-
Constructor Summary
Constructors Constructor Description LocalDataInputStream(File file)Constructs a newLocalDataInputStreamobject from a givenFileobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()longgetPos()Gets the current position in the input stream.intread()intread(byte[] buffer, int offset, int length)intread(long position, ByteBuffer byteBuffer)Reads up tobyteBuffer.remaining()bytes into byteBuffer from a given position in the file and returns the number of bytes read.intread(ByteBuffer byteBuffer)Reads up to byteBuffer.remaining() bytes into byteBuffer.voidseek(long desired)Seek to the given offset from the start of the file.longskip(long n)-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Constructor Detail
-
LocalDataInputStream
public LocalDataInputStream(File file) throws IOException
Constructs a newLocalDataInputStreamobject from a givenFileobject.- Parameters:
file- The File the data stream is read from- Throws:
IOException- Thrown if the data input stream cannot be created.
-
-
Method Detail
-
seek
public void seek(long desired) throws IOExceptionDescription copied from class:FSDataInputStreamSeek to the given offset from the start of the file. The next read() will be from that location. Can't seek past the end of the stream.- Specified by:
seekin classFSDataInputStream- Parameters:
desired- the desired offset- Throws:
IOException- Thrown if an error occurred while seeking inside the input stream.
-
getPos
public long getPos() throws IOExceptionDescription copied from class:FSDataInputStreamGets the current position in the input stream.- Specified by:
getPosin classFSDataInputStream- Returns:
- current position in the input stream
- Throws:
IOException- Thrown if an I/O error occurred in the underlying stream implementation while accessing the stream's position.
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(@Nonnull byte[] buffer, int offset, int length) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
read
public int read(ByteBuffer byteBuffer) throws IOException
Description copied from interface:ByteBufferReadableReads up to byteBuffer.remaining() bytes into byteBuffer. Callers should use byteBuffer.limit(..) to control the size of the desired read.After a successful call, byteBuffer.position() will be advanced by the number of bytes read and byteBuffer.limit() should be unchanged.
In the case of an exception, the values of byteBuffer.position() and byteBuffer.limit() are undefined, and callers should be prepared to recover from this eventuality. Implementations should treat 0-length requests as legitimate, and must not signal an error upon their receipt.
- Specified by:
readin interfaceByteBufferReadable- Parameters:
byteBuffer- the ByteBuffer to receive the results of the read operation.- Returns:
- the number of bytes read, possibly zero, or -1 if reach end-of-stream
- Throws:
IOException- if there is some error performing the read
-
read
public int read(long position, ByteBuffer byteBuffer) throws IOExceptionDescription copied from interface:ByteBufferReadableReads up tobyteBuffer.remaining()bytes into byteBuffer from a given position in the file and returns the number of bytes read. Callers should usebyteBuffer.limit(...)to control the size of the desired read andbyteBuffer.position(...)to control the offset into the buffer the data should be written to.After a successful call,
byteBuffer.position()will be advanced by the number of bytes read andbyteBuffer.limit()will be unchanged.In the case of an exception, the state of the buffer (the contents of the buffer, the
buf.position(), thebuf.limit(), etc.) is undefined, and callers should be prepared to recover from this eventuality.Implementations should treat 0-length requests as legitimate, and must not signal an error upon their receipt.
- Specified by:
readin interfaceByteBufferReadable- Parameters:
position- position within filebyteBuffer- the ByteBuffer to receive the results of the read operation.- Returns:
- the number of bytes read, possibly zero, or -1 if reached end-of-stream
- Throws:
IOException- if there is some error performing the read
-
-