Class SevenZipArchive

    • Constructor Detail

      • SevenZipArchive

        public SevenZipArchive()

        Initializes a new instance of the SevenZipArchive class with optional settings for its entries.

        The following example shows how to compress a single file with default settings: LZMA compression without encryption.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("data.bin", "file.dat");
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         
        LZMA compression without encryption would be used.
      • SevenZipArchive

        public SevenZipArchive​(SevenZipEntrySettings newEntrySettings)

        Initializes a new instance of the SevenZipArchive class with optional settings for its entries.

        The following example shows how to compress a single file with default settings: LZMA compression without encryption.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("data.bin", "file.dat");
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        newEntrySettings - compression and encryption settings used for newly added SevenZipArchiveEntry items. If not specified, LZMA compression without encryption would be used
      • SevenZipArchive

        public SevenZipArchive​(InputStream sourceStream)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive(new FileInputStream("archive.7z"))) {
                 archive.extractToDirectory("C:\\extracted");
             } catch (FileNotFoundException ex) {
             }
         

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        Parameters:
        sourceStream - the source of the archive
        Throws:
        com.aspose.ms.System.ArgumentException - sourceStream is not seekable.
        com.aspose.ms.System.ArgumentNullException - sourceStream is null.
        com.aspose.ms.System.NotImplementedException - The archive contains more than one coder.
      • SevenZipArchive

        public SevenZipArchive​(InputStream sourceStream,
                               String password)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive(new FileInputStream("archive.7z"))) {
                 archive.extractToDirectory("C:\\extracted");
             } catch (FileNotFoundException ex) {
             }
         

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        Parameters:
        sourceStream - the source of the archive
        password - optional password for decryption. If file names are encrypted, it must be present
        Throws:
        com.aspose.ms.System.ArgumentException - sourceStream is not seekable.
        com.aspose.ms.System.ArgumentNullException - sourceStream is null.
        com.aspose.ms.System.NotImplementedException - The archive contains more than one coder.
      • SevenZipArchive

        public SevenZipArchive​(String path)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
                 archive.extractToDirectory("C:\\extracted");
             } catch (FileNotFoundException ex) {
             }
         

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        Parameters:
        path - the fully qualified or the relative path to the archive 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.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • SevenZipArchive

        public SevenZipArchive​(String path,
                               String password)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
                 archive.extractToDirectory("C:\\extracted");
             } catch (FileNotFoundException ex) {
             }
         

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        Parameters:
        path - the fully qualified or the relative path to the archive file
        password - optional password for decryption. If file names are encrypted, it must be present
        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.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • SevenZipArchive

        public SevenZipArchive​(InputStream sourceStream,
                               SevenZipLoadOptions options)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        Extract an encrypted archive. Allow up to 60 seconds to proceed, cancel after that period.

        
             try (CancellationFlag cf = new CancellationFlag()) {
                 SevenZipLoadOptions options = new SevenZipLoadOptions();
                 options.setDecryptionPassword("Top$ecr3t");
                 options.setCancellationFlag(cf);
                 cf.cancelAfter(TimeUnit.SECONDS.toMillis(60));
                 try (SevenZipArchive a = new SevenZipArchive(new FileInputStream("archive.7z"), options)) {
                     a.extractToDirectory("C:\\extracted");
                 } catch (IOException ex) {
                 }
             }
         

        Parameters:
        sourceStream - The source of the archive.
        options - Options to load existing archive with.

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        Throws:
        com.aspose.ms.System.ArgumentException - sourceStream is not seekable.
        com.aspose.ms.System.ArgumentNullException - sourceStream is null.
        com.aspose.ms.System.NotImplementedException - The archive contains more than one coder. Now only LZMA compression supported.
      • SevenZipArchive

        public SevenZipArchive​(String path,
                               SevenZipLoadOptions options)

        Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.

        Extract an encrypted archive. Allow up to 60 seconds to proceed, cancel after that period.

        
             try (CancellationFlag cf = new CancellationFlag()) {
                 SevenZipLoadOptions options = new SevenZipLoadOptions();
                 options.setDecryptionPassword("Top$ecr3t");
                 options.setCancellationFlag(cf);
                 cf.cancelAfter(TimeUnit.SECONDS.toMillis(60));
                 try (SevenZipArchive a = new SevenZipArchive(new FileInputStream("archive.7z"), options)) {
                     a.extractToDirectory("C:\\extracted");
                 } catch (IOException ex) {
                 }
             }
         

        Parameters:
        path - The fully qualified or the relative path to the archive file.
        options - Options to load existing archive with.

        This constructor does not decompress any entry. See extractToDirectory(String, String) method for decompressing.

        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.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • SevenZipArchive

        public SevenZipArchive​(String[] parts)

        Initializes a new instance of the SevenZipArchive class from multi-volume 7z archive and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive(new String[] { "multi.7z.001", "multi.7z.002", "multi.7z.003" } )) {
                 archive.extractToDirectory("C:\\extracted");
             }
         
        Parameters:
        parts - paths to each segment of multi-volume 7z archive respecting order
        Throws:
        com.aspose.ms.System.ArgumentNullException - parts is null.
        com.aspose.ms.System.ArgumentException - parts has no entries.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path to a file is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path to a part, 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 a path contains a colon (:) in the middle of the string.
      • SevenZipArchive

        public SevenZipArchive​(String[] parts,
                               String password)

        Initializes a new instance of the SevenZipArchive class from multi-volume 7z archive and composes an entry list can be extracted from the archive.

        
             try (SevenZipArchive archive = new SevenZipArchive(new String[] { "multi.7z.001", "multi.7z.002", "multi.7z.003" } )) {
                 archive.extractToDirectory("C:\\extracted");
             }
         
        Parameters:
        parts - paths to each segment of multi-volume 7z archive respecting order
        password - optional password for decryption. If file names are encrypted, it must be present
        Throws:
        com.aspose.ms.System.ArgumentNullException - parts is null.
        com.aspose.ms.System.ArgumentException - parts has no entries.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path to a file is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path to a part, 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 a path contains a colon (:) in the middle of the string.
    • Method Detail

      • getFormat

        public final ArchiveFormat getFormat()

        Gets the archive format.

        Specified by:
        getFormat in interface IArchive
        Returns:
        the archive format
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      File file)

        Creates a single entry within the archive.

        Compose archive with entries encrypted with different passwords each.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 File fi1 = new File("data1.bin");
                 File fi2 = new File("data2.bin");
                 File fi3 = new File("data3.bin");
        
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("entry1.bin", fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
                     archive.createEntry("entry2.bin", fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test2")));
                     archive.createEntry("entry3.bin", fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test3")));
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in file parameter does not affect the entry name.

        Parameters:
        name - the name of the entry
        file - the metadata of file to be compressed
        Returns:
        Seven Zip entry instance
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      File file,
                                                      boolean openImmediately)

        Creates a single entry within the archive.

        Compose archive with entries encrypted with different passwords each.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 File fi1 = new File("data1.bin");
                 File fi2 = new File("data2.bin");
                 File fi3 = new File("data3.bin");
        
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("entry1.bin", fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
                     archive.createEntry("entry2.bin", fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test2")));
                     archive.createEntry("entry3.bin", fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test3")));
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in file parameter does not affect the entry name.

        If the file is opened immediately with openImmediately parameter it becomes blocked until archive is saved.

        Parameters:
        name - the name of the entry
        file - the metadata of file to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        Returns:
        Seven Zip entry instance
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      File file,
                                                      boolean openImmediately,
                                                      SevenZipEntrySettings newEntrySettings)

        Creates a single entry within the archive.

        Compose archive with entries encrypted with different passwords each.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 File fi1 = new File("data1.bin");
                 File fi2 = new File("data2.bin");
                 File fi3 = new File("data3.bin");
        
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("entry1.bin", fi1, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test1")));
                     archive.createEntry("entry2.bin", fi2, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test2")));
                     archive.createEntry("entry3.bin", fi3, false, new SevenZipEntrySettings(new SevenZipStoreCompressionSettings(), new SevenZipAESEncryptionSettings("test3")));
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in file parameter does not affect the entry name.

        If the file is opened immediately with openImmediately parameter it becomes blocked until archive is saved.

        Parameters:
        name - the name of the entry
        file - the metadata of file to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        newEntrySettings - compression and encryption settings used for added SevenZipArchiveEntry item. Individual compression settings is ignored in case of solid compression, see SevenZipEntrySettings.Solid(SevenZipEntrySettings.getSolid()/SevenZipEntrySettings.setSolid(boolean)).
        Returns:
        Seven Zip entry instance
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      InputStream source,
                                                      SevenZipEntrySettings newEntrySettings,
                                                      File file)

        Creates a single entry within the archive.

        Compose archive with LZMA compressed encrypted entry.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive()) {
                     archive.createEntry("entry1.bin", new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF}), new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings("test1")), new File("data1.bin"));
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in file parameter does not affect the entry name.

        file can refer to directory.

        Parameters:
        name - the name of the entry
        source - the input stream for the entry
        newEntrySettings - compression and encryption settings used for added SevenZipArchiveEntry item. Individual compression settings is ignored in case of solid compression, see SevenZipEntrySettings.Solid(SevenZipEntrySettings.getSolid()/SevenZipEntrySettings.setSolid(boolean)).
        file - the metadata of file or folder to be compressed
        Returns:
        Seven Zip entry instance
        Throws:
        com.aspose.ms.System.InvalidOperationException - Both source and file are null or source is null and file stands for directory.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      InputStream source)

        Creates a single entry within the archive.

        Compose 7z archive with LZMA compression and encryption of all entries.

        
             try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings("p@s$")))) {
                 archive.createEntry("data.bin", new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF} ));
                 archive.save("archive.7z");
             }
         
        Parameters:
        name - the name of the entry
        source - the input stream for the entry
        Returns:
        Seven Zip entry instance
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      InputStream source,
                                                      SevenZipEntrySettings newEntrySettings)

        Creates a single entry within the archive.

        Compose 7z archive with LZMA compression and encryption of all entries.

        
             try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings(), new SevenZipAESEncryptionSettings("p@s$")))) {
                 archive.createEntry("data.bin", new ByteArrayInputStream(new byte[] {0x00, (byte)0xFF} ));
                 archive.save("archive.7z");
             }
         
        Parameters:
        name - the name of the entry
        source - the input stream for the entry
        newEntrySettings - compression and encryption settings used for added SevenZipArchiveEntry item. Individual compression settings is ignored in case of solid compression, see SevenZipEntrySettings.Solid(SevenZipEntrySettings.getSolid()/SevenZipEntrySettings.setSolid(boolean)).
        Returns:
        Seven Zip entry instance
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      String path)

        Creates a single entry within the archive.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                     archive.createEntry("data.bin", "file.dat");
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

        Parameters:
        name - the name of the entry
        path - the fully qualified name of the new file, or the relative file name to be compressed
        Returns:
        Seven Zip entry instance
        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.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      String path,
                                                      boolean openImmediately)

        Creates a single entry within the archive.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                     archive.createEntry("data.bin", "file.dat");
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

        If the file is opened immediately with openImmediately parameter it becomes blocked until archive is saved.

        Parameters:
        name - the name of the entry
        path - the fully qualified name of the new file, or the relative file name to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        Returns:
        Seven Zip entry instance
        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.
      • createEntry

        public final SevenZipArchiveEntry createEntry​(String name,
                                                      String path,
                                                      boolean openImmediately,
                                                      SevenZipEntrySettings newEntrySettings)

        Creates a single entry within the archive.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                     archive.createEntry("data.bin", "file.dat");
                     archive.save(sevenZipFile);
                 }
             } catch (IOException ex) {
             }
         

        The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

        If the file is opened immediately with openImmediately parameter it becomes blocked until archive is saved.

        Parameters:
        name - the name of the entry
        path - the fully qualified name of the new file, or the relative file name to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        newEntrySettings - compression and encryption settings used for added SevenZipArchiveEntry item. Individual compression settings is ignored in case of solid compression, see SevenZipEntrySettings.Solid(SevenZipEntrySettings.getSolid()/SevenZipEntrySettings.setSolid(boolean)).
        Returns:
        Zip entry instance
        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.
      • createEntries

        public final SevenZipArchive createEntries​(File directory)

        Adds to the archive all files and directories recursively in the directory given.

        
             try (SevenZipArchive archive = new SevenZipArchive()) {
                 File folder = new File("C:\\folder");
                 archive.createEntries(folder);
                 archive.save("folder.7z");
             }
         
        Parameters:
        directory - directory to compress
        Returns:
        the archive with entries composed
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - The path to directory is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access directory.
      • createEntries

        public final SevenZipArchive createEntries​(File directory,
                                                   boolean includeRootDirectory)

        Adds to the archive all files and directories recursively in the directory given.

        
             try (SevenZipArchive archive = new SevenZipArchive()) {
                 File folder = new File("C:\\folder");
                 archive.createEntries(folder);
                 archive.save("folder.7z");
             }
         
        Parameters:
        directory - directory to compress
        includeRootDirectory - indicates whether to include the root directory itself or not
        Returns:
        the archive with entries composed
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - The path to directory is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access directory.
      • createEntries

        public final SevenZipArchive createEntries​(String sourceDirectory)

        Adds to the archive all files and directories recursively in the directory given.

        Compose 7z archive with LZMA compression.

        
             try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                 archive.createEntries("C:\\folder");
                 archive.save("folder.7z");
             }
         
        Parameters:
        sourceDirectory - directory to compress
        Returns:
        the archive with entries composed
      • createEntries

        public final SevenZipArchive createEntries​(String sourceDirectory,
                                                   boolean includeRootDirectory)

        Adds to the archive all files and directories recursively in the directory given.

        Compose 7z archive with LZMA compression.

        
             try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                 archive.createEntries("C:\\folder");
                 archive.save("folder.7z");
             }
         
        Parameters:
        sourceDirectory - directory to compress
        includeRootDirectory - indicates whether to include the root directory itself or not
        Returns:
        the archive with entries composed
      • save

        public final void save​(OutputStream output)

        Saves 7z archive to the stream provided.

        
             try (FileOutputStream sevenZipFile = new FileOutputStream("archive.7z")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (SevenZipArchive archive = new SevenZipArchive()) {
                         archive.createEntry("data", source);
                         archive.save(sevenZipFile);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.InvalidOperationException - Encoder failed to compress data.
      • save

        public final void save​(String destinationFileName)

        Saves archive to a destination file provided.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (SevenZipArchive archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings()))) {
                     archive.createEntry("data", source);
                     archive.save("archive.7z");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        destinationFileName - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.

        It is possible to save an archive to the same path as it was loaded from. However, this is not recommended because this approach uses copying to a temporary file.

        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationFileName is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The destinationFileName is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified destinationFileName, 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 destinationFileName contains a colon (:) in the middle of the string.
      • saveSplit

        public final void saveSplit​(String destinationDirectory,
                                    SplitSevenZipArchiveSaveOptions options)

        Saves multi-volume archive to destination directory provided.

        
             try (SevenZipArchive archive = new SevenZipArchive()) {
                 archive.createEntry("entry.bin", "data.bin");
                 archive.saveSplit("C:\\Folder", new SplitSevenZipArchiveSaveOptions("volume", 65536));
             }
         

        This method composes several (n) files filename.7z.001, filename.7z.002, ..., filename.7z.(n).

        Cannot make existing archive multi-volume.

        Parameters:
        destinationDirectory - the path to the directory where archive segments to be created
        options - options for archive saving, including file name
        Throws:
        com.aspose.ms.System.InvalidOperationException - This archive was opened from the existing source.
        com.aspose.ms.System.ArgumentNullException - destinationDirectory is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access the directory.
        com.aspose.ms.System.ArgumentException - destinationDirectory contains invalid characters such as ", >, <, or |.
        com.aspose.ms.System.IO.PathTooLongException - The specified path exceeds the system-defined maximum length.
      • extractToDirectory

        public final void extractToDirectory​(String destinationDirectory)

        Extracts all the files in the archive to the directory provided.

        
             try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
                 archive.extractToDirectory("C:\\extracted");
             }
         
        Specified by:
        extractToDirectory in interface IArchive
        Parameters:
        destinationDirectory - the path to the directory to place the extracted files in.

        If the directory does not exist, it will be created

        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationDirectory is null.
        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.SecurityException - The caller does not have the required permission to access the existing directory.
        com.aspose.ms.System.NotSupportedException - If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").
        com.aspose.ms.System.ArgumentException - destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters.
        com.aspose.ms.System.IO.IOException - The directory specified by path is a file. -or- The network name is not known.
        com.aspose.ms.System.IO.InvalidDataException - The archive is corrupted.
      • extractToDirectory

        public final void extractToDirectory​(String destinationDirectory,
                                             String password)

        Extracts all the files in the archive to the directory provided.

        
             try (SevenZipArchive archive = new SevenZipArchive("archive.7z")) {
                 archive.extractToDirectory("C:\\extracted");
             }
         
        Parameters:
        destinationDirectory - the path to the directory to place the extracted files in

        If the directory does not exist, it will be created.

        password - optional password for content decryption.

        password is used for content decryption only. If file names are encrypted provide password in SevenZipArchive(String, String) or SevenZipArchive(java.io.InputStream, String) constructor.

        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationDirectory is null.
        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.SecurityException - The caller does not have the required permission to access the existing directory.
        com.aspose.ms.System.NotSupportedException - If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").
        com.aspose.ms.System.ArgumentException - destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters.
        com.aspose.ms.System.IO.IOException - The directory specified by path is a file. -or- The network name is not known.
        com.aspose.ms.System.IO.InvalidDataException - The archive is corrupted.