Class Archive
java.lang.Object
com.github.junrar.Archive
- All Implemented Interfaces:
Closeable, AutoCloseable, Iterable<FileHeader>
The Main Rar Class; represents a rar Archive
- Version:
- $LastChangedRevision$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classAn emptyInputStream.private static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SeekableReadOnlyByteChannelprivate intprivate final ComprDataIOprivate static final org.slf4j.Loggerprivate MarkHeaderprivate static final intprivate MainHeaderprivate FileHeaderprivate Stringprivate static final intprivate longNumber of bytes of compressed data read from current file.private longSize of packed data in current file.private Unpackprivate final UnrarCallbackprivate static final booleanprivate Volumeprivate VolumeManager -
Constructor Summary
ConstructorsConstructorDescriptionArchive(VolumeManager volumeManager, UnrarCallback unrarCallback, String password) Archive(File firstVolume, UnrarCallback unrarCallback) Archive(File firstVolume, UnrarCallback unrarCallback, String password) Archive(InputStream rarAsStream) Archive(InputStream rarAsStream, UnrarCallback unrarCallback) Archive(InputStream rarAsStream, UnrarCallback unrarCallback, String password) Archive(InputStream rarAsStream, String password) -
Method Summary
Modifier and TypeMethodDescriptionvoidbytesReadRead(int count) voidclose()Close the underlying compressed file.private voiddoExtractFile(FileHeader hd, OutputStream os) voidextractFile(FileHeader hd, OutputStream os) Extract the file specified by the given header and write it to the supplied output streamGets all of the headers in the archive.Returns anInputStreamthat will allow to read the file and stream it.private static <T> TgetPropertyAs(String key, Function<String, T> function, T defaultValue) booleanbooleanbooleaniterator()private voidreadHeaders(long fileLength) Read the headers of the archiveprivate static byte[]safelyAllocate(long len, int maxSize) private voidsetChannel(SeekableReadOnlyByteChannel channel, long length) voidsetPassword(String password) voidvoidsetVolumeManager(VolumeManager volumeManager) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
MAX_HEADER_SIZE
private static final int MAX_HEADER_SIZE- See Also:
-
PIPE_BUFFER_SIZE
private static final int PIPE_BUFFER_SIZE -
USE_EXECUTOR
private static final boolean USE_EXECUTOR -
channel
-
unrarCallback
-
dataIO
-
headers
-
markHead
-
newMhd
-
unpack
-
currentHeaderIndex
private int currentHeaderIndex -
totalPackedSize
private long totalPackedSizeSize of packed data in current file. -
totalPackedRead
private long totalPackedReadNumber of bytes of compressed data read from current file. -
volumeManager
-
volume
-
nextFileHeader
-
password
-
-
Constructor Details
-
Archive
public Archive(VolumeManager volumeManager, UnrarCallback unrarCallback, String password) throws RarException, IOException - Throws:
RarExceptionIOException
-
Archive
- Throws:
RarExceptionIOException
-
Archive
- Throws:
RarExceptionIOException
-
Archive
- Throws:
RarExceptionIOException
-
Archive
public Archive(File firstVolume, UnrarCallback unrarCallback, String password) throws RarException, IOException - Throws:
RarExceptionIOException
-
Archive
- Throws:
RarExceptionIOException
-
Archive
public Archive(InputStream rarAsStream, UnrarCallback unrarCallback) throws RarException, IOException - Throws:
RarExceptionIOException
-
Archive
- Throws:
IOExceptionRarException
-
Archive
public Archive(InputStream rarAsStream, UnrarCallback unrarCallback, String password) throws IOException, RarException - Throws:
IOExceptionRarException
-
-
Method Details
-
setChannel
private void setChannel(SeekableReadOnlyByteChannel channel, long length) throws IOException, RarException - Throws:
IOExceptionRarException
-
bytesReadRead
public void bytesReadRead(int count) -
getChannel
-
getHeaders
-
getFileHeaders
- Returns:
- returns all file headers of the archive
-
nextFileHeader
-
getUnrarCallback
-
isEncrypted
- Returns:
- whether the archive is encrypted
- Throws:
RarException- when the main header is not present
-
isPasswordProtected
- Returns:
- whether the archive content is password protected
- Throws:
RarException- when the main header is not present
-
readHeaders
Read the headers of the archive- Parameters:
fileLength- Length of file.- Throws:
IOExceptionRarException
-
safelyAllocate
- Throws:
RarException
-
extractFile
Extract the file specified by the given header and write it to the supplied output stream- Parameters:
hd- the header to be extractedos- the outputstream- Throws:
RarException- .
-
getPropertyAs
-
getInputStream
Returns anInputStreamthat will allow to read the file and stream it.
Please note that this method will create a pair of Pipe streams and either:
- delegate the work to a
ThreadPoolExecutor, viaArchive.ExtractorExecutorHolder; or - delegate the work to a newly created thread on each call
You can choose which strategy to use by setting the
junrar.extractor.use-executorsystem property.
Defaults to using theThreadPoolExecutor.- Parameters:
hd- the header to be extracted- Returns:
- an
InputStreamfrom which you can read the uncompressed bytes - Throws:
IOException- if any I/O error occur- See Also:
- delegate the work to a
-
doExtractFile
- Throws:
RarExceptionIOException
-
getMainHeader
- Returns:
- returns the main header of this archive
-
isOldFormat
public boolean isOldFormat()- Returns:
- whether the archive is old format
-
close
Close the underlying compressed file.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getVolumeManager
- Returns:
- the volumeManager
-
setVolumeManager
- Parameters:
volumeManager- the volumeManager to set
-
getVolume
- Returns:
- the volume
-
getPassword
-
setPassword
-
setVolume
- Parameters:
volume- the volume to set- Throws:
IOException- .RarException- .
-
iterator
- Specified by:
iteratorin interfaceIterable<FileHeader>
-