Class CpioEntry

    • Method Detail

      • getName

        public final String getName()

        Gets the name of the entry within the archive.

        Specified by:
        getName in interface IArchiveFileEntry
        Returns:
        the name of the entry within the archive
      • getParent

        public final CpioArchive getParent()

        Gets the archive the entry belongs to.

        Returns:
        the archive the entry belongs to
      • getLength

        public final Long getLength()

        Gets the length of the entry in bytes.

        Specified by:
        getLength in interface IArchiveFileEntry
        Returns:
        the length of the entry in bytes
      • isDirectory

        public final boolean isDirectory()

        Gets a value indicating whether the entry represents a directory.

        Returns:
        a value indicating whether the entry represents a directory.
      • getLastWriteTimeUtc

        public final Date getLastWriteTimeUtc()

        Gets the last write time.

        Returns:
        the last write time
      • open

        public final InputStream open()

        Opens the entry for extraction and provides a stream with entry content.

        Usage:
        
             CpioArchive archive = new CpioArchive("archive.cpio");
             CpioEntry entry = archive.getEntries().get(0);
             try (FileOutputStream fileStream = new FileOutputStream("data.bin")) {
                 try (InputStream decompressed = entry.open()) {
                     byte[] buffer = new byte[8192];
                     int bytesRead;
                     while (0 < (bytesRead = decompressed.read(buffer, 0, buffer.length))) {
                         fileStream.write(buffer, 0, bytesRead);
                     }
                 }
             } catch (IOException ex) {
             }
         

        Read from the stream to get the original content of a file. See examples section.

        Returns:
        the stream that represents the contents of the entry
      • extract

        public final File extract​(String path)

        Extracts the entry to the filesystem by the path provided.

        
             try (CpioArchive archive = new CpioArchive("archive.cpio")) {
                 archive.getEntries().get(0).extract("data.bin");
             }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        path - the path to destination file. If the file already exists, it will be overwritten
        Returns:
        the file info of the extracted file
        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.
      • extract

        public final void extract​(OutputStream destination)

        Extracts the entry to the stream provided.

        Extract an entry of cpio archive.

        
             try (CpioArchive archive = new CpioArchive("archive.cpio")) {
                 archive.getEntries().get(0).extract(httpResponseStream);
             }
         
        Specified by:
        extract in interface IArchiveFileEntry
        Parameters:
        destination - destination stream. Must be writable
        Throws:
        com.aspose.ms.System.ArgumentException - destination does not support writing.
      • toString

        public String toString()

        Returns string representation of the instance of the CpioEntry class.

        Overrides:
        toString in class Object
        Returns:
        string representation of this object.