ArchiveFactory

Inheritance: java.lang.Object

public final class ArchiveFactory

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

Methods

MethodDescription
compressDirectory(String path, String outputFileName, ArchiveFormat archiveFormat)Compresses the specified directory into an archive file using the provided archive format.
getArchive(InputStream stream)Detects the archive format and creates the appropriate IArchive object according to the type of archive specified by the given stream.
getArchive(String path)Detects the archive format and creates the appropriate IArchive object according to the type of archive specified by the given path.

compressDirectory(String path, String outputFileName, ArchiveFormat archiveFormat)

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:

ParameterTypeDescription
pathjava.lang.Stringthe path to the directory that will be compressed
outputFileNamejava.lang.Stringdestination file name
archiveFormatArchiveFormatthe format of the archive to create (e.g., zip, rar, tar, etc.)

getArchive(InputStream stream)

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:

ParameterTypeDescription
streamjava.io.InputStreamthe stream containing the archive data

Returns: IArchive - an IArchive object representing the archive

getArchive(String path)

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:

ParameterTypeDescription
pathjava.lang.Stringthe path to the archive to be analyzed

Returns: IArchive - an IArchive object representing the archive