com.groupdocs.parser.data

Class ContainerItem



  • public abstract class ContainerItem
    extends Object
    Represents a container item like Zip archive entity, email attachment, PDF Portfolio item and so on.

    An instance of ContainerItem class is used as return value of Parser.getContainer() method. See the usage examples there.

    • Constructor Detail

      • ContainerItem

        public ContainerItem(String name,
                             String directory,
                             long size,
                             Iterable<MetadataItem> metadata)
        Initializes a new instance of ContainerItem with the item name and directory.
        Parameters:
        name - The name of the item.
        directory - The directory of the item.
        size - The size of the item.
        metadata - The collection of metadata items.
      • ContainerItem

        public ContainerItem(String filePath,
                             long size,
                             Iterable<MetadataItem> metadata)
        Initializes a new instance of ContainerItem with the item full path.
        Parameters:
        filePath - The full path of the item.
        size - The size of the item.
        metadata - The collection of metadata items.
    • Method Detail

      • getName

        public String getName()
        Gets the name of the item.
        Returns:
        A string value that represents the file name of the item (without a directory).
      • getDirectory

        public String getDirectory()
        Gets the directory of the item.
        Returns:
        A string value that represents the directory of the item (without a file name).
      • getFilePath

        public String getFilePath()
        Gets the full path of the item.
        Returns:
        A string value that represents the full path of the item.
      • getSize

        public long getSize()
        Gets the size of the item.
        Returns:
        An integer value that represents the size of the item in bytes.
      • getMetadata

        public Iterable<MetadataItem> getMetadata()
        Gets the collection of metadata items.
        Returns:
        A collection of MetadataItem objects; empty if metadata isn't set.
      • getMetadataValue

        public String getMetadataValue(String name)
        Gets the metadata value.
        Parameters:
        name - The name of the metadata.
        Returns:
        A string value that represents the value of the metadata item; null if the metadata with this name isn't found.
      • openStream

        public abstract InputStream openStream()
        Opens the stream of the item content.
        Returns:
        A stream with the item content.
      • openParser

        public Parser openParser()
        Creates the Parser object for the item content.
        Returns:
        An instance of Parser class of the item content.
      • openParser

        public Parser openParser(LoadOptions loadOptions)
        Creates the Parser object for the item content with LoadOptions.
        Parameters:
        loadOptions - The options to open the item content.
        Returns:
        An instance of Parser class of the item content.
      • openParser

        public abstract Parser openParser(LoadOptions loadOptions,
                                          ParserSettings parserSettings)
        Creates the Parser object for the item content with LoadOptions and ParserSettings.
        Parameters:
        loadOptions - The options to open the item content.
        parserSettings - The parser settings which are used to customize data extraction.
        Returns:
        An instance of Parser class of the item content.
      • detectFileType

        public abstract FileType detectFileType(FileTypeDetectionMode detectionMode)
        Detects a file type of the container item.

        detectionMode parameter provides the ability to control file type detection:

        • Default. The file type is detected by the file extension; if the file extension isn't recognized, the file type is detected by the file content.
        • Extension.The file type is detected only by the file extension.
        • Content. The file type is detected only by the file content.

        The following example shows how to detect file type of container item:

         // Create an instance of Parser class
         try (Parser parser = new Parser(filePath)) {
             // Extract attachments from the container
             Iterable<ContainerItem> attachments = parser.getContainer();
             // Check if container extraction is supported
             if (attachments == null) {
                 System.out.println("Container extraction isn't supported");
             }
             // Iterate over attachments
             for (ContainerItem item : attachments) {
                 // Detect the file type
                 FileType fileType = item.detectFileType(FileTypeDetectionMode.Default);
                 // Print the name and file type
                 System.out.println(String.format("%s: %s", item.getName(), fileType));
             }
         }
         
        Parameters:
        detectionMode - Defines a mode of the file type detection.
        Returns:
        An instance of FileType class; FileType.Unknown if a file type isn't detected.