Class Archive

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<FileHeader>

    public class Archive
    extends java.lang.Object
    implements java.io.Closeable, java.lang.Iterable<FileHeader>
    The Main Rar Class; represents a rar Archive
    Version:
    $LastChangedRevision$
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • PIPE_BUFFER_SIZE

        private static final int PIPE_BUFFER_SIZE
      • USE_EXECUTOR

        private static final boolean USE_EXECUTOR
      • headers

        private final java.util.List<BaseBlock> headers
      • unpack

        private Unpack unpack
      • currentHeaderIndex

        private int currentHeaderIndex
      • totalPackedSize

        private long totalPackedSize
        Size of packed data in current file.
      • totalPackedRead

        private long totalPackedRead
        Number of bytes of compressed data read from current file.
      • volume

        private Volume volume
      • nextFileHeader

        private FileHeader nextFileHeader
      • password

        private java.lang.String password
    • Constructor Detail

      • Archive

        public Archive​(java.io.File firstVolume)
                throws RarException,
                       java.io.IOException
        Throws:
        RarException
        java.io.IOException
      • Archive

        public Archive​(java.io.File firstVolume,
                       java.lang.String password)
                throws RarException,
                       java.io.IOException
        Throws:
        RarException
        java.io.IOException
      • Archive

        public Archive​(java.io.File firstVolume,
                       UnrarCallback unrarCallback,
                       java.lang.String password)
                throws RarException,
                       java.io.IOException
        Throws:
        RarException
        java.io.IOException
      • Archive

        public Archive​(java.io.InputStream rarAsStream)
                throws RarException,
                       java.io.IOException
        Throws:
        RarException
        java.io.IOException
      • Archive

        public Archive​(java.io.InputStream rarAsStream,
                       java.lang.String password)
                throws java.io.IOException,
                       RarException
        Throws:
        java.io.IOException
        RarException
      • Archive

        public Archive​(java.io.InputStream rarAsStream,
                       UnrarCallback unrarCallback,
                       java.lang.String password)
                throws java.io.IOException,
                       RarException
        Throws:
        java.io.IOException
        RarException
    • Method Detail

      • bytesReadRead

        public void bytesReadRead​(int count)
      • getHeaders

        public java.util.List<BaseBlock> getHeaders()
        Gets all of the headers in the archive.
        Returns:
        returns the headers.
      • getFileHeaders

        public java.util.List<FileHeader> getFileHeaders()
        Returns:
        returns all file headers of the archive
      • nextFileHeader

        public FileHeader nextFileHeader()
      • isEncrypted

        public boolean isEncrypted()
                            throws RarException
        Returns:
        whether the archive is encrypted
        Throws:
        RarException - when the main header is not present
      • isPasswordProtected

        public boolean isPasswordProtected()
                                    throws RarException
        Returns:
        whether the archive content is password protected
        Throws:
        RarException - when the main header is not present
      • readHeaders

        private void readHeaders​(long fileLength)
                          throws java.io.IOException,
                                 RarException
        Read the headers of the archive
        Parameters:
        fileLength - Length of file.
        Throws:
        java.io.IOException
        RarException
      • safelyAllocate

        private static byte[] safelyAllocate​(long len,
                                             int maxSize)
                                      throws RarException
        Throws:
        RarException
      • extractFile

        public void extractFile​(FileHeader hd,
                                java.io.OutputStream os)
                         throws RarException
        Extract the file specified by the given header and write it to the supplied output stream
        Parameters:
        hd - the header to be extracted
        os - the outputstream
        Throws:
        RarException - .
      • getPropertyAs

        private static <T> T getPropertyAs​(java.lang.String key,
                                           java.util.function.Function<java.lang.String,​T> function,
                                           T defaultValue)
      • getInputStream

        public java.io.InputStream getInputStream​(FileHeader hd)
                                           throws java.io.IOException
        Returns an InputStream that will allow to read the file and stream it.
        Please note that this method will create a pair of Pipe streams and either:

        You can choose which strategy to use by setting the junrar.extractor.use-executor system property.
        Defaults to using the ThreadPoolExecutor.

        Parameters:
        hd - the header to be extracted
        Returns:
        an InputStream from which you can read the uncompressed bytes
        Throws:
        java.io.IOException - if any I/O error occur
        See Also:
        Archive.ExtractorExecutorHolder
      • doExtractFile

        private void doExtractFile​(FileHeader hd,
                                   java.io.OutputStream os)
                            throws RarException,
                                   java.io.IOException
        Throws:
        RarException
        java.io.IOException
      • getMainHeader

        public MainHeader getMainHeader()
        Returns:
        returns the main header of this archive
      • isOldFormat

        public boolean isOldFormat()
        Returns:
        whether the archive is old format
      • close

        public void close()
                   throws java.io.IOException
        Close the underlying compressed file.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • getVolumeManager

        public VolumeManager getVolumeManager()
        Returns:
        the volumeManager
      • setVolumeManager

        public void setVolumeManager​(VolumeManager volumeManager)
        Parameters:
        volumeManager - the volumeManager to set
      • getVolume

        public Volume getVolume()
        Returns:
        the volume
      • getPassword

        public java.lang.String getPassword()
      • setPassword

        public void setPassword​(java.lang.String password)
      • setVolume

        public void setVolume​(Volume volume)
                       throws java.io.IOException,
                              RarException
        Parameters:
        volume - the volume to set
        Throws:
        java.io.IOException - .
        RarException - .
      • iterator

        public java.util.Iterator<FileHeader> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<FileHeader>