Class ArchiveFactory


  • public final class ArchiveFactory
    extends Object

    Detects the archive format and creates the appropriate IArchive object according to the type of archive.

    • Method Detail

      • getArchive

        public static IArchive getArchive​(String path)

        Detects the archive format and creates the appropriate IArchive object according to the type of archive specified by the given path.

        Parameters:
        path - the path to the archive to be analyzed
        Returns:
        an IArchive object representing the archive
      • getArchive

        public static IArchive getArchive​(InputStream stream)

        Detects the archive format and creates the appropriate IArchive object according to the type of archive specified by the given stream.

        Parameters:
        stream - the stream containing the archive data
        Returns:
        an IArchive object representing the archive
      • getArchive

        public static IArchive getArchive​(InputStream stream,
                                          String password)

        Detects the archive format and creates the appropriate IArchive object according to the type of encrypted archive specified by the given stream.

        Parameters:
        stream - the stream containing the archive data
        password - password to decrypt an encrypted archive
        Returns:
        an IArchive object representing the archive
      • compressDirectory

        public static void compressDirectory​(String path,
                                             String outputFileName,
                                             ArchiveFormat archiveFormat)

        Compresses the specified directory into an archive file using the provided archive format.

        Here is an example of how to use the CompressDirectory method:
        
             String directoryPath = "C:\\path\\to\\your\\directory";
             ArchiveFormat format = ArchiveFormat.Zip;
             ArchiveFactory.compressDirectory(directoryPath, "result", format);
             // This will create a ZIP file with the contents of the directory at the specified path.
         

        This method will create an archive file at the location specified by the path parameter. The name of the archive file will typically be the directory name followed by the appropriate file extension based on the archiveFormat. The directory itself is not modified or deleted.

        Parameters:
        path - the path to the directory that will be compressed
        outputFileName - destination file name
        archiveFormat - the format of the archive to create (e.g., zip, rar, tar, etc.)
        Throws:
        com.aspose.ms.System.IO.DirectoryNotFoundException - Thrown if the directory specified by path does not exist.
        com.aspose.ms.System.ArgumentException - Thrown if path is null or an empty string.
        com.aspose.ms.System.NotSupportedException - Thrown if the specified archiveFormat is not supported or recognized.