Interface Blob


public interface Blob
Reference to a blob, which is simply a piece of data identified by its container and name.
  • 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

      boolean exists() throws DataStoreException
      Returns true 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

      boolean delete() throws DataStoreException
      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

      long size() throws DataStoreException
      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

      Instant lastModified() throws DataStoreException
      Returns the last modified time of the blob.
      Returns:
      the last modified time
      Throws:
      DataStoreException - if an error occurred accessing the data store
    • openReader

      Reader openReader() throws DataStoreException
      Creates and returns a Reader 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

      InputStream openInputStream() throws DataStoreException
      Creates and returns an InputStream 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 a TransactionalWriter 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 a TransactionalOutputStream 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

      default void extractTo(File file) throws DataStoreException
      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

      default void extractTo(Path path) throws DataStoreException
      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

      default void extractTo(OutputStream out) throws DataStoreException
      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

      default void extractTo(Writer out) throws DataStoreException
      Transfers the content of this blob to a writer.
      Parameters:
      out - the writer
      Throws:
      DataStoreException - if an error occurred accessing the data store
    • storeFrom

      default void storeFrom(File file) throws DataStoreException
      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

      default void storeFrom(Path path) throws DataStoreException
      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

      default String extractText() throws DataStoreException
      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

      default byte[] extractBytes() throws DataStoreException
      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

      default Population extractPopulation() throws DataStoreException
      Extracts the content of this blob to a Population.
      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 DataStoreException
      Executes a function with an InputStream 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 DataStoreException
      Executes a function with a Reader 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 the Stateful 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 store
      ClassNotFoundException - if the class of the serialized object could not be found
    • extractObject

      default Object extractObject() throws DataStoreException, ClassNotFoundException
      Extracts the blob and deserializes the content.
      Returns:
      the deserialized object
      Throws:
      DataStoreException - if an error occurred accessing the data store
      ClassNotFoundException - if the class of the serialized object could not be found
    • extractObject

      default <T> T extractObject(Class<T> type) throws DataStoreException, ClassNotFoundException
      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 store
      ClassNotFoundException - if the class of the serialized object could not be found
    • storeText

      default void storeText(String text) throws DataStoreException
      Stores the given string to this blob.
      Parameters:
      text - the text to store
      Throws:
      DataStoreException - if an error occurred accessing the data store
    • storeBytes

      default void storeBytes(byte[] data) throws DataStoreException
      Stores the given data to this blob.
      Parameters:
      data - the data to store
      Throws:
      DataStoreException - if an error occurred accessing the data store
    • storePopulation

      default void storePopulation(Population population) throws DataStoreException
      Stores the given Population 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

      default void storeText(Formattable<?> formattable) throws DataStoreException
      Stores the given Formattable object to this blob using the TableFormat.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 given Formattable object to this blob using the specified table format.
      Parameters:
      formattable - the formattable object to store
      tableFormat - the table format
      Throws:
      DataStoreException - if an error occurred accessing the data store
    • storeFrom

      default void storeFrom(InputStream in) throws DataStoreException
      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

      default void storeFrom(Reader reader) throws DataStoreException
      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 an OutputStream 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 a PrintStream 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 a Writer 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

      default <T extends Stateful> void storeState(T value) throws DataStoreException
      Stores a Stateful 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

      default void storeObject(Object value) throws DataStoreException, NotSerializableException
      Stores a serializable object to the blob.
      Parameters:
      value - the object to store
      Throws:
      DataStoreException - if an error occurred accessing the data store
      NotSerializableException - if the object is not serializable
    • getURI

      default URI getURI()
      Returns the URI for this blob, which can be used with DataStoreFactory.resolveBlob(java.net.URI).
      Returns:
      the URI
    • toJSON

      default String toJSON()
      Returns a description of this blob formatted as JSON.
      Returns:
      the JSON string
    • toJSON

      default String toJSON(URI baseURI)
      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

      default String toJSON(URI baseURI, boolean full)
      Returns a description of this blob formatted as JSON.
      Parameters:
      baseURI - the base URI, which is used to produce URLs
      full - if true, output the full data (can produce large output)
      Returns:
      the JSON string