ContainerItem

Inheritance: java.lang.Object

public abstract class ContainerItem

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.

Constructors

Constructor Description
ContainerItem(String name, String directory, long size, Iterable metadata) Initializes a new instance of ContainerItem with the item name and directory.
ContainerItem(String filePath, long size, Iterable metadata) Initializes a new instance of ContainerItem with the item full path.

Methods

Method Description
getName() Gets the name of the item.
getDirectory() Gets the directory of the item.
getFilePath() Gets the full path of the item.
getSize() Gets the size of the item.
getMetadata() Gets the collection of metadata items.
getMetadataValue(String name) Gets the metadata value.
openStream() Opens the stream of the item content.
openParser() Creates the Parser object for the item content.
openParser(LoadOptions loadOptions) Creates the Parser object for the item content with LoadOptions.
openParser(LoadOptions loadOptions, ParserSettings parserSettings) Creates the Parser object for the item content with LoadOptions and ParserSettings.
detectFileType(FileTypeDetectionMode detectionMode) Detects a file type of the container item.

ContainerItem(String name, String directory, long size, Iterable metadata)

public ContainerItem(String name, String directory, long size, Iterable<MetadataItem> metadata)

Initializes a new instance of ContainerItem with the item name and directory.

Parameters:

Parameter Type Description
name java.lang.String The name of the item.
directory java.lang.String The directory of the item.
size long The size of the item.
metadata java.lang.Iterable<com.groupdocs.parser.data.MetadataItem> The collection of metadata items.

ContainerItem(String filePath, long size, Iterable metadata)

public ContainerItem(String filePath, long size, Iterable<MetadataItem> metadata)

Initializes a new instance of ContainerItem with the item full path.

Parameters:

Parameter Type Description
filePath java.lang.String The full path of the item.
size long The size of the item.
metadata java.lang.Iterable<com.groupdocs.parser.data.MetadataItem> The collection of metadata items.

getName()

public String getName()

Gets the name of the item.

Returns: java.lang.String - 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: java.lang.String - 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: java.lang.String - A string value that represents the full path of the item.

getSize()

public long getSize()

Gets the size of the item.

Returns: long - An integer value that represents the size of the item in bytes.

getMetadata()

public Iterable<MetadataItem> getMetadata()

Gets the collection of metadata items.

Returns: java.lang.Iterable<com.groupdocs.parser.data.MetadataItem> - A collection of MetadataItem objects; empty if metadata isn’t set.

getMetadataValue(String name)

public String getMetadataValue(String name)

Gets the metadata value.

Parameters:

Parameter Type Description
name java.lang.String The name of the metadata.

Returns: java.lang.String - 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: java.io.InputStream - A stream with the item content.

openParser()

public Parser openParser()

Creates the Parser object for the item content.

Returns: Parser - An instance of Parser class of the item content.

openParser(LoadOptions loadOptions)

public Parser openParser(LoadOptions loadOptions)

Creates the Parser object for the item content with LoadOptions.

Parameters:

Parameter Type Description
loadOptions LoadOptions The options to open the item content.

Returns: Parser - An instance of Parser class of the item content.

openParser(LoadOptions loadOptions, ParserSettings parserSettings)

public abstract Parser openParser(LoadOptions loadOptions, ParserSettings parserSettings)

Creates the Parser object for the item content with LoadOptions and ParserSettings.

Parameters:

Parameter Type Description
loadOptions LoadOptions The options to open the item content.
parserSettings ParserSettings The parser settings which are used to customize data extraction.

Returns: Parser - An instance of Parser class of the item content.

detectFileType(FileTypeDetectionMode detectionMode)

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

Parameter Type Description
detectionMode FileTypeDetectionMode Defines a mode of the file type detection.

Returns: FileType - An instance of FileType class; FileType.Unknown if a file type isn’t detected.