Package org.digidoc4j

Class ContainerBuilder

java.lang.Object
org.digidoc4j.ContainerBuilder
Direct Known Subclasses:
AsicEContainerBuilder, AsicSContainerBuilder, DDocContainerBuilder, PadesContainerBuilder

public abstract class ContainerBuilder extends Object
Class for creating and opening containers.

Here's an example of creating a new container:

Container container = ContainerBuilder.
   aContainer("BDOC").
   withConfiguration(configuration). // Configuration settings
   withDataFile("testFiles/legal_contract_1.txt", "text/plain"). // Adding a document from a hard drive
   withDataFile(inputStream, "legal_contract_2.txt", "text/plain"). // Adding a document from a stream
   withTimeStampToken(DigestAlgorithm digestAlgorithm). // (DEPRECATED) Adding timestamp token in case of ASICS
   build();

Use ContainerBuilder.aContainer() to create a new container builder, populate the builder with data and finally call build() to create the container with the populated data. Use fromExistingFile(String) or fromStream(InputStream) to open an existing container.

  • Constructor Details

    • ContainerBuilder

      public ContainerBuilder()
  • Method Details

    • aContainer

      public static ContainerBuilder aContainer()
      Create a new ASICE container builder.
      Returns:
      builder for creating or opening a ASICE container.
    • aContainer

      public static ContainerBuilder aContainer(String type)
      Create a new container builder based on a container type.
      Parameters:
      type - a type of container to be created, e.g. "BDOC(ASICE)", "ASICS" or "DDOC".
      Returns:
      builder for creating a container.
    • aContainer

      public static ContainerBuilder aContainer(Container.DocumentType type)
      Create a new container builder based on a container type.
      Parameters:
      type - a type of container to be created, e.g. "BDOC(ASICE)", "ASICS" or "DDOC".
      Returns:
      builder for creating a container.
    • build

      public Container build()
      Builds a new container or opens existing container from the parameters given to the builder.
      Returns:
      fresh container.
    • withConfiguration

      public ContainerBuilder withConfiguration(Configuration configuration)
      Specify configuration for the container.
      Parameters:
      configuration - configuration to use for creating the container.
      Returns:
      builder for creating or opening a container.
    • withDataFile

      public ContainerBuilder withDataFile(String filePath, String mimeType) throws InvalidDataFileException
      Add a data file to the container.
      Parameters:
      filePath - data file location on the disk.
      mimeType - MIME type of the data file, for example 'text/plain' or 'application/msword'
      Returns:
      builder for creating or opening a container.
      Throws:
      InvalidDataFileException
    • withDataFile

      public ContainerBuilder withDataFile(InputStream inputStream, String fileName, String mimeType) throws InvalidDataFileException
      Add a data file from a stream to the container.
      Parameters:
      inputStream - stream of a data file to be added to the container.
      fileName - name of the data file to be added.
      mimeType - MIME type of the data file, for example 'text/plain' or 'application/msword'
      Returns:
      builder for creating or opening a container.
      Throws:
      InvalidDataFileException
    • withDataFile

      public ContainerBuilder withDataFile(File file, String mimeType) throws InvalidDataFileException
      Add a data file to the container.
      Parameters:
      file - data file to be added to the container.
      mimeType - MIME type of the data file, for example 'text/plain' or 'application/msword'
      Returns:
      builder for creating or opening a container.
      Throws:
      InvalidDataFileException
    • withDataFile

      public ContainerBuilder withDataFile(DataFile dataFile)
      Add a data file to the container.
      Parameters:
      dataFile - data file to be added to the container.
      Returns:
      builder for creating or opening a container.
    • withTimeStampToken

      @Deprecated public ContainerBuilder withTimeStampToken(eu.europa.esig.dss.enumerations.DigestAlgorithm digestAlgorithm)
      Deprecated.
      Deprecated for removal
      Add time stamp token to container
      Parameters:
      digestAlgorithm -
      Returns:
      ContainerBuilder
    • fromExistingFile

      public ContainerBuilder fromExistingFile(String filePath)
      Open container from an existing file.
      Parameters:
      filePath - absolute path to the container file.
      Returns:
      builder for creating or opening a container.
    • fromStream

      public ContainerBuilder fromStream(InputStream containerInputStream)
      Open container from a stream.
      Parameters:
      containerInputStream - stream of the container file to be opened.
      Returns:
      builder for creating or opening a container.
    • setContainerImplementation

      public static <T extends Container> void setContainerImplementation(String containerType, Class<T> containerClass)
      Set a custom container implementation class to be used for the container type.
      Type Parameters:
      T - container class extending the Container interface.
      Parameters:
      containerType - container type name used when handling such containers.
      containerClass - container implementation for handling such container types.
      See Also:
    • removeCustomContainerImplementations

      public static void removeCustomContainerImplementations()
      Clear the list of custom container implementations and types and continue using the default container types and implementations.
    • usingTempDirectory

      public abstract ContainerBuilder usingTempDirectory(String temporaryDirectoryPath)