Class StorageHeap

  • All Implemented Interfaces:
    Storage

    public class StorageHeap
    extends Object
    implements Storage
    Implementation of not persistent storage on Java heap.
    • Constructor Detail

      • StorageHeap

        public StorageHeap()
        Creates a not persistent storage.
    • Method Detail

      • store

        public OutputStream store​(String id)
                           throws IOException
        Description copied from interface: Storage
        Stores data that will be referenced with an ID.

        If an entry is already stored with this ID, its existing data is fully removed and replaced by the given data. Otherwise, a new entry is created.

        This operation may block the current thread depending on the implementation.

        The returned output stream must be flushed or closed to ensure that the data is available. Example of usage:

         try(OutputStream outputStream = store(id)) {
                outputStream.write(…);
                outputStream.write(…);
         }
         
        Specified by:
        store in interface Storage
        Parameters:
        id - the ID of the stored entry.
        Returns:
        the output stream to write data.
        Throws:
        IOException - if an I/O error occurs.
      • modify

        public OutputStream modify​(String id,
                                   int offset)
                            throws IOException
        Description copied from interface: Storage
        Modifies the entry that is referenced by an ID.

        If an entry is already stored with this ID, its existing data is not removed and only the targeted bytes will be overwritten. Otherwise, a new entry is created.

        This operation may block the current thread depending on the implementation.

        The returned output stream must be flushed or closed to ensure that the data is available.

        Specified by:
        modify in interface Storage
        Parameters:
        id - the ID of the stored entry.
        offset - the offset at which to write data.
        Returns:
        the output stream to write data.
        Throws:
        IOException - if an I/O error occurs.
      • append

        public OutputStream append​(String id)
                            throws IOException
        Description copied from interface: Storage
        Appends some data to an entry referenced with an ID.

        If an entry is already stored with this ID, its existing data is not removed and the given data will be added to the existing entry. Otherwise, a new entry is created.

        This operation may block the current thread depending on the implementation.

        The returned output stream must be flushed or closed to ensure that the data is available. Example of usage:

         try(OutputStream outputStream = append(id)) {
                outputStream.write(…);
                outputStream.write(…);
         }
         
        Specified by:
        append in interface Storage
        Parameters:
        id - the ID of the stored entry.
        Returns:
        the output stream to write data.
        Throws:
        IOException - if an I/O error occurs.
      • load

        @Nullable
        public InputStream load​(String id)
                         throws IOException
        Description copied from interface: Storage
        Loads the data stored with a specific ID or null if there is none.

        The returned input stream must be closed by the caller.

        This operation may block the current thread depending on the implementation.

        Specified by:
        load in interface Storage
        Parameters:
        id - the ID of the entry to be returned.
        Returns:
        the data of the entry stored with the given ID or null.
        Throws:
        IOException - if an I/O error occurs.
      • move

        public void move​(String sourceId,
                         String destinationId)
                  throws IOException
        Description copied from interface: Storage
        Changes the ID of an entry.

        If an entry is already stored with the destination ID, it is overwritten.

        This operation may block the current thread depending on the implementation.

        Specified by:
        move in interface Storage
        Parameters:
        sourceId - the old ID of the entry.
        destinationId - the new ID of the entry.
        Throws:
        IOException - if an I/O error occurs.
      • remove

        public void remove​(String id)
                    throws IOException
        Description copied from interface: Storage
        Removes the entry stored with an ID.

        This operation may block the current thread depending on the implementation.

        Specified by:
        remove in interface Storage
        Parameters:
        id - the ID of the entry to remove.
        Throws:
        IOException - if an I/O error occurs.
      • getSize

        public long getSize​(String id)
                     throws IOException
        Description copied from interface: Storage
        Returns the size of the entry stored with an ID.
        Specified by:
        getSize in interface Storage
        Parameters:
        id - the ID of the entry.
        Returns:
        the size of the entry.
        Throws:
        IOException - if an I/O error occurs.
      • exists

        public boolean exists​(String id)
                       throws IOException
        Description copied from interface: Storage
        Tests whether an entry exists for this ID.
        Specified by:
        exists in interface Storage
        Parameters:
        id - the ID to check.
        Returns:
        true if the given ID exists, false otherwise
        Throws:
        IOException - if an I/O error occurs.
      • getIds

        public String[] getIds()
                        throws IOException
        Description copied from interface: Storage
        Returns all IDs of the stored entries.
        Specified by:
        getIds in interface Storage
        Returns:
        an array of all IDs.
        Throws:
        IOException - if an I/O error occurs.