Class RandomAccessInputStream
java.lang.Object
java.io.InputStream
org.archive.io.SeekInputStream
org.archive.io.RandomAccessInputStream
- All Implemented Interfaces:
RepositionableStream,Closeable,AutoCloseable
Wraps a RandomAccessFile with an InputStream interface.
- Author:
- gojomo
-
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessInputStream(File file) Constructor.RandomAccessInputStream(File file, long offset) Constructor.Constructor.RandomAccessInputStream(RandomAccessFile raf, boolean sympathyClose, long offset) -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()voidmark(int readlimit) Marks the current position of the stream.booleanReturns true, since SeekInputStreams support mark/reset by default.longposition()Returns the current stream position.voidposition(long position) Sets the current stream position.intread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()Resets this stream to its marked position.longskip(long n)
-
Constructor Details
-
RandomAccessInputStream
Constructor. If using this constructor, caller created the RAF and therefore its assumed wants to control close of the RAF. The RAF.close is not called if this constructor is used on close of this stream.- Parameters:
raf- RandomAccessFile to wrap.- Throws:
IOException
-
RandomAccessInputStream
Constructor.- Parameters:
file- File to get RAFIS on. Creates an RAF from passed file. Closes the created RAF when this stream is closed.- Throws:
IOException
-
RandomAccessInputStream
Constructor.- Parameters:
file- File to get RAFIS on. Creates an RAF from passed file. Closes the created RAF when this stream is closed.offset-- Throws:
IOException
-
RandomAccessInputStream
public RandomAccessInputStream(RandomAccessFile raf, boolean sympathyClose, long offset) throws IOException - Parameters:
raf- RandomAccessFile to wrap.sympathyClose- Set to true if we are to close the RAF file when this stream is closed.offset-- Throws:
IOException
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
position
Description copied from interface:RepositionableStreamReturns the current stream position.- Returns:
- the current stream position.
- Throws:
IOException
-
position
Description copied from interface:RepositionableStreamSets the current stream position.- Parameters:
position- the new stream position.- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()Description copied from class:SeekInputStreamReturns true, since SeekInputStreams support mark/reset by default.- Overrides:
markSupportedin classSeekInputStream- Returns:
- true
-
mark
public void mark(int readlimit) Description copied from class:SeekInputStreamMarks the current position of the stream. The limit parameter is ignored; the mark will remain valid until reset is called or the stream is closed.- Overrides:
markin classSeekInputStream- Parameters:
readlimit- ignored
-
reset
Description copied from class:SeekInputStreamResets this stream to its marked position.- Overrides:
resetin classSeekInputStream- Throws:
IOException- if there is no mark, or if an IO error occurs
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-