Interface SharedStorageServiceResource

All Superinterfaces:
java.lang.AutoCloseable, java.io.Closeable

public interface SharedStorageServiceResource
extends java.io.Closeable
Represents a resource stored on common file storage.
NOTE: Client should not assume that implementation of this interface will be synchronized.
Also refer SharedStorageService.getResource(String)
  • Method Details

    • openOutputStream

      java.io.OutputStream openOutputStream() throws java.io.IOException
      Returns OutputStream for writing content to the resource. Its important to close the returned OutputStream once its used. This will release underlying resources
      e.g.
         try (SharedStorageServiceResource sharedResource = Services.get(SharedStorageService.class).getResource(pathStr);
               OutputStream outputStream = sharedResource.openOutputStream()) {
            //write data to outputStream
         }
       
      Returns:
      OutputStream for the storage resource
      Throws:
      java.io.IOException
    • openOutputStream

      java.io.OutputStream openOutputStream​(boolean append) throws java.io.IOException
      Returns OutputStream for writing content to the resource. Its important to close the returned OutputStream once its used. This will release underlying resources
      e.g.
         try (SharedStorageServiceResource sharedResource = Services.get(SharedStorageService.class).getResource(pathStr);
               OutputStream outputStream = sharedResource.openOutputStream()) {
            //write data to outputStream
         }
       
      Parameters:
      append - true to append existing storage resource
      Returns:
      OutputStream for the storage resource
      Throws:
      java.io.IOException
    • openInputStream

      java.io.InputStream openInputStream() throws java.io.IOException
      Returns InputStream for reading content to the resource. Its important to close the returned InputStream once its used. This will release underlying resources
      e.g.
         try (SharedStorageServiceResource sharedResource = Services.get(SharedStorageService.class).getResource(pathStr);
               InputStream inputStream = sharedResource.openInputStream()) {
            //read data from inputStream
         }
       
      Returns:
      InputStream for reading the storage resource
      Throws:
      java.io.IOException - If storage resource does not exist on shared storage
    • openInputStream

      java.io.InputStream openInputStream​(boolean keepCompressed) throws java.io.IOException
      Returns InputStream for reading content to the resource. Its important to close the returned InputStream once its used. This will release underlying resources
      e.g.
         try (SharedStorageServiceResource sharedResource = Services.get(SharedStorageService.class).getResource(pathStr);
               InputStream inputStream = sharedResource.openInputStream(true)) {
            //read data from inputStream
         }
       
      Parameters:
      keepCompressed - true to return compressed stream if the resource is compressed
      Returns:
      InputStream for reading the storage resource
      Throws:
      java.io.IOException - If storage resource does not exist on shared storage
    • getFile

      default java.io.File getFile()
      Creates a local file for the resource. If this method is called then close() should be also called once the resource is not required.
      e.g.
             try (SharedStorageServiceResource resource = Services.get(SharedStorageService.class).getResource(name)) {
               File file = resource.getFile();
             }
       
      Returns:
    • getFile

      java.io.File getFile​(boolean fetchFreshCopy)
      This method behaves similar to getFile() except if the passed value is false then it checks if local file already exists. If yes then return that file otherwise fetch the data and create a local file.
      If this method is called then close() should be also called once the resource is not required.
      e.g.
             try (SharedStorageServiceResource resource = Services.get(SharedStorageService.class).getResource(name)) {
               File file = resource.getFile();
             }
       
      Returns:
    • close

      void close() throws java.io.IOException
      Releases any underlying resources and sync data to storage.
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Throws:
      java.io.IOException
    • isCompressed

      boolean isCompressed()
      Returns:
      true storage resource is compressed
    • delete

      void delete() throws java.io.IOException
      Permanently deletes the resource from storage. This is NOT scoped by the current database transaction and must therefore be performed with care; if you delete a resource but a database transaction is rolled back, this will NOT rollback the delete.
      Throws:
      java.io.IOException
    • getPath

      java.lang.String getPath()
      Returns:
      path, including resource name, of the storage resource which can be used to access the resource
    • getName

      java.lang.String getName()
      Returns:
      name of storage resource. This is just the last name in the path's name sequence.
    • exists

      boolean exists()
      Returns:
      true if the storage resource existing in shared storage
    • mkdirs

      boolean mkdirs()
      Creates the directory named by the path of this resource, including any necessary but nonexistent parent directories It assumes the path denotes a directory.
    • isDirectory

      boolean isDirectory()
      Returns true if the path of the resource is a directory
    • listResources

      java.util.List<SharedStorageServiceResource> listResources()
      Returns:
      list containing children resources of this resource
    • listResources

      java.util.List<SharedStorageServiceResource> listResources​(boolean ignoreErrors)
      Parameters:
      ignoreErrors - true to ignore error while fetching child resource. Such children will not be available in the returned list.
      Returns:
      list containing children resources of this resource
    • rename

      SharedStorageServiceResource rename​(java.lang.String path) throws java.io.IOException
      Renames this storage resource to passed path
      Parameters:
      path - path, including resource name, to which resource needs to be renamed/moved. NOTE: This path is relative to storage root.
      Returns:
      SharedStorageServiceResource for provided path
      Throws:
      java.io.IOException
    • rename

      SharedStorageServiceResource rename​(java.lang.String path, boolean isAbsolutePath) throws java.io.IOException
      Renames this storage resource to passed path
      Parameters:
      path - path, including resource name, to which resource needs to be renamed/moved.
      isAbsolutePath - true if path is absolute path and not relative to storage root.
      Returns:
      SharedStorageServiceResource for provided path
      Throws:
      java.io.IOException
    • size

      long size()
      Returns:
      size of the resource in bytes
    • size

      double size​(FileSizeUnit unit)
      Returns:
      size of the resources in bytes divided by passed in unit
    • lastModified

      long lastModified()
      Returns:
      time when the resource was modified the last. Its total milliseconds from computing epoch i.e. January 1, 1970 UTC.
    • getSharedStorageService

      SharedStorageService getSharedStorageService()
      Returns:
      SharedStorageService using which this resource object was created.