Package org.apache.commons.io.input
Class RandomAccessFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.AbstractInputStream
-
- org.apache.commons.io.input.RandomAccessFileInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class RandomAccessFileInputStream extends AbstractInputStream
Streams data from aRandomAccessFilestarting at its current position.To build an instance, use
RandomAccessFileInputStream.Builder.- Since:
- 2.8.0
- See Also:
RandomAccessFileInputStream.Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRandomAccessFileInputStream.BuilderBuilds a newRandomAccessFileInputStream.
-
Constructor Summary
Constructors Constructor Description RandomAccessFileInputStream(java.io.RandomAccessFile file)Deprecated.RandomAccessFileInputStream(java.io.RandomAccessFile file, boolean propagateClose)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Gets an estimate of the number of bytes that can be read (or skipped over) from this input stream.longavailableLong()Gets the number of bytes that can be read (or skipped over) from this input stream.static RandomAccessFileInputStream.Builderbuilder()Constructs a newRandomAccessFileInputStream.Builder.voidclose()longcopy(long pos, long size, java.io.OutputStream os)Copies our bytes from the given starting position for a size to the output stream.java.io.RandomAccessFilegetRandomAccessFile()Gets the underlying file.booleanisCloseOnClose()Tests whether to close the underlying file when this stream is closed, defaults to false for compatibility.intread()intread(byte[] bytes)intread(byte[] bytes, int offset, int length)longskip(long skipCount)-
Methods inherited from class org.apache.commons.io.input.AbstractInputStream
isClosed, setClosed
-
-
-
-
Constructor Detail
-
RandomAccessFileInputStream
@Deprecated public RandomAccessFileInputStream(java.io.RandomAccessFile file)
Deprecated.Constructs a new instance configured to leave the underlying file open when this stream is closed.- Parameters:
file- The file to stream.
-
RandomAccessFileInputStream
@Deprecated public RandomAccessFileInputStream(java.io.RandomAccessFile file, boolean propagateClose)
Deprecated.Constructs a new instance.- Parameters:
file- The file to stream.propagateClose- Whether to close the underlying file when this stream is closed.
-
-
Method Detail
-
builder
public static RandomAccessFileInputStream.Builder builder()
Constructs a newRandomAccessFileInputStream.Builder.- Returns:
- a new
RandomAccessFileInputStream.Builder. - Since:
- 2.12.0
-
available
public int available() throws java.io.IOException
Gets an estimate of the number of bytes that can be read (or skipped over) from this input stream.If there are more than
Integer.MAX_VALUEbytes available, returnInteger.MAX_VALUE.- Overrides:
availablein classjava.io.InputStream- Returns:
- An estimate of the number of bytes that can be read.
- Throws:
java.io.IOException- If an I/O error occurs.
-
availableLong
public long availableLong() throws java.io.IOException
Gets 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:
java.io.IOException- If an I/O error occurs.
-
close
public void close() throws java.io.IOException
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classAbstractInputStream- Throws:
java.io.IOException
-
copy
public long copy(long pos, long size, java.io.OutputStream os) throws java.io.IOException
Copies our bytes from the given starting position for a size to the output stream.- Parameters:
pos- Where to start copying. The offset position, measured in bytes from the beginning of the file, at which to set the file pointer.size- The number of bytes to copy.os- Where to copy.- Returns:
- The number of bytes copied.
- Throws:
java.io.IOException- ifposis less than0or if an I/O error occurs.- Since:
- 2.19.0
-
getRandomAccessFile
public java.io.RandomAccessFile getRandomAccessFile()
Gets the underlying file.- Returns:
- the underlying file.
-
isCloseOnClose
public boolean isCloseOnClose()
Tests whether to close the underlying file when this stream is closed, defaults to false for compatibility.- Returns:
- Whether to close the underlying file when this stream is closed.
-
read
public int read() throws java.io.IOException
- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] bytes) throws java.io.IOException
- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] bytes, int offset, int length) throws java.io.IOException
- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
skip
public long skip(long skipCount) throws java.io.IOException
- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
-