Class SandboxedStorage

  • All Implemented Interfaces:
    Storage

    public class SandboxedStorage
    extends Object
    implements Storage
    Extends the storage on file system to add sandboxing for the applications.
    • Constructor Detail

      • SandboxedStorage

        public SandboxedStorage()
                         throws IOException
        Creates a sandboxed storage on file system.

        The root folder is determined dynamically depending on the KF context. Each module has a different one.

        Throws:
        IOException - if the root cannot be created.
        See Also:
        Kernel.getContextOwner(), StorageFs()
      • SandboxedStorage

        public SandboxedStorage​(String root)
                         throws IOException
        Creates a storage on file system specifying the root folder where the root folder will be created.

        The root folder is determined dynamically depending on the KF context. Each module has a different one.

        Parameters:
        root - the root folder.
        Throws:
        IllegalArgumentException - if the root already exists and is not a directory.
        IOException - if the root cannot be created.
    • Method Detail

      • getRootFolder

        public String getRootFolder​(Module module)
        Gets the root folder of the storage service for a given module.
        Parameters:
        module - the module.
        Returns:
        the root folder.
      • store

        public OutputStream store​(String s)
                           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:
        s - 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 s,
                                   int i)
                            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:
        s - the ID of the stored entry.
        i - 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 s)
                            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:
        s - the ID of the stored entry.
        Returns:
        the output stream to write data.
        Throws:
        IOException - if an I/O error occurs.
      • load

        public InputStream load​(String s)
                         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:
        s - 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 s,
                         String s1)
                  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:
        s - the old ID of the entry.
        s1 - the new ID of the entry.
        Throws:
        IOException - if an I/O error occurs.
      • remove

        public void remove​(String s)
                    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:
        s - the ID of the entry to remove.
        Throws:
        IOException - if an I/O error occurs.
      • getSize

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

        public boolean exists​(String s)
                       throws IOException
        Description copied from interface: Storage
        Tests whether an entry exists for this ID.
        Specified by:
        exists in interface Storage
        Parameters:
        s - 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.