Class DataPackage
java.lang.Object
org.apache.tika.pipes.core.extractor.frictionless.DataPackage
Represents a Frictionless Data Package manifest (datapackage.json).
See: https://specs.frictionlessdata.io/data-package/
The Data Package format is a simple standard for packaging data with metadata.
This implementation includes:
- name: identifier for the package (typically the container filename)
- created: ISO 8601 timestamp of when the package was created
- resources: list of data files with path, mediatype, bytes, and hash
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty DataPackage for deserialization.DataPackage(String name) Creates a new DataPackage with the given name and current timestamp. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddResource(String path, String mediatype, long bytes, String hash, String name) Adds a resource to this data package with all parameters.voidaddResource(FrictionlessResource resource) Adds a resource to this data package.static DataPackageParses a DataPackage from JSON string.getName()getTitle()booleanReturns true if this package has any resources.intReturns the number of resources in this package.voidsetCreated(String created) voidsetDescription(String description) voidvoidsetResources(List<FrictionlessResource> resources) voidtoJson()Serializes this DataPackage to JSON.toString()voidwriteTo(OutputStream outputStream) Writes this DataPackage as JSON to the given output stream.
-
Constructor Details
-
DataPackage
Creates a new DataPackage with the given name and current timestamp.- Parameters:
name- the package name (typically container filename)
-
DataPackage
public DataPackage()Creates an empty DataPackage for deserialization.
-
-
Method Details
-
getName
-
setName
-
getCreated
-
setCreated
-
getTitle
-
setTitle
-
getDescription
-
setDescription
-
getResources
-
setResources
-
addResource
Adds a resource to this data package.- Parameters:
resource- the resource to add
-
addResource
Adds a resource to this data package with all parameters.- Parameters:
path- relative path within packagemediatype- MIME typebytes- file sizehash- SHA256 hash with "sha256:" prefixname- optional original filename
-
toJson
Serializes this DataPackage to JSON.- Returns:
- JSON string representation
- Throws:
IOException- if serialization fails
-
writeTo
Writes this DataPackage as JSON to the given output stream. Does not close the output stream.- Parameters:
outputStream- the stream to write to- Throws:
IOException- if serialization fails
-
fromJson
Parses a DataPackage from JSON string.- Parameters:
json- the JSON string- Returns:
- parsed DataPackage
- Throws:
IOException- if parsing fails
-
hasResources
public boolean hasResources()Returns true if this package has any resources.- Returns:
- true if resources list is not empty
-
resourceCount
public int resourceCount()Returns the number of resources in this package.- Returns:
- resource count
-
toString
-