Class ReferencedData
java.lang.Object
com.github.cafapi.common.util.ref.ReferencedData
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 Summary
Modifier and TypeMethodDescriptionacquire
(DataSource source) Return the referenced data as a stream, potentially performing a remote lookup.byte[]
getData()
static ReferencedData
getReferencedData
(String ref) Create a ReferencedData object that uses a remote reference to data present in an ObjectSource.static ReferencedData
getWrappedData
(byte[] data) Create a ReferencedData instance that directly wraps data without a reference.static ReferencedData
getWrappedData
(String ref, byte[] data) Create a ReferencedData instance that wraps data but also has a reference.long
size
(DataSource source) Determine the size of the data.
-
Method Details
-
getReference
- Returns:
- the remote reference to the object in the DataStore, if set
-
getData
public byte[] getData() -
acquire
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 acquiredIllegalStateException
- if there is no object or reference present
-
size
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
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
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
Create a ReferencedData instance that wraps data but also has a reference.- Parameters:
ref
- the reference to be interpreted by the DataStoredata
- the raw data to wrapper, also accessible via the supplied reference- Returns:
- a new ReferencedData instance that wraps and references the data supplied
-