Class ReferencedData

java.lang.Object
com.github.cafapi.common.util.ref.ReferencedData

public class ReferencedData extends Object
Utility wrapper for allowing data to potentially be within a message or located on a remote DataStore. The acquire(ObjectSource) method allows transparent method of obtaining an InputStream to the data. This is primarily intended for use with large amounts of binary data that needs to be processed without storing it all in memory.
  • Method Details

    • getReference

      public String getReference()
      Returns:
      the remote reference to the object in the DataStore, if set
    • getData

      public byte[] getData()
    • acquire

      public InputStream acquire(DataSource source) throws DataSourceException
      Return the referenced data as a stream, potentially performing a remote lookup.
      Parameters:
      source - the implementation that provides object instances given the provided references
      Returns:
      a stream of the data that this container is wrapping
      Throws:
      DataSourceException - if the data cannot be acquired
      IllegalStateException - if there is no object or reference present
    • size

      public long size(DataSource source) throws DataSourceException
      Determine the size of the data.
      Parameters:
      source - the implementation that provides object instances given the provided references
      Returns:
      the size of the abstracted data, in bytes
      Throws:
      DataSourceException - if the size information cannot be acquired
    • getReferencedData

      public static ReferencedData getReferencedData(String ref)
      Create a ReferencedData object that uses a remote reference to data present in an ObjectSource.
      Parameters:
      ref - the reference to be interpreted by the DataStore
      Returns:
      a new ReferencedData instance that relates to data in an ObjectSource via reference
    • getWrappedData

      public static ReferencedData getWrappedData(byte[] data)
      Create a ReferencedData instance that directly wraps data without a reference.
      Parameters:
      data - the raw data to wrapper
      Returns:
      a new ReferencedData instance that directly wraps the data specified
    • getWrappedData

      public static ReferencedData getWrappedData(String ref, byte[] data)
      Create a ReferencedData instance that wraps data but also has a reference.
      Parameters:
      ref - the reference to be interpreted by the DataStore
      data - the raw data to wrapper, also accessible via the supplied reference
      Returns:
      a new ReferencedData instance that wraps and references the data supplied