Class RarArchiveEntry

    • Method Detail

      • getName

        public final String getName()

        Gets the name of the entry within the archive.

        Specified by:
        getName in interface IArchiveFileEntry
        Returns:
        the name of the entry within the archive
      • getCompressedSize

        public final long getCompressedSize()

        Gets size of compressed file.

        Returns:
        the size of the compressed file
      • getUncompressedSize

        public final long getUncompressedSize()

        Gets the size of the original file.

        Returns:
        the size of the original file.
      • getModificationTime

        public final Date getModificationTime()

        Gets last modified date and time.

        Returns:
        last modified date and time.
      • getCreationTime

        public final Date getCreationTime()

        Gets creation date and time.

        Returns:
        creation date and time.
      • getLastAccessTime

        public final Date getLastAccessTime()

        Gets last access date and time.

        Returns:
        last access date and time.
      • isDirectory

        public final boolean isDirectory()

        Gets a value indicating whether the entry represents a directory.

        Returns:
        a value indicating whether the entry represents a directory.
      • getExtractionProgressed

        public final Event<ProgressEventArgs> getExtractionProgressed()

        Gets an event that is raised when a portion of raw stream extracted.

        
            archive.getEntries().get(0).setExtractionProgressed(new Event<ProgressEventArgs>() {
                public void invoke(Object sender, ProgressEventArgs progressEventArgs) {
                    int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / ((RarArchiveEntry) sender).getUncompressedSize());
                }
            });
         

        Event sender is an RarArchiveEntry instance.

        Returns:
        an event that is raised when a portion of raw stream extracted.
      • setExtractionProgressed

        public final void setExtractionProgressed​(Event<ProgressEventArgs> value)

        Sets an event that is raised when a portion of raw stream extracted.

        
            archive.getEntries().get(0).setExtractionProgressed(new Event<ProgressEventArgs>() {
                public void invoke(Object sender, ProgressEventArgs progressEventArgs) {
                    int percent = (int) ((100 * (long) progressEventArgs.getProceededBytes()) / ((RarArchiveEntry) sender).getUncompressedSize());
                }
            });
         

        Event sender is an RarArchiveEntry instance.

        Parameters:
        value - an event that is raised when a portion of raw stream extracted.
      • open

        public final InputStream open()

        Opens the entry for extraction and provides a stream with decompressed entry content.


        Usage:
        
            InputStream decompressed = entry.open();
            byte[] buffer = new byte[8192];
            int bytesRead;
            while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length)))
                fileStream.write(buffer, 0, bytesRead);
         

        Read from the stream to get the original content of the file. See examples section.

        Returns:
        The stream that represents the contents of the entry.
      • open

        public final InputStream open​(String password)

        Opens the entry for extraction and provides a stream with decompressed entry content.


        Usage:
        
            InputStream decompressed = entry.open();
            byte[] buffer = new byte[8192];
            int bytesRead;
            while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length)))
                fileStream.write(buffer, 0, bytesRead);
         

        Read from the stream to get the original content of the file. See examples section.

        Parameters:
        password - Optional password for decryption. It can also be set within RarArchiveLoadOptions.setDecryptionPassword(String).
        Returns:
        The stream that represents the contents of the entry.
      • extract

        public final File extract​(String path)

        Extracts the entry to the filesystem by the path provided.


        Extract two entries of rar archive.
        
            try (FileInputStream rarFile = new FileInputStream("archive.rar")) {
                try (RarArchive archive = new RarArchive(rarFile)) {
                    archive.getEntries().get(0).extract("first.bin", "pass");
                    archive.getEntries().get(1).extract("second.bin", "pass");
                }
            } catch (IOException ex) {
            }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        path - the path to destination file. If the file already exists, it will be overwritten
        Returns:
        the file info of the extracted file
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
        com.aspose.ms.System.IO.InvalidDataException - CRC or MAC verification failed for the entry.
      • extract

        public final File extract​(String path,
                                  String password)

        Extracts the entry to the filesystem by the path provided.


        Extract two entries of rar archive.
        
            try (FileInputStream rarFile = new FileInputStream("archive.rar")) {
                try (RarArchive archive = new RarArchive(rarFile)) {
                    archive.getEntries().get(0).extract("first.bin", "pass");
                    archive.getEntries().get(1).extract("second.bin", "pass");
                }
            } catch (IOException ex) {
            }
         
        Parameters:
        path - The path to destination file. If the file already exists, it will be overwritten.
        password - Optional password for decryption.
        Returns:
        the file info of the extracted file
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
        com.aspose.ms.System.IO.InvalidDataException - CRC or MAC verification failed for the entry.
      • extract

        public final void extract​(OutputStream destination)

        Extracts the entry to the stream provided.


        Extract an entry of rar archive with password.
        
            try (FileInputStream rarFile = new FileInputStream("archive.rar")) {
                try (RarArchive archive = new RarArchive(rarFile)) {
                    archive.getEntries().get(0).extract(outputStream, "p@s$");
                }
            } catch (IOException ex) {
            }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        destination - Destination stream. Must be writable.
        Throws:
        com.aspose.ms.System.IO.InvalidDataException - CRC or MAC verification failed for the entry.
        com.aspose.ms.System.ArgumentException - destination does not support writing.
      • extract

        public final void extract​(OutputStream destination,
                                  String password)

        Extracts the entry to the stream provided.


        Extract an entry of rar archive with password.
        
            try (FileInputStream rarFile = new FileInputStream("archive.rar")) {
                try (RarArchive archive = new RarArchive(rarFile)) {
                    archive.getEntries().get(0).extract(outputStream, "p@s$");
                }
            } catch (IOException ex) {
            }
         
        Parameters:
        destination - Destination stream. Must be writable.
        password - Optional password for decryption.
        Throws:
        com.aspose.ms.System.IO.InvalidDataException - CRC or MAC verification failed for the entry.
        com.aspose.ms.System.ArgumentException - destination does not support writing.