Interface DigitalObject

  • All Superinterfaces:
    java.util.function.Supplier<java.io.InputStream>

    public interface DigitalObject
    extends java.util.function.Supplier<java.io.InputStream>
    Digital Object (an object composed of a set of bit sequences) that is the original target of Long Term Preservation in an Archive. The object is identified by Reference Information and its bits are accessed through an InputStream.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      static DigitalObject fromBytes​(java.lang.String referenceInformation, byte[] bytes)
      Create a DigitalObject from bytes.
      static DigitalObject fromFile​(java.lang.String referenceInformation, java.io.File file)
      Create a DigitalObject from a file.
      static DigitalObject fromPath​(java.lang.String referenceInformation, java.nio.file.Path path)
      Create a DigitalObject from a path to a file.
      static DigitalObject fromResource​(java.lang.String referenceInformation, java.lang.Class<?> type, java.lang.String resourceName)
      Create a DigitalObject from a classpath resource.
      static DigitalObject fromString​(java.lang.String referenceInformation, java.lang.String value, java.nio.charset.Charset charset)
      Create a DigitalObject from a string.
      static DigitalObject fromSupplier​(java.lang.String referenceInformation, java.util.function.Supplier<java.io.InputStream> supplier)
      Create a DigitalObject from a supplier.
      static DigitalObject fromSupplier​(java.lang.String referenceInformation, java.util.function.Supplier<java.lang.Long> sizeSupplier, java.util.function.Supplier<java.io.InputStream> contentSupplier)
      Create a DigitalObject from a supplier.
      java.lang.String getReferenceInformation()
      A unique identifier for this object that can be used as Reference Information.
      long getSize()
      Returns the size of the content.
      static long getSize​(java.util.function.Supplier<java.io.InputStream> supplier)
      Calculate the size of an input stream by counting the number of bytes in it.
      • Methods inherited from interface java.util.function.Supplier

        get
    • Method Detail

      • getReferenceInformation

        java.lang.String getReferenceInformation()
        A unique identifier for this object that can be used as Reference Information.
        Returns:
        A unique identifier for this object
      • getSize

        long getSize()
        Returns the size of the content. Determining this may be slow, depending on the source of the content.
        Returns:
        the size of the content, in bytes
        Since:
        8.5.0
      • fromFile

        static DigitalObject fromFile​(java.lang.String referenceInformation,
                                      java.io.File file)
        Create a DigitalObject from a file.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        file - The file that holds the content of the DigitalObject
        Returns:
        The newly created DigitalObject
      • fromSupplier

        static DigitalObject fromSupplier​(java.lang.String referenceInformation,
                                          java.util.function.Supplier<java.lang.Long> sizeSupplier,
                                          java.util.function.Supplier<java.io.InputStream> contentSupplier)
        Create a DigitalObject from a supplier.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        sizeSupplier - The supplier of the size of the content
        contentSupplier - The supplier of the content of the DigitalObject
        Returns:
        The newly created DigitalObject
      • fromPath

        static DigitalObject fromPath​(java.lang.String referenceInformation,
                                      java.nio.file.Path path)
        Create a DigitalObject from a path to a file.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        path - The path to the file that holds the content of the DigitalObject
        Returns:
        The newly created DigitalObject
      • fromBytes

        static DigitalObject fromBytes​(java.lang.String referenceInformation,
                                       byte[] bytes)
        Create a DigitalObject from bytes.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        bytes - The content of the DigitalObject
        Returns:
        The newly created DigitalObject
      • fromString

        static DigitalObject fromString​(java.lang.String referenceInformation,
                                        java.lang.String value,
                                        java.nio.charset.Charset charset)
        Create a DigitalObject from a string.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        value - The string that holds the content of the DigitalObject
        charset - The encoding of the given string value
        Returns:
        The newly created DigitalObject
      • fromResource

        static DigitalObject fromResource​(java.lang.String referenceInformation,
                                          java.lang.Class<?> type,
                                          java.lang.String resourceName)
        Create a DigitalObject from a classpath resource.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        type - The type loaded by a classloader that has access to the resource
        resourceName - The name of the resource on the classpath
        Returns:
        The newly created DigitalObject
      • fromSupplier

        static DigitalObject fromSupplier​(java.lang.String referenceInformation,
                                          java.util.function.Supplier<java.io.InputStream> supplier)
        Create a DigitalObject from a supplier.
        Warning:
        The size of the content will be calculated by going through the stream and counting the bytes. This may negatively impact performance.
        Parameters:
        referenceInformation - The unique identifier to use as Reference Information
        supplier - The supplier of the content of the DigitalObject
        Returns:
        The newly created DigitalObject
      • getSize

        static long getSize​(java.util.function.Supplier<java.io.InputStream> supplier)
        Calculate the size of an input stream by counting the number of bytes in it. This will be slow if the stream is large.
        Parameters:
        supplier - The supplier of the content of the DigitalObject
        Returns:
        the size of the stream, or -1 in case of an I/O error.
        Since:
        8.5.0