Package com.onenetwork.platform.env
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
NOTE: Client should not assume that implementation of this interface will be synchronized.
Also refer
SharedStorageService.getResource(String)
-
Method Summary
Modifier and Type Method Description void
close()
Releases any underlying resources and sync data to storage.void
delete()
Permanently deletes the resource from storage.boolean
exists()
default java.io.File
getFile()
Creates a local file for the resource.java.io.File
getFile(boolean fetchFreshCopy)
This method behaves similar togetFile()
except if the passed value is false then it checks if local file already exists.java.lang.String
getName()
java.lang.String
getPath()
SharedStorageService
getSharedStorageService()
boolean
isCompressed()
boolean
isDirectory()
Returns true if the path of the resource is a directorylong
lastModified()
java.util.List<SharedStorageServiceResource>
listResources()
java.util.List<SharedStorageServiceResource>
listResources(boolean ignoreErrors)
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.java.io.InputStream
openInputStream()
ReturnsInputStream
for reading content to the resource.java.io.InputStream
openInputStream(boolean keepCompressed)
ReturnsInputStream
for reading content to the resource.java.io.OutputStream
openOutputStream()
ReturnsOutputStream
for writing content to the resource.java.io.OutputStream
openOutputStream(boolean append)
ReturnsOutputStream
for writing content to the resource.SharedStorageServiceResource
rename(java.lang.String path)
Renames this storage resource to passed pathSharedStorageServiceResource
rename(java.lang.String path, boolean isAbsolutePath)
Renames this storage resource to passed pathlong
size()
double
size(FileSizeUnit unit)
-
Method Details
-
openOutputStream
java.io.OutputStream openOutputStream() throws java.io.IOExceptionReturnsOutputStream
for writing content to the resource. Its important to close the returnedOutputStream
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.IOExceptionReturnsOutputStream
for writing content to the resource. Its important to close the returnedOutputStream
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.IOExceptionReturnsInputStream
for reading content to the resource. Its important to close the returnedInputStream
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.IOExceptionReturnsInputStream
for reading content to the resource. Its important to close the returnedInputStream
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 thenclose()
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 togetFile()
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 thenclose()
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.IOExceptionReleases any underlying resources and sync data to storage.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isCompressed
boolean isCompressed()- Returns:
- true storage resource is compressed
-
delete
void delete() throws java.io.IOExceptionPermanently 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
- 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
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.IOExceptionRenames 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
- 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.
-