Class TarArchive

    • Constructor Detail

      • TarArchive

        public TarArchive()

        Initializes a new instance of the TarArchive class.

        The following example shows how to compress a file.

        
             try (TarArchive archive = new TarArchive()) {
                     archive.createEntry(first.bin, "data.bin");
                     archive.save("archive.tar");
             }
         
      • TarArchive

        public TarArchive​(InputStream sourceStream)

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

        The following example shows how to extract all the entries to a directory.

        
             try (TarArchive archive = new TarArchive(new FileInputStream("archive.tar"))) {
                     archive.extractToDirectory("C:\\extracted");
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         

        This constructor does not unpack any entry. See TarEntry.open() method for unpacking.

        Parameters:
        sourceStream - the source of the archive
      • TarArchive

        public TarArchive​(String path)

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

        The following example shows how to extract all the entries to a directory.

        
             try (TarArchive archive = new TarArchive("archive.tar")) {
                 archive.extractToDirectory("C:\\extracted");
             }
         

        This constructor does not unpack any entry. See TarEntry.open() method for unpacking.

        Parameters:
        path - the 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.
    • Method Detail

      • getEntries

        public final List<TarEntry> getEntries()

        Gets entries of TarEntry type constituting the archive.

        Returns:
        entries of TarEntry type constituting the archive
      • getFormat

        public final ArchiveFormat getFormat()

        Gets the archive format.

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

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

        Creates a single entry within the archive.

        
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("bytes", new ByteArrayInputStream(new byte[] {0x00, (byte) 0xFF}));
                 archive.save(tarFile);
             }
         

        The entry name is solely set within name parameter.

        Parameters:
        name - the name of the entry
        source - the input stream for the entry
        Returns:
        Tar entry instance
        Throws:
        com.aspose.ms.System.IO.PathTooLongException - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.ArgumentException - File name, as a part of name, exceeds 100 symbols.
      • createEntry

        public final TarEntry createEntry​(String name,
                                          InputStream source,
                                          File file)

        Creates a single entry within the archive.

        
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("bytes", new ByteArrayInputStream(new byte[] {0x00, (byte) 0xFF}));
                 archive.save(tarFile);
             }
         

        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
        source - the input stream for the entry
        file - the metadata of file or folder to be compressed
        Returns:
        Tar entry instance
        Throws:
        com.aspose.ms.System.IO.PathTooLongException - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.ArgumentException - File name, as a part of name, exceeds 100 symbols.
      • createEntry

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

        Creates a single entry within the archive.

        
             File fi = new File("data.bin");
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("data.bin", fi);
                 archive.save(tarFile);
             }
         

        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 or folder to be compressed
        Returns:
        Tar entry instance
        Throws:
        com.aspose.ms.System.IO.PathTooLongException - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.ArgumentException - File name, as a part of name, exceeds 100 symbols.
      • createEntry

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

        Creates a single entry within the archive.

        
             File fi = new File("data.bin");
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("data.bin", fi);
                 archive.save(tarFile);
             }
         

        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 disposed.

        Parameters:
        name - the name of the entry
        file - the metadata of file or folder to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        Returns:
        Tar entry instance
        Throws:
        com.aspose.ms.System.IO.PathTooLongException - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.ArgumentException - File name, as a part of name, exceeds 100 symbols.
      • createEntry

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

        Creates a single entry within the archive.

        
             try (TarArchive archive = new TarArchive()) {
                     archive.createEntry(first.bin, "data.bin");
                     archive.save(outputTarFile);
             }
         

        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 - path to file to be compressed
        Returns:
        Tar 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. - or - File name, as a part of name, exceeds 100 symbols.
        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. - or - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
      • createEntry

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

        Creates a single entry within the archive.

        
             try (TarArchive archive = new TarArchive()) {
                     archive.createEntry(first.bin, "data.bin");
                     archive.save(outputTarFile);
             }
         

        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 disposed.

        Parameters:
        name - the name of the entry
        path - path to file to be compressed
        openImmediately - true, if open the file immediately, otherwise open the file on archive saving
        Returns:
        Tar 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. - or - File name, as a part of name, exceeds 100 symbols.
        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. - or - name is too long for tar as of IEEE 1003.1-1998 standard.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
      • createEntries

        public final TarArchive createEntries​(File directory)

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

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntries(new java.io.File("C:\\folder"), false);
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        directory - directory to compress
        Returns:
        the archive with entries composed
      • createEntries

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

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

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntries(new java.io.File("C:\\folder"), false);
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        directory - directory to compress
        includeRootDirectory - indicates whether to include the root directory itself or not
        Returns:
        the archive with entries composed
      • createEntries

        public final TarArchive createEntries​(String sourceDirectory)

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

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntries("C:\\folder", false);
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        sourceDirectory - directory to compress
        Returns:
        the archive with entries composed
        Throws:
        com.aspose.ms.System.ArgumentNullException - sourceDirectory is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access sourceDirectory.
        com.aspose.ms.System.ArgumentException - sourceDirectory contains invalid characters such as ", <, >, or |.
        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. The specified path, file name, or both are too long.
      • createEntries

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

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

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntries("C:\\folder", false);
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        sourceDirectory - 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.ArgumentNullException - sourceDirectory is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access sourceDirectory.
        com.aspose.ms.System.ArgumentException - sourceDirectory contains invalid characters such as ", <, >, or |.
        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. The specified path, file name, or both are too long.
      • deleteEntry

        public final TarArchive deleteEntry​(TarEntry entry)

        Removes the first occurrence of a specific entry from the entry list.

        Here is how you can remove all entries except the last one:

        
             try (TarArchive archive = new TarArchive("archive.tar")) {
                 while (archive.getEntries().size() > 1)
                     archive.deleteEntry(archive.getEntries().get_Item(0));
                 archive.save(outputTarFile);
             }
         
        Parameters:
        entry - the entry to remove from the entries list
        Returns:
        the archive with the entry deleted
      • deleteEntry

        public final TarArchive deleteEntry​(int entryIndex)

        Removes the entry from the entry list by index.

        
             try (TarArchive archive = new TarArchive("two_files.tar")) {
                 archive.deleteEntry(0);
                 archive.save("single_file.tar");
             }
         
        Parameters:
        entryIndex - the zero-based index of the entry to remove
        Returns:
        the archive with the entry deleted
        Throws:
        com.aspose.ms.System.ArgumentOutOfRangeException - entryIndex is less than 0.-or- entryIndex is equal to or greater than Entries count.
      • extractToDirectory

        public final void extractToDirectory​(String destinationDirectory)

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

        
             try (TarArchive archive = new TarArchive("archive.tar")) {
                 archive.extractToDirectory("C:\\extracted");
             }
         

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

        Specified by:
        extractToDirectory in interface IArchive
        Parameters:
        destinationDirectory - the path to the directory to place the extracted files in
        Throws:
        com.aspose.ms.System.ArgumentNullException - path 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 - path 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.
      • save

        public final void save​(OutputStream output)

        Saves archive to the stream provided.

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry1", "data.bin");
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        Throws:
        com.aspose.ms.System.ArgumentException - output is not writable, or output is the same stream we extract from, or it is impossible to save archive in format due to format restrictions.
      • save

        public final void save​(OutputStream output,
                               TarFormat format)

        Saves archive to the stream provided.

        
             try (FileOutputStream tarFile = new FileOutputStream("archive.tar")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry1", "data.bin");
                     archive.save(tarFile);
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentException - output is not writable, or output is the same stream we extract from, or it is impossible to save archive in format due to format restrictions.
      • save

        public final void save​(String destinationFileName)

        Saves archive to the destination file provided.

        
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry1", "data.bin");
                 archive.save("myarchive.tar");
             }
         

        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

        Parameters:
        destinationFileName - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
        Throws:
        com.aspose.ms.System.ArgumentException - destinationFileName is a zero-length string, contains only white space, or contains one or more invalid characters.
        com.aspose.ms.System.ArgumentNullException - destinationFileName is null.
        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.IO.DirectoryNotFoundException - The specified destinationFileName is invalid, (for example, it is on an unmapped drive).
        com.aspose.ms.System.IO.IOException - An I/O error occurred while opening the file.
        com.aspose.ms.System.NotSupportedException - destinationFileName is in an invalid format.
      • save

        public final void save​(String destinationFileName,
                               TarFormat format)

        Saves archive to the destination file provided.

        
             try (TarArchive archive = new TarArchive()) {
                 archive.createEntry("entry1", "data.bin");
                 archive.save("myarchive.tar");
             }
         

        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

        Parameters:
        destinationFileName - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentException - destinationFileName is a zero-length string, contains only white space, or contains one or more invalid characters.
        com.aspose.ms.System.ArgumentNullException - destinationFileName is null.
        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.IO.DirectoryNotFoundException - The specified destinationFileName is invalid, (for example, it is on an unmapped drive).
        com.aspose.ms.System.IO.IOException - An I/O error occurred while opening the file.
        com.aspose.ms.System.NotSupportedException - destinationFileName is in an invalid format.
      • saveGzipped

        public final void saveGzipped​(OutputStream output)

        Saves archive to the stream with gzip compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.gz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveGzipped(result);
                     }
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveGzipped

        public final void saveGzipped​(OutputStream output,
                                      TarFormat format)

        Saves archive to the stream with gzip compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.gz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveGzipped(result);
                     }
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveGzipped

        public final void saveGzipped​(String path)

        Saves archive to the file by path with gzip compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveGzipped("result.tar.gz");
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveGzipped

        public final void saveGzipped​(String path,
                                      TarFormat format)

        Saves archive to the file by path with gzip compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveGzipped("result.tar.gz");
                 }
             } catch (IOException ex) {
                 System.out.println(ex);
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
      • saveZstandard

        public final void saveZstandard​(OutputStream output)

        Saves archive to the stream with Zstandard compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.zst")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveZstandard(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveZstandard

        public final void saveZstandard​(OutputStream output,
                                        TarFormat format)

        Saves archive to the stream with Zstandard compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.zst")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveZstandard(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveZstandard

        public final void saveZstandard​(String path)

        Saves archive to the file by path with Zstandard compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveZstandard("result.tar.zst");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveZstandard

        public final void saveZstandard​(String path,
                                        TarFormat format)

        Saves archive to the file by path with Zstandard compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveZstandard("result.tar.zst");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
      • saveLzipped

        public final void saveLzipped​(OutputStream output)

        Saves archive to the stream with lzip compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLzipped(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLzipped

        public final void saveLzipped​(OutputStream output,
                                      TarFormat format)

        Saves archive to the stream with lzip compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLzipped(result, TarFormat.Gnu);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        output must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLzipped

        public final void saveLzipped​(String path)

        Saves archive to the file by path with lzip compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLzipped("result.tar.lz");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveLzipped

        public final void saveLzipped​(String path,
                                      TarFormat format)

        Saves archive to the file by path with lzip compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLzipped("result.tar.lz", TarFormat.Gnu);
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
      • saveLZMACompressed

        public final void saveLZMACompressed​(OutputStream output)

        Saves archive to the stream with LZMA compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lzma")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLZMACompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         

        Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        output - destination stream.

        output must be writable

        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLZMACompressed

        public final void saveLZMACompressed​(OutputStream output,
                                             TarFormat format)

        Saves archive to the stream with LZMA compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lzma")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLZMACompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         

        Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        output - destination stream.

        output must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLZMACompressed

        public final void saveLZMACompressed​(String path)

        Saves archive to the file by path with lzma compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLZMACompressed("result.tar.lzma");
                 }
             } catch (IOException ex) {
             }
         

        Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveLZMACompressed

        public final void saveLZMACompressed​(String path,
                                             TarFormat format)

        Saves archive to the file by path with lzma compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLZMACompressed("result.tar.lzma");
                 }
             } catch (IOException ex) {
             }
         

        Important: tar archive is composed then compressed within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
      • saveLZ4Compressed

        public final void saveLZ4Compressed​(OutputStream output)

        Saves archive to the stream with LZ4 compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lz4")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLZ4Compressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         

        Parameters:
        output - Destination stream.
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLZ4Compressed

        public final void saveLZ4Compressed​(OutputStream output,
                                            TarFormat format)

        Saves archive to the stream with LZ4 compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.lz4")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveLZ4Compressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         

        Parameters:
        output - Destination stream.
        format - Defines the tar header format. Null value will be treated as USTar when possible.
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveLZ4Compressed

        public final void saveLZ4Compressed​(String path)

        Saves archive to the file by path with LZ4 compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLZ4Compressed("result.tar.lz4");
                 }
             } catch (IOException ex) {
             }
         

        Parameters:
        path - The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
        Throws:
        com.aspose.ms.System.ArgumentException - path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
        com.aspose.ms.System.ArgumentNullException - path 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.IO.DirectoryNotFoundException - The specified path is invalid, (for example, it is on an unmapped drive).
        com.aspose.ms.System.NotSupportedException - path is in an invalid format.
      • saveLZ4Compressed

        public final void saveLZ4Compressed​(String path,
                                            TarFormat format)

        Saves archive to the file by path with LZ4 compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveLZ4Compressed("result.tar.lz4");
                 }
             } catch (IOException ex) {
             }
         

        Parameters:
        path - The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten.
        format - Defines the tar header format. Null value will be treated as USTar when possible.
        Throws:
        com.aspose.ms.System.ArgumentException - path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.
        com.aspose.ms.System.ArgumentNullException - path 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.IO.DirectoryNotFoundException - The specified path is invalid, (for example, it is on an unmapped drive).
        com.aspose.ms.System.NotSupportedException - path is in an invalid format.
      • saveXzCompressed

        public final void saveXzCompressed​(OutputStream output)

        Saves archive to the stream with xz compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveXzCompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        outputThe stream must be writable

        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveXzCompressed

        public final void saveXzCompressed​(OutputStream output,
                                           TarFormat format)

        Saves archive to the stream with xz compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveXzCompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        outputThe stream must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveXzCompressed

        public final void saveXzCompressed​(OutputStream output,
                                           TarFormat format,
                                           XzArchiveSettings settings)

        Saves archive to the stream with xz compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.xz")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveXzCompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - destination stream.

        outputThe stream must be writable

        format - defines the tar header format. Null value will be treated as USTar when possible
        settings - set of setting particular xz archive: dictionary size, block size, check type
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveXzCompressed

        public final void saveXzCompressed​(String path)

        Saves archive to the file by path with xz compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveXzCompressed("result.tar.xz");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveXzCompressed

        public final void saveXzCompressed​(String path,
                                           TarFormat format)

        Saves archive to the file by path with xz compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveXzCompressed("result.tar.xz");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines tar header format. Null value will be treated as USTar when possible
      • saveXzCompressed

        public final void saveXzCompressed​(String path,
                                           TarFormat format,
                                           XzArchiveSettings settings)

        Saves archive to the file by path with xz compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveXzCompressed("result.tar.xz");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
        settings - set of setting particular xz archive: dictionary size, block size, check type
      • saveZCompressed

        public final void saveZCompressed​(OutputStream output)

        Saves archive to the stream with Z compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.Z")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveZCompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - the destination stream
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveZCompressed

        public final void saveZCompressed​(OutputStream output,
                                          TarFormat format)

        Saves archive to the stream with Z compression.

        
             try (FileOutputStream result = new FileOutputStream("result.tar.Z")) {
                 try (FileInputStream source = new FileInputStream("data.bin")) {
                     try (TarArchive archive = new TarArchive()) {
                         archive.createEntry("entry.bin", source);
                         archive.saveZCompressed(result);
                     }
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - the destination stream
        format - defines the tar header format. Null value will be treated as USTar when possible
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
        com.aspose.ms.System.ArgumentException - output is not writable.
      • saveZCompressed

        public final void saveZCompressed​(String path)

        Saves archive to the file by path with Z compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveZCompressed("result.tar.Z");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
      • saveZCompressed

        public final void saveZCompressed​(String path,
                                          TarFormat format)

        Saves archive to the file by path with Z compression.

        
             try (FileInputStream source = new FileInputStream("data.bin")) {
                 try (TarArchive archive = new TarArchive()) {
                     archive.createEntry("entry.bin", source);
                     archive.saveZCompressed("result.tar.Z");
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        path - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        format - defines the tar header format. Null value will be treated as USTar when possible
      • fromGZip

        public static TarArchive fromGZip​(InputStream source)

        Extracts supplied gzip archive and composes TarArchive from extracted data.

        Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        GZip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood

        Parameters:
        source - the source of the archive.
        Returns:
        an instance of TarArchive
      • fromGZip

        public static TarArchive fromGZip​(String path)

        Extracts supplied gzip archive and composes TarArchive from extracted data.

        Important: gzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        GZip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood

        Parameters:
        path - the path to the archive file.
        Returns:
        an instance of TarArchive
      • fromZstandard

        public static TarArchive fromZstandard​(InputStream source)

        Extracts supplied Zstandard archive and composes TarArchive from extracted data.

        Important: Zstandard archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        source - the source of the archive
        Returns:
        an instance of TarArchive
      • fromZstandard

        public static TarArchive fromZstandard​(String path)

        Extracts supplied Zstandard archive and composes TarArchive from extracted data.

        Important: Zstandard archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        path - the path to the archive file
        Returns:
        an instance of TarArchive
      • fromLZip

        public static TarArchive fromLZip​(InputStream source)

        Extracts supplied lzip archive and composes TarArchive from extracted data.

        Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Lzip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood

        Parameters:
        source - the source of the archive.
        Returns:
        an instance of TarArchive
      • fromLZip

        public static TarArchive fromLZip​(String path)

        Extracts supplied lzip archive and composes TarArchive from extracted data.

        Important: lzip archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Lzip extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood

        Parameters:
        path - the path to the archive file.
        Returns:
        an instance of TarArchive
      • fromLZMA

        public static TarArchive fromLZMA​(InputStream source)

        Extracts supplied LZMA archive and composes TarArchive from extracted data.

        Important: LZMA archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        LZMA extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Parameters:
        source - the source of the archive
        Returns:
        an instance of TarArchive
      • fromLZ4

        public static TarArchive fromLZ4​(String path)

        Extracts supplied LZ4 archive and composes TarArchive from extracted data.

        Important: LZ4 archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        path - The path to the archive file.

        LZ4 extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Returns:
        An instance of TarArchive
        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 is in an invalid format.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.EndOfStreamException - The file is too short.
        com.aspose.ms.System.IO.InvalidDataException - The file has the wrong signature.
      • fromLZ4

        public static TarArchive fromLZ4​(InputStream source)

        Extracts supplied LZ4 archive and composes TarArchive from extracted data.

        Important: LZ4 archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        source - The source of the archive.

        LZ4 extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Returns:
        An instance of TarArchive
        Throws:
        com.aspose.ms.System.ArgumentException - Cannot read from source
        com.aspose.ms.System.ArgumentNullException - source is null.
        com.aspose.ms.System.IO.EndOfStreamException - source is too short.
        com.aspose.ms.System.IO.InvalidDataException - The source has the wrong signature.
      • fromLZMA

        public static TarArchive fromLZMA​(String path)

        Extracts supplied LZMA archive and composes TarArchive from extracted data.

        Important: LZMA archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        LZMA extraction stream is not seekable by the nature of compression algorithm. Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Parameters:
        path - the path to the archive file
        Returns:
        an instance of TarArchive
      • fromXz

        public static TarArchive fromXz​(InputStream source)

        Extracts supplied xz format archive and composes TarArchive from extracted data.

        Important: xz archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Parameters:
        source - the source of the archive
        Returns:
        an instance of TarArchive
      • fromXz

        public static TarArchive fromXz​(String path)

        Extracts supplied xz format archive and composes TarArchive from extracted data.

        Important: xz archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Tar archive provides facility to extract arbitrary record, so it has to operate seekable stream under the hood.

        Parameters:
        path - the path to the archive file
        Returns:
        an instance of TarArchive
      • fromZ

        public static TarArchive fromZ​(InputStream source)

        Extracts supplied Z format archive and composes TarArchive from extracted data.

        Important: Z archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        source - the source of the archive
        Returns:
        an instance of TarArchive
      • fromZ

        public static TarArchive fromZ​(String path)

        Extracts supplied Z format archive and composes TarArchive from extracted data.

        Important: Z archive is fully extracted within this method, its content is kept internally. Beware of memory consumption.

        Parameters:
        path - the path to the archive file
        Returns:
        an instance of TarArchive