SnappyArchive

Inheritance: java.lang.Object

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

public class SnappyArchive implements IArchive, IArchiveFileEntry, AutoCloseable

Denna klass representerar en snappy-arkivfil. Använd den för att skapa eller extrahera snappy-arkiv.

Konstruktörer

KonstruktorBeskrivning
SnappyArchive()Initierar en ny instans av klassen SnappyArchive för komprimering.
SnappyArchive(InputStream source)Initierar en ny instans av klassen SnappyArchive för dekomprimering.
SnappyArchive(String path)Initierar en ny instans av klassen SnappyArchive för dekomprimering.

Metoder

MetodBeskrivning
close(){@inheritDoc}
extract(File file)Extraherar snappy-arkivet till en fil.
extract(OutputStream destination)Extraherar snappy-arkivet till en ström.
extract(String path)Extraherar snappy-arkivet till en fil via sökväg.
extractToDirectory(String destinationDirectory)Extraherar arkivets innehåll till den angivna katalogen.
getFileEntries()Hämtar poster av typen IArchiveFileEntry som utgör snappy-arkivet.
getFormat()Hämtar arkivformatet.
getLength()Hämtar längd.
getName()Namnet på den ursprungliga filen.
save(File destination)Sparar snappy-arkivet till den angivna destinationsfilen.
save(OutputStream output)Sparar snappy-arkivet till den angivna strömmen.
save(String destinationFileName)Sparar snappy-arkivet till den angivna destinationsfilen.
setSource(File file)Ställer in innehållet som ska komprimeras i arkivet.
setSource(InputStream source)Ställer in innehållet som ska komprimeras i arkivet.
setSource(String sourcePath)Ställer in innehållet som ska komprimeras i arkivet.

SnappyArchive()

public SnappyArchive()

Initierar en ny instans av klassen SnappyArchive för komprimering.

Följande exempel visar hur man komprimerar en fil.

try (SnappyArchive archive = new SnappyArchive()) { archive.setSource(“data.bin”); archive.save("archive.snappy"); }




### SnappyArchive(InputStream source) {#SnappyArchive-java.io.InputStream-}

public SnappyArchive(InputStream source)



Initializes a new instance of the [SnappyArchive](../../com.aspose.zip/snappyarchive) class prepared for decompressing.

This constructor does not decompress. See [extract(java.io.OutputStream)](../../com.aspose.zip/snappyarchive\#extract-java.io.OutputStream-) method for decompressing.

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

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

public SnappyArchive(String path)



Initializes a new instance of the [SnappyArchive](../../com.aspose.zip/snappyarchive) class prepared for decompressing.

      try (FileInputStream sourceSnappyFile = new FileInputStream("sourceFileName")) {
          try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) {
              try (SnappyArchive archive = new SnappyArchive(sourceSnappyFile)) {
                  archive.extract(extractedFile);
              }
          }
      } catch (IOException ex) {
      }
 
```

Denna konstruktor dekomprimerar inte. Se [extract(java.io.OutputStream)](../../com.aspose.zip/snappyarchive\\#extract-java.io.OutputStream-) metoden för att dekomprimera.

**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| path | java.lang.String | sökvägen till källan för arkivet |

### close() {#close--}
```
public void close()
```




### extract(File file) {#extract-java.io.File-}
```
public final void extract(File file)
```


Extraherar snappy-arkivet till en fil.

```

try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) { try (SnappyArchive archive = new SnappyArchive(snappyFile)) { archive.extract(new File("extracted.bin")); } } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| file | java.io.File | the file for storing decompressed data |

### extract(OutputStream destination) {#extract-java.io.OutputStream-}

public final void extract(OutputStream destination)



Extracts snappy archive to a stream.

     try (FileInputStream sourceSnappyFile = new FileInputStream("sourceFileName")) {
         try (FileOutputStream extractedFile = new FileOutputStream("extractedFileName")) {
             try (SnappyArchive archive = new SnappyArchive(sourceSnappyFile)) {
                 archive.extract(extractedFile);
             }
         }
     } catch (IOException ex) {
     }
 
```



**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| mål | java.io.OutputStream | strömmen för att lagra dekomprimerade data |

### extract(String path) {#extract-java.lang.String-}
```
public final File extract(String path)
```


Extraherar snappy-arkivet till en fil via sökväg.

```

try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) { try (SnappyArchive archive = new SnappyArchive(snappyFile)) { archive.extract("extracted.bin"); } } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| path | java.lang.String | the path to the file which will store decompressed data |

**Returns:**
java.io.File - java.io.File instance containing extracted data
### extractToDirectory(String destinationDirectory) {#extractToDirectory-java.lang.String-}

public final void extractToDirectory(String destinationDirectory)



Extracts content of the archive to the directory provided.

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

### getFileEntries() {#getFileEntries--}

public final Iterable getFileEntries()



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

**Returns:**
java.lang.Iterable<com.aspose.zip.IArchiveFileEntry> - entries of [IArchiveFileEntry](../../com.aspose.zip/iarchivefileentry) type constituting the snappy archive
### getFormat() {#getFormat--}

public final ArchiveFormat getFormat()



Gets the archive format.

**Returns:**
[ArchiveFormat](../../com.aspose.zip/archiveformat) - the archive format
### getLength() {#getLength--}

public final Long getLength()



Gets length.

**Returns:**
java.lang.Long - length.
### getName() {#getName--}

public final String getName()



The name of original file.

**Returns:**
java.lang.String - the name of the original file
### save(File destination) {#save-java.io.File-}

public final void save(File destination)



Saves snappy archive to the destination file provided.

     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save(new File("archive.snappy"));
     }
 
```



**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| mål | java.io.File | filen, som kommer att öppnas som en destinationsström |

### save(OutputStream output) {#save-java.io.OutputStream-}
```
public final void save(OutputStream output)
```


Sparar snappy-arkivet till den angivna strömmen.

```

try (FileOutputStream snappyFile = new FileOutputStream("archive.snappy")) { try (SnappyArchive archive = new SnappyArchive()) { archive.setSource(“data.bin”); archive.save(snappyFile); } } catch (IOException ex) { }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| output | java.io.OutputStream | the destination stream |

### save(String destinationFileName) {#save-java.lang.String-}

public final void save(String destinationFileName)



Saves snappy archive to the destination file provided.

     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new File("data.bin"));
         archive.save("result.snappy");
     }
 
```



**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| destinationFileName | java.lang.String | sökvägen till arkivet som ska skapas. Om det angivna filnamnet pekar på en befintlig fil kommer den att skrivas över |

### setSource(File file) {#setSource-java.io.File-}
```
public final void setSource(File file)
```


Ställer in innehållet som ska komprimeras i arkivet.

```

try (SnappyArchive archive = new SnappyArchive()) { archive.setSource(new File("data.bin")); archive.save("archive.snappy"); }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| file | java.io.File | the file which will be opened as an input stream |

### setSource(InputStream source) {#setSource-java.io.InputStream-}

public final void setSource(InputStream source)



Sets the content to be compressed within the archive.

     try (SnappyArchive archive = new SnappyArchive()) {
         archive.setSource(new ByteArrayInputStream(new byte[] {
                 0x00,
                 (byte) 0xFF
         }));
         archive.save("archive.snappy");
     }
 
```



**Parameters:**
| Parameter | Typ | Beskrivning |
| --- | --- | --- |
| source | java.io.InputStream | indataströmmen för arkivet |

### setSource(String sourcePath) {#setSource-java.lang.String-}
```
public final void setSource(String sourcePath)
```


Ställer in innehållet som ska komprimeras i arkivet.

```

try (SnappyArchive archive = new SnappyArchive()) { archive.setSource(“data.bin”); archive.save("archive.snappy"); }




**Parameters:**
| Parameter | Type | Description |
| --- | --- | --- |
| sourcePath | java.lang.String | the path to the file which will be opened as an input stream |