Package org.apache.commons.io.input
Class RandomAccessFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.RandomAccessFileInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class RandomAccessFileInputStream extends InputStream
Streams data from aRandomAccessFilestarting at its current position.- Since:
- 2.8.0
-
-
Constructor Summary
Constructors Constructor Description RandomAccessFileInputStream(RandomAccessFile file)Constructs a new instance configured to leave the underlying file open when this stream is closed.RandomAccessFileInputStream(RandomAccessFile file, boolean closeOnClose)Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream.longavailableLong()Returns the number of bytes that can be read (or skipped over) from this input stream.voidclose()RandomAccessFilegetRandomAccessFile()Gets the underlying file.booleanisCloseOnClose()Returns whether to close the underlying file when this stream is closed.intread()intread(byte[] bytes)intread(byte[] bytes, int offset, int length)longskip(long skipCount)-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Constructor Detail
-
RandomAccessFileInputStream
public RandomAccessFileInputStream(RandomAccessFile file)
Constructs a new instance configured to leave the underlying file open when this stream is closed.- Parameters:
file- The file to stream.
-
RandomAccessFileInputStream
public RandomAccessFileInputStream(RandomAccessFile file, boolean closeOnClose)
Constructs a new instance.- Parameters:
file- The file to stream.closeOnClose- Whether to close the underlying file when this stream is closed.
-
-
Method Detail
-
available
public int available() throws IOExceptionReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream. If there are more thanInteger.MAX_VALUEbytes available, returnInteger.MAX_VALUE.- Overrides:
availablein classInputStream- Returns:
- An estimate of the number of bytes that can be read.
- Throws:
IOException- If an I/O error occurs.
-
availableLong
public long availableLong() throws IOExceptionReturns the number of bytes that can be read (or skipped over) from this input stream.- Returns:
- The number of bytes that can be read.
- Throws:
IOException- If an I/O error occurs.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getRandomAccessFile
public RandomAccessFile getRandomAccessFile()
Gets the underlying file.- Returns:
- the underlying file.
-
isCloseOnClose
public boolean isCloseOnClose()
Returns whether to close the underlying file when this stream is closed.- Returns:
- Whether to close the underlying file when this stream is closed.
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] bytes) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] bytes, int offset, int length) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
skip
public long skip(long skipCount) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
-