public abstract class ContainerItem extends Object
An instance of ContainerItem
class is used as return value of Parser.getContainer()
method. See the usage examples there.
Constructor and Description |
---|
ContainerItem(String filePath,
long size,
Iterable<MetadataItem> metadata)
Initializes a new instance of
ContainerItem with the item full path. |
ContainerItem(String name,
String directory,
long size,
Iterable<MetadataItem> metadata)
Initializes a new instance of
ContainerItem with the item name and directory. |
Modifier and Type | Method and Description |
---|---|
abstract FileType |
detectFileType(FileTypeDetectionMode detectionMode)
Detects a file type of the container item.
|
String |
getDirectory()
Gets the directory of the item.
|
String |
getFilePath()
Gets the full path of the item.
|
Iterable<MetadataItem> |
getMetadata()
Gets the collection of metadata items.
|
String |
getMetadataValue(String name)
Gets the metadata value.
|
String |
getName()
Gets the name of the item.
|
long |
getSize()
Gets the size of the item.
|
Parser |
openParser()
Creates the
Parser object for the item content. |
Parser |
openParser(LoadOptions loadOptions)
Creates the
Parser object for the item content with LoadOptions . |
abstract Parser |
openParser(LoadOptions loadOptions,
ParserSettings parserSettings)
|
abstract InputStream |
openStream()
Opens the stream of the item content.
|
public ContainerItem(String name, String directory, long size, Iterable<MetadataItem> metadata)
ContainerItem
with the item name and directory.name
- The name of the item.directory
- The directory of the item.size
- The size of the item.metadata
- The collection of metadata items.public ContainerItem(String filePath, long size, Iterable<MetadataItem> metadata)
ContainerItem
with the item full path.filePath
- The full path of the item.size
- The size of the item.metadata
- The collection of metadata items.public String getName()
public String getDirectory()
public String getFilePath()
public long getSize()
public Iterable<MetadataItem> getMetadata()
MetadataItem
objects; empty if metadata isn't set.public String getMetadataValue(String name)
name
- The name of the metadata.null
if the metadata with this name isn't found.public abstract InputStream openStream()
public Parser openParser()
Parser
object for the item content.Parser
class of the item content.public Parser openParser(LoadOptions loadOptions)
Parser
object for the item content with LoadOptions
.loadOptions
- The options to open the item content.Parser
class of the item content.public abstract Parser openParser(LoadOptions loadOptions, ParserSettings parserSettings)
loadOptions
- The options to open the item content.parserSettings
- The parser settings which are used to customize data extraction.Parser
class of the item content.public abstract FileType detectFileType(FileTypeDetectionMode detectionMode)
detectionMode
parameter provides the ability to control file type detection:
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));
}
}
detectionMode
- Defines a mode of the file type detection.FileType
class; FileType.Unknown
if a file type isn't detected.