Package net.sf.sevenzipjbinding.impl
Class RandomAccessFileInStream
java.lang.Object
net.sf.sevenzipjbinding.impl.RandomAccessFileInStream
- All Implemented Interfaces:
Closeable,AutoCloseable,IInStream,ISeekableStream,ISequentialInStream
Implementation of
IInStream using RandomAccessFile. This is the usual way to open an archive from a
file: wrap a RandomAccessFile and pass it to
SevenZip.openInArchive(net.sf.sevenzipjbinding.ArchiveFormat, IInStream).- Since:
- 4.65-1
- Author:
- Boris Brodski
-
Field Summary
Fields inherited from interface net.sf.sevenzipjbinding.ISeekableStream
SEEK_CUR, SEEK_END, SEEK_SET -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessFileInStream(RandomAccessFile randomAccessFile) Constructs an instance from the given random access file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes random access file.intread(byte[] data) Reads at least 1 and maximumdata.lengthbytes from the in-stream.longseek(long offset, int seekOrigin) Move current location pointer to the new offset depending onseekOrigin.
Note: depending on the archive format and the data size this method may be called from different threads.
-
Constructor Details
-
RandomAccessFileInStream
Constructs an instance from the given random access file.- Parameters:
randomAccessFile- random access file to use
-
-
Method Details
-
seek
Move current location pointer to the new offset depending onseekOrigin.
Note: depending on the archive format and the data size this method may be called from different threads. Synchronized implementation may be required.- Specified by:
seekin interfaceISeekableStream- Parameters:
offset- absolute or relative offset in the stream to move toseekOrigin- one of three possible seek origins:
ISeekableStream.SEEK_SET-offsetis an absolute offset to move to,ISeekableStream.SEEK_CUR-offsetis a relative offset from the current position in the stream,ISeekableStream.SEEK_END-offsetis an offset from the end of the stream
- Returns:
- new absolute position in the stream.
- Throws:
SevenZipException- in error case. If this method ends with an exception, the current operation will be reported to 7-Zip as failed. There is no guarantee that no further callback methods will be called. The first and last thrown exceptions will be saved and thrown later on from the originally called method such asIInArchive.extract()orSevenZip.openInArchive(). Up to four exceptions depending on the situation can be saved for further analysis. SeeSevenZipExceptionandSevenZipException.printStackTraceExtended()for details.
-
read
Reads at least 1 and maximumdata.lengthbytes from the in-stream. Ifdata.length == 00 should be returned. Ifdata.length != 0, then return value 0 indicates end-of-stream (EOF). This means no more bytes can be read from the stream.
This function is allowed to read fewer than the number of remaining bytes in the stream and fewer thandata.length. You must call theread()function in a loop if you need an exact amount of data.
Note: depending on the archive format and the data size this method may be called from different threads. Synchronized implementation may be required.- Specified by:
readin interfaceISequentialInStream- Parameters:
data- buffer to get read data- Returns:
- number of bytes read into the
dataarray; 0 indicates end of stream. - Throws:
SevenZipException- in error case. If this method ends with an exception, the current operation will be reported to 7-Zip as failed. There is no guarantee that no further callback methods will be called. The first and last thrown exceptions will be saved and thrown later on from the originally called method such asIInArchive.extract()orSevenZip.openInArchive(). Up to four exceptions depending on the situation can be saved for further analysis. SeeSevenZipExceptionandSevenZipException.printStackTraceExtended()for details.
-
close
Closes random access file. After this call no more methods should be called.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- seeRandomAccessFile.close()
-