ArchiveFactory
Inheritance: java.lang.Object
public final class ArchiveFactory
Detekterar arkivformatet och skapar det lämpliga IArchive objektet enligt arkivtypen.
Metoder
| Metod | Beskrivning |
|---|---|
| compressDirectory(String path, String outputFileName, ArchiveFormat archiveFormat) | Komprimerar den angivna katalogen till en arkivfil med hjälp av det angivna arkivformatet. |
| getArchive(InputStream stream) | Detekterar arkivformatet och skapar det lämpliga IArchive objektet enligt den arkivtyp som anges av den givna strömmen. |
| getArchive(InputStream stream, String password) | Detekterar arkivformatet och skapar det lämpliga IArchive objektet enligt den krypterade arkivtypen som anges av den givna strömmen. |
| getArchive(String path) | Detekterar arkivformatet och skapar det lämpliga IArchive objektet enligt den arkivtyp som anges av den givna sökvägen. |
compressDirectory(String path, String outputFileName, ArchiveFormat archiveFormat)
public static void compressDirectory(String path, String outputFileName, ArchiveFormat archiveFormat)
Komprimerar den angivna katalogen till en arkivfil med hjälp av det angivna arkivformatet.
Här är ett exempel på hur man använder metoden CompressDirectory:
String directoryPath = “C:\path\to\your\directory”; ArchiveFormat format = ArchiveFormat.Zip; ArchiveFactory.compressDirectory(directoryPath, “result”, format); // Detta kommer att skapa en ZIP-fil med innehållet i katalogen på den angivna sökvägen.
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:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the directory that will be compressed |
| outputFileName | java.lang.String | destination file name |
| archiveFormat | [ArchiveFormat](../../com.aspose.zip/archiveformat) | the format of the archive to create (e.g., zip, rar, tar, etc.) |
### getArchive(InputStream stream) {#getArchive-java.io.InputStream-}
public static IArchive getArchive(InputStream stream)
Detects the archive format and creates the appropriate [IArchive](../../com.aspose.zip/iarchive) object according to the type of archive specified by the given stream.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | java.io.InputStream | the stream containing the archive data |
**Returns:**
[IArchive](../../com.aspose.zip/iarchive) - an [IArchive](../../com.aspose.zip/iarchive) object representing the archive
### getArchive(InputStream stream, String password) {#getArchive-java.io.InputStream-java.lang.String-}
public static IArchive getArchive(InputStream stream, String password)
Detects the archive format and creates the appropriate [IArchive](../../com.aspose.zip/iarchive) object according to the type of encrypted archive specified by the given stream.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| stream | java.io.InputStream | the stream containing the archive data |
| password | java.lang.String | password to decrypt an encrypted archive |
**Returns:**
[IArchive](../../com.aspose.zip/iarchive) - an [IArchive](../../com.aspose.zip/iarchive) object representing the archive
### getArchive(String path) {#getArchive-java.lang.String-}
public static IArchive getArchive(String path)
Detects the archive format and creates the appropriate [IArchive](../../com.aspose.zip/iarchive) object according to the type of archive specified by the given path.
**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the archive to be analyzed |
**Returns:**
[IArchive](../../com.aspose.zip/iarchive) - an [IArchive](../../com.aspose.zip/iarchive) object representing the archive