Package org.digidoc4j

Class DataFile

java.lang.Object
org.digidoc4j.DataFile
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AsicDataFile, DigestDataFile, LargeDataFile

public class DataFile extends Object implements Serializable
Data file wrapper providing methods for handling signed files or files to be signed in Container.
See Also:
  • Constructor Details

    • DataFile

      public DataFile(String path, String mimeType)
      Creates container.
      Parameters:
      path - file name with path
      mimeType - MIME type of the data file, for example 'text/plain' or 'application/msword'
    • DataFile

      public DataFile(byte[] data, String fileName, String mimeType)
      Creates in memory document container.
      Parameters:
      data - file content
      fileName - file name with path
      mimeType - MIME type of the data file, for example 'text/plain' or 'application/msword'
    • DataFile

      public DataFile(InputStream stream, String fileName, String mimeType)
      Creates in memory document container.
      Parameters:
      stream - file content from stream
      fileName - file name with path
      mimeType - MIME type of the stream file, for example 'text/plain' or 'application/msword'
    • DataFile

      @Deprecated public 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

      public byte[] calculateDigest(URL method)
      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#sha512

      In 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

      public byte[] calculateDigest(DigestAlgorithm digestType)
      Parameters:
      digestType - digest algorithm type
      Returns:
      digest algorithm uri
    • getName

      public String getName()
      Returns the data file name.
      Returns:
      filename
    • getId

      public String 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()
      Returns true if the data file size is 0 bytes.
      Returns:
      true if the data file is empty
    • getMediaType

      public String getMediaType()
      Returns the file media type.
      Returns:
      media type
    • setMediaType

      @Deprecated public void setMediaType(String mediaType)
      Deprecated.
      Deprecated for removal. Use parameterized constructors to create instances that do not need post-construct mutation.
    • saveAs

      public void saveAs(OutputStream out) throws IOException
      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

      public void saveAs(String path)
      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

      public InputStream getStream()
      Gives data file as stream
      Returns:
      data file stream
    • setId

      public void setId(String dataFileId)
      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 public void setDocument(eu.europa.esig.dss.model.DSSDocument document)
      Deprecated.
      Deprecated for removal. Use parameterized constructors to create instances that do not need post-construct mutation.