Package org.digidoc4j
Class DataFile
java.lang.Object
org.digidoc4j.DataFile
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AsicDataFile
,DigestDataFile
,LargeDataFile
Data file wrapper providing methods for handling signed files or files to be signed in Container.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDataFile()
Deprecated.Deprecated for removal.Creates in memory document container.DataFile
(InputStream stream, String fileName, String mimeType) Creates in memory document container.Creates container. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Calculates digest http://www.w3.org/2001/04/xmlenc#sha256 for the data file.byte[]
calculateDigest
(URL method) Calculates digest for data file.byte[]
calculateDigest
(DigestAlgorithm digestType) byte[]
getBytes()
Gives file byteseu.europa.esig.dss.model.DSSDocument
long
Returns the data file size.getId()
Returns file ID For BDoc it will return the filenameReturns the file media type.getName()
Returns the data file name.Gives data file as streamboolean
Returnstrue
if the data file size is 0 bytes.void
saveAs
(OutputStream out) Saves a copy of the data file as a file to the specified stream.void
Saves a copy of the data file as a file with the specified file name.void
setDocument
(eu.europa.esig.dss.model.DSSDocument document) Deprecated.Deprecated for removal.void
Set id for the dataFile (DDoc usage only)void
setMediaType
(String mediaType) Deprecated.Deprecated for removal.
-
Constructor Details
-
DataFile
Creates container.- Parameters:
path
- file name with pathmimeType
- MIME type of the data file, for example 'text/plain' or 'application/msword'
-
DataFile
Creates in memory document container.- Parameters:
data
- file contentfileName
- file name with pathmimeType
- MIME type of the data file, for example 'text/plain' or 'application/msword'
-
DataFile
Creates in memory document container.- Parameters:
stream
- file content from streamfileName
- file name with pathmimeType
- MIME type of the stream file, for example 'text/plain' or 'application/msword'
-
DataFile
Deprecated.Deprecated for removal. Use parameterized constructors to create instances that do not need post-construct mutation.
-
-
Method Details
-
calculateDigest
public byte[] calculateDigest()Calculates digest http://www.w3.org/2001/04/xmlenc#sha256 for the data file. If digest values are cached by the implementation and the digest has already been calculated, then the cached value will be returned, otherwise the digest value is calculated and returned.- Returns:
- calculated digest
-
calculateDigest
Calculates digest for data file. If digest values are cached by the implementation and the digest has already been calculated, then the cached value will be returned, otherwise the digest value is calculated and returned.Supported uris for BDoc:
http://www.w3.org/2000/09/xmldsig#sha1
http://www.w3.org/2001/04/xmldsig-more#sha224
http://www.w3.org/2001/04/xmlenc#sha256
http://www.w3.org/2001/04/xmldsig-more#sha384
http://www.w3.org/2001/04/xmlenc#sha512In case of DDoc files the parameter is ignored and SHA1 hash is always returned
- Parameters:
method
- method uri for calculating the digest- Returns:
- calculated digest
-
calculateDigest
- Parameters:
digestType
- digest algorithm type- Returns:
- digest algorithm uri
-
getName
Returns the data file name.- Returns:
- filename
-
getId
Returns file ID For BDoc it will return the filename- Returns:
- id or name
-
getFileSize
public long getFileSize()Returns the data file size.- Returns:
- file size in bytes
-
isFileEmpty
public boolean isFileEmpty()Returnstrue
if the data file size is 0 bytes.- Returns:
true
if the data file is empty
-
getMediaType
Returns the file media type.- Returns:
- media type
-
setMediaType
Deprecated.Deprecated for removal. Use parameterized constructors to create instances that do not need post-construct mutation. -
saveAs
Saves a copy of the data file as a file to the specified stream.- Parameters:
out
- stream where data is written to- Throws:
IOException
- on file write error
-
saveAs
Saves a copy of the data file as a file with the specified file name.- Parameters:
path
- full file path where the data file should be saved to. If the file exists it will be overwritten
-
getBytes
public byte[] getBytes()Gives file bytes- Returns:
- data as bytes
-
getStream
Gives data file as stream- Returns:
- data file stream
-
setId
Set id for the dataFile (DDoc usage only)- Parameters:
dataFileId
- id for the dataFile
-
getDocument
public eu.europa.esig.dss.model.DSSDocument getDocument() -
setDocument
Deprecated.Deprecated for removal. Use parameterized constructors to create instances that do not need post-construct mutation.
-