Package org.moeaframework.analysis.store
Interface Blob
public interface Blob
Reference to a blob, which is simply a piece of data identified by its container and name.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
delete()
Deletes this blob if it exists.boolean
exists()
Returnstrue
if the blob exists;false
otherwise.default byte[]
Extracts the content of this blob to bytes.default <R> R
extractInputStream
(org.apache.commons.io.function.IOFunction<InputStream, R> function) Executes a function with anInputStream
for reading this blob.default Object
Extracts the blob and deserializes the content.default <T> T
extractObject
(Class<T> type) Extracts the blob and deserializes the content.default Population
Extracts the content of this blob to aPopulation
.default <R> R
extractReader
(org.apache.commons.io.function.IOFunction<Reader, R> function) Executes a function with aReader
for reading this blob.default <T extends Stateful>
TextractState
(T value) Extracts the state and loads it into theStateful
object.default String
Extracts the content of this blob to a string.default void
Extracts the content of this blob to a file.default void
extractTo
(OutputStream out) Transfers the content of this blob to an output stream.default void
Transfers the content of this blob to a writer.default void
Extracts the content of this blob to a path.Gets the container for this blob.getName()
Gets the name of this blob.default URI
getURI()
Returns the URI for this blob, which can be used withDataStoreFactory.resolveBlob(java.net.URI)
.default boolean
Executes the consumer function if this blob exists.default boolean
Executes the consumer function if this blob is missing.Returns the last modified time of the blob.Creates and returns anInputStream
for reading binary data from this blob.Creates and returns aTransactionalOutputStream
for writing binary data to this blob.Creates and returns aReader
for reading text from this blob.Creates and returns aTransactionalWriter
for writing text to this blob.long
size()
Returns the size of the blob, in bytes.default void
storeBytes
(byte[] data) Stores the given data to this blob.default void
Stores the contents of a file to this blob.default void
storeFrom
(InputStream in) Stores the content read from an input stream to this this blob.default void
Stores the content read from a reader to this this blob.default void
Stores the contents of a path to this blob.default void
storeObject
(Object value) Stores a serializable object to the blob.default void
storeOutputStream
(org.apache.commons.io.function.IOConsumer<OutputStream> consumer) Executes a consumer with anOutputStream
for writing to this blob.default void
storePopulation
(Population population) Stores the givenPopulation
object to this blob as a result file.default void
storePrintStream
(org.apache.commons.io.function.IOConsumer<PrintStream> consumer) Executes a consumer with aPrintStream
for writing to this blob.default <T extends Stateful>
voidstoreState
(T value) Stores aStateful
object to the blob.default void
Stores the given string to this blob.default void
storeText
(Formattable<?> formattable) Stores the givenFormattable
object to this blob using theTableFormat.Plaintext
format.default void
storeText
(Formattable<?> formattable, TableFormat tableFormat) Stores the givenFormattable
object to this blob using the specified table format.default void
storeWriter
(org.apache.commons.io.function.IOConsumer<Writer> consumer) Executes a consumer with aWriter
for writing to this blob.default String
toJSON()
Returns a description of this blob formatted as JSON.default String
Returns a description of this blob formatted as JSON.default String
Returns a description of this blob formatted as JSON.
-
Method Details
-
getName
String getName()Gets the name of this blob.- Returns:
- the blo name
-
getContainer
Container getContainer()Gets the container for this blob.- Returns:
- the container
-
exists
Returnstrue
if the blob exists;false
otherwise.- Returns:
true
if the blob exists;false
otherwise- Throws:
DataStoreException
- if an error occurred accessing the data store
-
delete
Deletes this blob if it exists.- Returns:
true
if the blob was deleted;false
if the blob does not exist- Throws:
DataStoreException
- if an error occurred accessing the data store
-
size
Returns the size of the blob, in bytes.- Returns:
- the size of the blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
lastModified
Returns the last modified time of the blob.- Returns:
- the last modified time
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
openReader
Creates and returns aReader
for reading text from this blob. The caller is responsible for closing the reader when finished.- Returns:
- a reader for this blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
openInputStream
Creates and returns anInputStream
for reading binary data from this blob. The caller is responsible for closing the stream when finished.- Returns:
- an input stream for this blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
openWriter
Creates and returns aTransactionalWriter
for writing text to this blob. The caller is responsible for committing and closing the writer when finished. If the writer is closed before being committed, any written content is discarded.- Returns:
- the writer for this blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
openOutputStream
Creates and returns aTransactionalOutputStream
for writing binary data to this blob. The caller is responsible for committing and closing the stream when finished. If the stream is closed before being committed, any written content is discarded.- Returns:
- the output stream for this blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
ifMissing
default boolean ifMissing(org.apache.commons.io.function.IOConsumer<Blob> consumer) throws DataStoreException Executes the consumer function if this blob is missing.- Parameters:
consumer
- the consumer function- Returns:
true
if the blob is missing and the consumer was invoked;false
otherwise- Throws:
DataStoreException
- if an error occurred accessing the data store
-
ifFound
default boolean ifFound(org.apache.commons.io.function.IOConsumer<Blob> consumer) throws DataStoreException Executes the consumer function if this blob exists.- Parameters:
consumer
- the consumer function- Returns:
true
if the blob exists and the consumer was invoked;false
otherwise- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractTo
Extracts the content of this blob to a file.- Parameters:
file
- the destination file- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractTo
Extracts the content of this blob to a path.- Parameters:
path
- the destination path- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractTo
Transfers the content of this blob to an output stream.- Parameters:
out
- the output stream- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractTo
Transfers the content of this blob to a writer.- Parameters:
out
- the writer- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeFrom
Stores the contents of a file to this blob.- Parameters:
file
- the source file- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeFrom
Stores the contents of a path to this blob.- Parameters:
path
- the source path- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractText
Extracts the content of this blob to a string.- Returns:
- the content of the blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractBytes
Extracts the content of this blob to bytes.- Returns:
- the content of the blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractPopulation
Extracts the content of this blob to aPopulation
.- Returns:
- the content of the blob
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractInputStream
default <R> R extractInputStream(org.apache.commons.io.function.IOFunction<InputStream, R> function) throws DataStoreExceptionExecutes a function with anInputStream
for reading this blob. The input stream is automatically closed when the function returns.- Type Parameters:
R
- the return type- Parameters:
function
- the function- Returns:
- the object read from the stream
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractReader
default <R> R extractReader(org.apache.commons.io.function.IOFunction<Reader, R> function) throws DataStoreExceptionExecutes a function with aReader
for reading this blob. The reader is automatically closed when the function returns.- Type Parameters:
R
- the return type- Parameters:
function
- the function- Returns:
- the object read from the reader
- Throws:
DataStoreException
- if an error occurred accessing the data store
-
extractState
default <T extends Stateful> T extractState(T value) throws DataStoreException, ClassNotFoundException Extracts the state and loads it into theStateful
object.- Type Parameters:
T
- the object type- Parameters:
value
- the stateful object- Returns:
- the stateful object
- Throws:
DataStoreException
- if an error occurred accessing the data storeClassNotFoundException
- if the class of the serialized object could not be found
-
extractObject
Extracts the blob and deserializes the content.- Returns:
- the deserialized object
- Throws:
DataStoreException
- if an error occurred accessing the data storeClassNotFoundException
- if the class of the serialized object could not be found
-
extractObject
Extracts the blob and deserializes the content.- Type Parameters:
T
- the return type- Parameters:
type
- the type of the object- Returns:
- the deserialized object cast to the given type
- Throws:
DataStoreException
- if an error occurred accessing the data storeClassNotFoundException
- if the class of the serialized object could not be found
-
storeText
Stores the given string to this blob.- Parameters:
text
- the text to store- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeBytes
Stores the given data to this blob.- Parameters:
data
- the data to store- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storePopulation
Stores the givenPopulation
object to this blob as a result file.- Parameters:
population
- the population to store- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeText
Stores the givenFormattable
object to this blob using theTableFormat.Plaintext
format.- Parameters:
formattable
- the formattable object to store- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeText
default void storeText(Formattable<?> formattable, TableFormat tableFormat) throws DataStoreException Stores the givenFormattable
object to this blob using the specified table format.- Parameters:
formattable
- the formattable object to storetableFormat
- the table format- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeFrom
Stores the content read from an input stream to this this blob.- Parameters:
in
- the input stream- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeFrom
Stores the content read from a reader to this this blob.- Parameters:
reader
- the reader- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeOutputStream
default void storeOutputStream(org.apache.commons.io.function.IOConsumer<OutputStream> consumer) throws DataStoreException Executes a consumer with anOutputStream
for writing to this blob. The stream is automatically closed when the consumer returns.- Parameters:
consumer
- the consumer- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storePrintStream
default void storePrintStream(org.apache.commons.io.function.IOConsumer<PrintStream> consumer) throws DataStoreException Executes a consumer with aPrintStream
for writing to this blob. The stream is automatically closed when the consumer returns.- Parameters:
consumer
- the consumer- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeWriter
default void storeWriter(org.apache.commons.io.function.IOConsumer<Writer> consumer) throws DataStoreException Executes a consumer with aWriter
for writing to this blob. The writer is automatically closed when the consumer returns.- Parameters:
consumer
- the consumer function- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeState
Stores aStateful
object to the blob.- Type Parameters:
T
- the object type- Parameters:
value
- the stateful object to store- Throws:
DataStoreException
- if an error occurred accessing the data store
-
storeObject
Stores a serializable object to the blob.- Parameters:
value
- the object to store- Throws:
DataStoreException
- if an error occurred accessing the data storeNotSerializableException
- if the object is not serializable
-
getURI
Returns the URI for this blob, which can be used withDataStoreFactory.resolveBlob(java.net.URI)
.- Returns:
- the URI
-
toJSON
Returns a description of this blob formatted as JSON.- Returns:
- the JSON string
-
toJSON
Returns a description of this blob formatted as JSON.- Parameters:
baseURI
- the base URI, which is used to produce URLs- Returns:
- the JSON string
-
toJSON
Returns a description of this blob formatted as JSON.- Parameters:
baseURI
- the base URI, which is used to produce URLsfull
- iftrue
, output the full data (can produce large output)- Returns:
- the JSON string
-