CabArchive

Inheritance: java.lang.Object

All Implemented Interfaces: com.aspose.zip.ICompressionArchive, java.lang.AutoCloseable

public class CabArchive implements ICompressionArchive, AutoCloseable

This class represents a CAB archive file.

Constructors

ConstructorDescription
CabArchive(CabEntrySettings settings)Initializes a new instance of the CabArchive class prepared for compressing.
CabArchive(InputStream sourceStream)Initializes a new instance of the CabArchive class and composes an entry list can be extracted from the archive.
CabArchive(InputStream sourceStream, CabLoadOptions loadOptions)Initializes a new instance of the CabArchive class and composes an entry list can be extracted from the archive.
CabArchive(String path)Initializes a new instance of the CabArchive class and composes an entry list can be extracted from the archive.
CabArchive(String path, CabLoadOptions loadOptions)Initializes a new instance of the CabArchive class and composes an entry list can be extracted from the archive.

Methods

MethodDescription
close(){@inheritDoc}
createEntries(File directory)Adds to the archive all files, recursively, from the specified directory.
createEntries(File directory, boolean includeRootDirectory)Adds to the archive all files, recursively, from the specified directory.
createEntries(String sourceDirectory)Adds to the archive all files recursively from the specified directory path.
createEntries(String sourceDirectory, boolean includeRootDirectory)Adds to the archive all files recursively from the specified directory path.
createEntry(String name, File fileInfo)Create a single entry within the archive.
createEntry(String name, File fileInfo, CabEntrySettings newEntrySettings)Create a single entry within the archive.
createEntry(String name, InputStream source)Create a single entry within the archive.
createEntry(String name, InputStream source, CabEntrySettings newEntrySettings)Create a single entry within the archive and specific settings.
createEntry(String name, String path)Create a single entry within the archive.
createEntry(String name, String path, CabEntrySettings newEntrySettings)Create a single entry within the archive.
createEntry(String name, Supplier<InputStream> streamProvider)Create a single entry within the archive.
createEntry(String name, Supplier<InputStream> streamProvider, CabEntrySettings newEntrySettings)Create a single entry within the archive.
extractToDirectory(String destinationDirectory)Extracts all the files in the archive to the directory provided.
getEntries()Gets entries of CabEntry type constituting the archive.
getFileEntries()Gets entries of IArchiveFileEntry type constituting the cab archive.
getFormat()Gets the archive format.
save(OutputStream outputStream)Saves archive to the stream provided.
save(OutputStream outputStream, CabSaveOptions saveOptions)Saves archive to the stream provided with specific options.
save(String destinationFileName)Saves archive to the destination file provided.
save(String destinationFileName, CabSaveOptions saveOptions)Saves archive to the destination file provided.

CabArchive(CabEntrySettings settings)

public CabArchive(CabEntrySettings settings)

Initializes a new instance of the CabArchive class prepared for compressing.

Compress a file using specific compression settings.

CabEntrySettings settings = new CabEntrySettings(new CabStoreCompressionSettings())); try (CabArchive archive = new CabArchive(settings)) { archive.createEntry(“entry.bin”, “data.bin”); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| settings | [CabEntrySettings](../../com.aspose.zip/cabentrysettings) | the source of the archive |

### CabArchive(InputStream sourceStream) {#CabArchive-java.io.InputStream-}

public CabArchive(InputStream sourceStream)



Initializes a new instance of the [CabArchive](../../com.aspose.zip/cabarchive) 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 (CabArchive archive = new CabArchive(new FileInputStream("archive.cab"))) {
         archive.extractToDirectory("C:\\extracted");
     } catch (IOException ex) {
     }
 
```

This constructor does not unpack any entry. See [CabEntry.open()](../../com.aspose.zip/cabentry\#open--) method for unpacking.

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | the source of the archive |

### CabArchive(InputStream sourceStream, CabLoadOptions loadOptions) {#CabArchive-java.io.InputStream-com.aspose.zip.CabLoadOptions-}
```
public CabArchive(InputStream sourceStream, CabLoadOptions loadOptions)
```


Initializes a new instance of the [CabArchive](../../com.aspose.zip/cabarchive) 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 (CabArchive archive = new CabArchive(new FileInputStream("archive.cab"))) {
     archive.extractToDirectory("C:\\extracted");
 } catch (IOException ex) {
 }

This constructor does not unpack any entry. See [CabEntry.open()](../../com.aspose.zip/cabentry\#open--) method for unpacking.

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceStream | java.io.InputStream | the source of the archive |
| loadOptions | [CabLoadOptions](../../com.aspose.zip/cabloadoptions) | Options to load existing archive with. |

### CabArchive(String path) {#CabArchive-java.lang.String-}

public CabArchive(String path)



Initializes a new instance of the [CabArchive](../../com.aspose.zip/cabarchive) 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 (CabArchive archive = new CabArchive("archive.cab")) {
         archive.extractToDirectory("C:\\extracted");
     } catch (IOException ex) {
     }
 
```

This constructor does not unpack any entry. See [CabEntry.open()](../../com.aspose.zip/cabentry\#open--) method for unpacking.

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the archive file |

### CabArchive(String path, CabLoadOptions loadOptions) {#CabArchive-java.lang.String-com.aspose.zip.CabLoadOptions-}
```
public CabArchive(String path, CabLoadOptions loadOptions)
```


Initializes a new instance of the [CabArchive](../../com.aspose.zip/cabarchive) 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 (CabArchive archive = new CabArchive("archive.cab")) {
     archive.extractToDirectory("C:\\extracted");
 } catch (IOException ex) {
 }

This constructor does not unpack any entry. See [CabEntry.open()](../../com.aspose.zip/cabentry\#open--) method for unpacking.

**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the archive file |
| loadOptions | [CabLoadOptions](../../com.aspose.zip/cabloadoptions) | Options to load existing archive with. |

### close() {#close--}

public void close()





### createEntries(File directory) {#createEntries-java.io.File-}

public final CabArchive createEntries(File directory)



Adds to the archive all files, recursively, from the specified directory.

 try (var archive = new CabArchive())
 {
     File directory = new File("C:/Logs");
     archive.createEntries(directory);
     archive.save("logs.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | Directory to compress. |

**Returns:**
[CabArchive](../../com.aspose.zip/cabarchive) - The current [CabArchive](../../com.aspose.zip/cabarchive) instance.
### createEntries(File directory, boolean includeRootDirectory) {#createEntries-java.io.File-boolean-}
```
public final CabArchive createEntries(File directory, boolean includeRootDirectory)
```


Adds to the archive all files, recursively, from the specified directory.

```

try (var archive = new CabArchive()) { File directory = new File(“C:/Logs”); archive.createEntries(directory, false); archive.save(“logs.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| directory | java.io.File | Directory to compress. |
| includeRootDirectory | boolean | Indicates whether to include the root directory name in entry paths. |

**Returns:**
[CabArchive](../../com.aspose.zip/cabarchive) - The current [CabArchive](../../com.aspose.zip/cabarchive) instance.
### createEntries(String sourceDirectory) {#createEntries-java.lang.String-}

public final CabArchive createEntries(String sourceDirectory)



Adds to the archive all files recursively from the specified directory path.

 try (var archive = new CabArchive())
 {
     archive.createEntries("C:/Logs");
     archive.save("logs.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | Directory path to compress. |

**Returns:**
[CabArchive](../../com.aspose.zip/cabarchive) - The current [CabArchive](../../com.aspose.zip/cabarchive) instance.
### createEntries(String sourceDirectory, boolean includeRootDirectory) {#createEntries-java.lang.String-boolean-}
```
public final CabArchive createEntries(String sourceDirectory, boolean includeRootDirectory)
```


Adds to the archive all files recursively from the specified directory path.

```

try (var archive = new CabArchive()) { archive.createEntries(“C:/Logs”, false); archive.save(“logs.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourceDirectory | java.lang.String | Directory path to compress. |
| includeRootDirectory | boolean | Indicates whether to include the root directory name in entry paths. |

**Returns:**
[CabArchive](../../com.aspose.zip/cabarchive) - The current [CabArchive](../../com.aspose.zip/cabarchive) instance.
### createEntry(String name, File fileInfo) {#createEntry-java.lang.String-java.io.File-}

public final CabEntry createEntry(String name, File fileInfo)



Create a single entry within the archive.

 try (CabArchive archive = new CabArchive())
 {
     var sourceFile = new java.io.File("logs\\log.txt");
     archive.createEntry("log.txt", sourceFile);
     archive.save("archive.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| fileInfo | java.io.File | The metadata of file to be compressed.

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

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - CAB entry instance.
### createEntry(String name, File fileInfo, CabEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.io.File-com.aspose.zip.CabEntrySettings-}
```
public final CabEntry createEntry(String name, File fileInfo, CabEntrySettings newEntrySettings)
```


Create a single entry within the archive.

```

try (CabArchive archive = new CabArchive()) { CabEntrySettings settings = new CabEntrySettings(); File sourceFile = new File(“logs\log.txt”); archive.createEntry(“log.txt”, sourceFile, settings); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| fileInfo | java.io.File | The metadata of file to be compressed. |
| newEntrySettings | [CabEntrySettings](../../com.aspose.zip/cabentrysettings) | Compression and encryption settings used for added [CabEntry](../../com.aspose.zip/cabentry) item.

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

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - CAB entry instance.
### createEntry(String name, InputStream source) {#createEntry-java.lang.String-java.io.InputStream-}

public final CabEntry createEntry(String name, InputStream source)



Create a single entry within the archive.

 try (CabArchive archive = new CabArchive(); FileInputStream stream = new FileInputStream("stream-entry.bin"))
 {
     archive.createEntry("stream-entry.bin", stream);
     archive.save("archive.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| source | java.io.InputStream | The input stream for the entry. |

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - Cab entry instance.
### createEntry(String name, InputStream source, CabEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.io.InputStream-com.aspose.zip.CabEntrySettings-}
```
public final CabEntry createEntry(String name, InputStream source, CabEntrySettings newEntrySettings)
```


Create a single entry within the archive and specific settings.

```

try (CabArchive archive = new CabArchive(); FileInputStream stream = new FileInputStream(“stream-entry.bin”)) {
CabEntrySettings settings = new CabEntrySettings(new CabStoreCompressionSettings()); archive.createEntry(“stream-entry.bin”, stream, settings); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| source | java.io.InputStream | The input stream for the entry. |
| newEntrySettings | [CabEntrySettings](../../com.aspose.zip/cabentrysettings) | Compression and encryption settings used for added [CabEntry](../../com.aspose.zip/cabentry) item. |

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - Cab entry instance.
### createEntry(String name, String path) {#createEntry-java.lang.String-java.lang.String-}

public final CabEntry createEntry(String name, String path)



Create a single entry within the archive.

 try (CabArchive archive = new CabArchive())
 {
     archive.createEntry("entry.bin", "data.bin");
     archive.save("archive.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| path | java.lang.String | The fully qualified name of the new file, or the relative file name to be compressed.

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

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - Cab entry instance.
### createEntry(String name, String path, CabEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.lang.String-com.aspose.zip.CabEntrySettings-}
```
public final CabEntry createEntry(String name, String path, CabEntrySettings newEntrySettings)
```


Create a single entry within the archive.

```

try (CabArchive archive = new CabArchive()) { CabEntrySettings settings = new CabEntrySettings(); archive.createEntry(“entry.bin”, “data.bin”, settings); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| path | java.lang.String | The fully qualified name of the new file, or the relative file name to be compressed. |
| newEntrySettings | [CabEntrySettings](../../com.aspose.zip/cabentrysettings) | Compression and encryption settings used for added [CabEntry](../../com.aspose.zip/cabentry) item.

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

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - Cab entry instance.
### createEntry(String name, Supplier&lt;InputStream&gt; streamProvider) {#createEntry-java.lang.String-java.util.function.Supplier-java.io.InputStream--}

public final CabEntry createEntry(String name, Supplier streamProvider)



Create a single entry within the archive.

 try (CabArchive archive = new CabArchive())
 {
     archive.createEntry("log.txt", () -> new FileInputStream("log.txt"));
     archive.save("archive.cab");
 } catch (IOException ex) {
 }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| streamProvider | java.util.function.Supplier&lt;java.io.InputStream&gt; | The method providing input stream for the entry. |

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - CAB entry instance.
### createEntry(String name, Supplier&lt;InputStream&gt; streamProvider, CabEntrySettings newEntrySettings) {#createEntry-java.lang.String-java.util.function.Supplier-java.io.InputStream--com.aspose.zip.CabEntrySettings-}
```
public final CabEntry createEntry(String name, Supplier<InputStream> streamProvider, CabEntrySettings newEntrySettings)
```


Create a single entry within the archive.

```

try (CabArchive archive = new CabArchive()) { CabEntrySettings settings = new CabEntrySettings(); archive.createEntry(“log.txt”, () -> new FileInputStream(“log.txt”), settings); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| name | java.lang.String | The name of the entry. |
| streamProvider | java.util.function.Supplier&lt;java.io.InputStream&gt; | The method providing input stream for the entry. |
| newEntrySettings | [CabEntrySettings](../../com.aspose.zip/cabentrysettings) | Compression and encryption settings used for added [CabEntry](../../com.aspose.zip/cabentry) item. |

**Returns:**
[CabEntry](../../com.aspose.zip/cabentry) - CAB entry instance.
### extractToDirectory(String destinationDirectory) {#extractToDirectory-java.lang.String-}

public final void extractToDirectory(String destinationDirectory)



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

     try (CabArchive archive = new CabArchive("archive.cab")) {
         archive.extractToDirectory("C:\\extracted");
     } catch (IOException ex) {
     }
 
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationDirectory | java.lang.String | the path to the directory to place the extracted files in.

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

### getEntries() {#getEntries--}
```
public final List<CabEntry> getEntries()
```


Gets entries of [CabEntry](../../com.aspose.zip/cabentry) type constituting the archive.

**Returns:**
java.util.List&lt;com.aspose.zip.CabEntry&gt; - entries of [CabEntry](../../com.aspose.zip/cabentry) type constituting the archive
### getFileEntries() {#getFileEntries--}
```
public final Iterable<IArchiveFileEntry> getFileEntries()
```


Gets entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the cab archive.

**Returns:**
java.lang.Iterable&lt;com.aspose.zip.IArchiveFileEntry&gt; - entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the cab archive
### getFormat() {#getFormat--}
```
public final ArchiveFormat getFormat()
```


Gets the archive format.

**Returns:**
[ArchiveFormat](../../com.aspose.zip/archiveformat) - the archive format
### save(OutputStream outputStream) {#save-java.io.OutputStream-}
```
public final void save(OutputStream outputStream)
```


Saves archive to the stream provided.

```

try (CabArchive archive = new CabArchive(); FileOutputStream cabFile = new FileOutputStream(“archive.cab”)) { archive.createEntry(“entry.bin”, “data.bin”); archive.save(cabFile); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| outputStream | java.io.OutputStream | Destination stream.

`outputStream` must be writable. |

### save(OutputStream outputStream, CabSaveOptions saveOptions) {#save-java.io.OutputStream-com.aspose.zip.CabSaveOptions-}

public final void save(OutputStream outputStream, CabSaveOptions saveOptions)



Saves archive to the stream provided with specific options.

  try (CabArchive archive = new CabArchive(); FileOutputStream cabFile = new FileOutputStream("archive.cab"))
  {
      CabSaveOptions options = new CabSaveOptions();
      options.setSkipChecksumCalculation(true);
      archive.createEntry("entry.bin", "data.bin");
      archive.save(cabFile, options);
  } catch (IOException ex) {
  }
  
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| outputStream | java.io.OutputStream | Destination stream. |
| saveOptions | [CabSaveOptions](../../com.aspose.zip/cabsaveoptions) | Options for archive saving.

`outputStream` must be writable. |

### save(String destinationFileName) {#save-java.lang.String-}
```
public final void save(String destinationFileName)
```


Saves archive to the destination file provided.

```

try (CabArchive archive = new CabArchive()) { archive.createEntry(“entry.bin”, “data.bin”); archive.save(“archive.cab”); } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationFileName | java.lang.String | 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. |

### save(String destinationFileName, CabSaveOptions saveOptions) {#save-java.lang.String-com.aspose.zip.CabSaveOptions-}

public final void save(String destinationFileName, CabSaveOptions saveOptions)



Saves archive to the destination file provided.

  try (CabArchive archive = new CabArchive())
  {
      CabSaveOptions options = new CabSaveOptions();
      options.setSkipChecksumCalculation(true);
      archive.createEntry("entry.bin", "data.bin");
      archive.save("archive.cab", options);
  } catch (IOException ex) {
  }
  
```



**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| destinationFileName | java.lang.String | The path of the archive to be created. If the specified file name points to an existing file, it will be overwritten. |
| saveOptions | [CabSaveOptions](../../com.aspose.zip/cabsaveoptions) | Options for archive saving.

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