Package net.sf.sevenzipjbinding.impl
Class VolumedArchiveInStream
java.lang.Object
net.sf.sevenzipjbinding.impl.VolumedArchiveInStream
- All Implemented Interfaces:
Closeable,AutoCloseable,IInStream,ISeekableStream,ISequentialInStream
This helper class allows merging multiple instances of
IInStream interface into one. This is helpful for
accessing 7z volumed archives. 7z splits its archives into volumes on the byte layout. Each archive volume gets
extension .7z.nnn (.7z.001, .7z.002, .7z.003, ...). Such archives
can be reassembled into single archive file using simple concatenation: cat name.7z.* > name.7z
To use this you need to implement IArchiveOpenVolumeCallback interface.
IArchiveOpenVolumeCallback.getProperty(PropID)with thepropID=PropID.NAMEwill be called ones to get the file name of the first volume in case it was not given to constructor. The file name should ends with.7z.001or SevenZipException will be thrown.IArchiveOpenVolumeCallback.getStream(String)will be called multiple times to get instance ofIInStreamrepresenting required volume. The implementation ofIArchiveOpenVolumeCallbackshould close file associated with the oldIInStream, if a newIInStreamwas successfully instantiated.
- 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
ConstructorsConstructorDescriptionVolumedArchiveInStream(String firstVolumeFilename, IArchiveOpenVolumeCallback archiveOpenVolumeCallback) Creates instance ofVolumedArchiveInStreamusingIArchiveOpenVolumeCallback.VolumedArchiveInStream(IArchiveOpenVolumeCallback archiveOpenVolumeCallback) Creates instance ofVolumedArchiveInStreamusingIArchiveOpenVolumeCallback. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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
-
VolumedArchiveInStream
public VolumedArchiveInStream(IArchiveOpenVolumeCallback archiveOpenVolumeCallback) throws SevenZipException Creates instance ofVolumedArchiveInStreamusingIArchiveOpenVolumeCallback. The name of the first archive volume will be asked usingIArchiveOpenVolumeCallback.getProperty(PropID)with thepropID=PropID.NAME. The file name should end with.7z.001or SevenZipException will be thrown.- Parameters:
archiveOpenVolumeCallback- call back implementation used to access different volumes of archive.- Throws:
SevenZipException- 7-Zip or 7-Zip-JBinding error occurs. UseSevenZipException.printStackTraceExtended()to get stack traces of this SevenZipException and of all thrown 'caused by' exceptions.
-
VolumedArchiveInStream
public VolumedArchiveInStream(String firstVolumeFilename, IArchiveOpenVolumeCallback archiveOpenVolumeCallback) throws SevenZipException Creates instance ofVolumedArchiveInStreamusingIArchiveOpenVolumeCallback.- Parameters:
firstVolumeFilename- the file name of the first volume.archiveOpenVolumeCallback- call back implementation used to access different volumes of archive. The file name should end with.7z.001or SevenZipException will be thrown.- Throws:
SevenZipException- 7-Zip or 7-Zip-JBinding error occurs. UseSevenZipException.printStackTraceExtended()to get stack traces of this SevenZipException and of all thrown 'caused by' exceptions.
-
-
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
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-