Class SnappyArchive

    • Constructor Detail

      • SnappyArchive

        public SnappyArchive()

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

        The following example shows how to compress a file.

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

        public SnappyArchive​(InputStream source)

        Initializes a new instance of the SnappyArchive class prepared for decompressing.

        This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

        Parameters:
        source - The source of the archive.
        Throws:
        com.aspose.ms.System.ArgumentNullException - source is null.
      • SnappyArchive

        public SnappyArchive​(String path)

        Initializes a new instance of the 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) {
              }
         

        This constructor does not decompress. See extract(java.io.OutputStream) method for decompressing.

        Parameters:
        path - the path to the source of the archive
        Throws:
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
    • Method Detail

      • getName

        public final String getName()

        The name of original file.

        Specified by:
        getName in interface IArchiveFileEntry
        Returns:
        the name of the original file
      • getFormat

        public final ArchiveFormat getFormat()

        Gets the archive format.

        Specified by:
        getFormat in interface IArchive
        Returns:
        the archive format
      • extract

        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) {
             }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        destination - the stream for storing decompressed data
        Throws:
        com.aspose.ms.System.InvalidOperationException - Archive headers and service information were not read.
        com.aspose.ms.System.IO.InvalidDataException - Error in data in header or checksum.
        com.aspose.ms.System.ArgumentNullException - Destination stream is null.
        com.aspose.ms.System.ArgumentException - Destination stream does not support writing.
      • extract

        public final void extract​(File file)

        Extracts snappy archive to a file.

        
             try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) {
                 try (SnappyArchive archive = new SnappyArchive(snappyFile)) {
                     archive.extract(new File("extracted.bin"));
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        file - the file for storing decompressed data
        Throws:
        com.aspose.ms.System.InvalidOperationException - Archive headers and service information were not read.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to open the file.
        com.aspose.ms.System.ArgumentException - The file path is empty or contains only white spaces.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.ArgumentNullException - file is null.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • extract

        public final File extract​(String path)

        Extracts snappy archive to a file by path.

        
             try (FileInputStream snappyFile = new FileInputStream("sourceFileName")) {
                 try (SnappyArchive archive = new SnappyArchive(snappyFile)) {
                     archive.extract("extracted.bin");
                 }
             } catch (IOException ex) {
             }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        path - the path to the file which will store decompressed data
        Returns:
        File instance containing extracted data
        Throws:
        com.aspose.ms.System.InvalidOperationException - Archive headers and service information were not read.
        com.aspose.ms.System.ArgumentNullException - path is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The path is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at path contains a colon (:) in the middle of the string.
      • extractToDirectory

        public final void extractToDirectory​(String destinationDirectory)

        Extracts content of the archive to the directory provided.

        Specified by:
        extractToDirectory in interface IArchive
        Parameters:
        destinationDirectory - the path to the directory to place the extracted files in.

        If the directory does not exist, it will be created

        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationDirectory is null.
        com.aspose.ms.System.IO.PathTooLongException - The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access the existing directory.
        com.aspose.ms.System.NotSupportedException - If the directory does not exist, the path contains a colon character (:) that is not part of a drive label ("C:\").
        com.aspose.ms.System.ArgumentException - destinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters. -or- path is prefixed with, or contains, only a colon character (:).
        com.aspose.ms.System.IO.IOException - The directory specified by path is a file. -or- The network name is not known.
      • setSource

        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:
        source - the input stream for the archive
        Throws:
        com.aspose.ms.System.ArgumentException - The source stream is unseekable.
      • setSource

        public final void setSource​(File file)

        Sets the content to be compressed within the archive.

        
             try (SnappyArchive archive = new SnappyArchive()) {
                 archive.setSource(new File("data.bin"));
                 archive.save("archive.snappy");
             }
         
        Parameters:
        file - the file which will be opened as an input stream
        Throws:
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to open the file.
        com.aspose.ms.System.ArgumentException - The file path is empty or contains only white spaces.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.ArgumentNullException - file is null.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • setSource

        public final void setSource​(String sourcePath)

        Sets the content to be compressed within the archive.

        
             try (SnappyArchive archive = new SnappyArchive()) {
                 archive.setSource("data.bin");
                 archive.save("archive.snappy");
             }
         
        Parameters:
        sourcePath - the path to the file which will be opened as an input stream
        Throws:
        com.aspose.ms.System.ArgumentNullException - sourcePath is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The sourcePath is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified sourcePath, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at sourcePath contains a colon (:) in the middle of the string.
      • save

        public final void save​(OutputStream output)

        Saves snappy archive to the stream provided.

        
             try (FileOutputStream snappyFile = new FileOutputStream("archive.snappy")) {
                 try (SnappyArchive archive = new SnappyArchive()) {
                     archive.setSource("data.bin");
                     archive.save(snappyFile);
                 }
             } catch (IOException ex) {
             }
         
        Parameters:
        output - the destination stream
        Throws:
        com.aspose.ms.System.ArgumentNullException - output is null.
      • save

        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:
        destination - the file, which will be opened as a destination stream
        Throws:
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to open the destination.
        com.aspose.ms.System.ArgumentException - The file path is empty or contains only white spaces.
        com.aspose.ms.System.IO.FileNotFoundException - The file is not found.
        com.aspose.ms.System.ArgumentNullException - destination is null.
        com.aspose.ms.System.IO.DirectoryNotFoundException - The specified path is invalid, such as being on an unmapped drive.
        com.aspose.ms.System.IO.IOException - The file is already open.
      • save

        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:
        destinationFileName - the path of the archive to be created. If the specified file name points to an existing file, it will be overwritten
        Throws:
        com.aspose.ms.System.ArgumentNullException - destinationFileName is null.
        com.aspose.ms.System.SecurityException - The caller does not have the required permission to access.
        com.aspose.ms.System.ArgumentException - The destinationFileName is empty, contains only white spaces, or contains invalid characters.
        com.aspose.ms.System.IO.PathTooLongException - The specified destinationFileName, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.
        com.aspose.ms.System.NotSupportedException - File at destinationFileName contains a colon (:) in the middle of the string.