Package com.dua3.utility.io
Interface WritableObjectStore
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
ObjectStore
- All Known Implementing Classes:
FileObjectStore
Represents a generic object storage interface for managing and interacting
with objects stored at specified URIs. The interface provides methods to
list objects, read and write data, manage folders, and perform other common
storage operations.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcreateFolder(URI path) Creates a folder at the specified URI path within the object store.getRoot()Retrieve the rootURIthat serves as the base location for objects managed by this storage.openOutputStream(URI path, ObjectStore.OutputOption... options) Opens an output stream to write data to the specified URI.longwrite(URI path, byte[] data, int from, int to, ObjectStore.OutputOption... options) Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store.default longwrite(URI path, byte[] data, ObjectStore.OutputOption... options) Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store.longwrite(URI path, InputStream in, ObjectStore.OutputOption... options) Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store.Methods inherited from interface java.lang.AutoCloseable
close
-
Method Details
-
getRoot
URI getRoot()Retrieve the rootURIthat serves as the base location for objects managed by this storage. TheURIreturned will always be anabsoluteURI.- Returns:
- the root
URIrepresenting the base location of the storage
-
write
Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store. If the object already exists, its contents may be overwritten.- Parameters:
path- theURIspecifying the location where the input data should be writtenin- theInputStreamproviding the data to be writtenoptions- theObjectStore.ObjectInfospecifying how to handle existing objects at the output location; when none are present,ObjectStore.OutputOption.CREATE_NEWis used.- Returns:
- the number of bytes successfully written to the object
- Throws:
AbsolutePathException- if the path isabsoluteIllegalPathException- if the path points outside the root of the storageObjectExistsException- if the path points to an existing object and theObjectStore.OutputOption.CREATE_NEWoption is specifiedIOException- if an I/O error occurs during the write operation
-
write
Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store. If the object already exists, its contents may be overwritten.- Parameters:
path- theURIspecifying the location where the input data should be writtendata- the byte array containing the data to be writtenoptions- theObjectStore.OutputOptionspecifying how to handle existing objects at the output location; when none are present,ObjectStore.OutputOption.CREATE_NEWis used.- Returns:
- the number of bytes successfully written to the object
- Throws:
AbsolutePathException- if the path isabsoluteIllegalPathException- if the path points outside the root of the storageObjectExistsException- if the path points to an existing object and theObjectStore.OutputOption.CREATE_NEWoption is specifiedIOException- if an I/O error occurs during the write operation
-
write
long write(URI path, byte[] data, int from, int to, ObjectStore.OutputOption... options) throws IOException Writes data from the specifiedInputStreamto an object located at the specified URI path within the object store. If the object already exists, its contents may be overwritten.- Parameters:
path- theURIspecifying the location where the input data should be writtendata- the byte array containing the data to be writtenfrom- the starting index in the data array to be written (inclusive)to- the ending index in the data array to be written (exclusive)options- theObjectStore.OutputOptionspecifying how to handle existing objects at the output location; when none are present,ObjectStore.OutputOption.CREATE_NEWis used.- Returns:
- the number of bytes successfully written to the object
- Throws:
AbsolutePathException- if the path isabsoluteIllegalPathException- if the path points outside the root of the storageObjectExistsException- if the path points to an existing object and theObjectStore.OutputOption.CREATE_NEWoption is specifiedIOException- if an I/O error occurs during the write operation
-
openOutputStream
Opens an output stream to write data to the specified URI. This method provides anOutputStreamfor writing data to the object located at the specified path. If the object already exists, its contents may be overwritten.If any I/O error occurs while opening the output stream, the operation aborts and the store may be partially modified.
- Parameters:
path- theURIspecifying the location where the output data will be writtenoptions- theObjectStore.OutputOptionspecifying how to handle existing objects at the output location; when none are present,ObjectStore.OutputOption.CREATE_NEWis used.- Returns:
- an
OutputStreamfor writing data to the specified URI - Throws:
AbsolutePathException- if the path isabsoluteIllegalPathException- if the path points outside the root of the storageObjectExistsException- if the path points to an existing object and theObjectStore.OutputOption.CREATE_NEWoption is specifiedIOException- if an I/O error occurs while opening the output stream
-
createFolder
Creates a folder at the specified URI path within the object store. If the folder already exists, this method does nothing. Missing parent folders are created as needed. If a non-folder object already exists at the specified path, an exception is thrown.- Parameters:
path- the URI representing the path where the folder will be created- Throws:
AbsolutePathException- if the path isabsoluteIllegalPathException- if the path points outside the root of the storageNotAFolderException- if the path or any missing parent points to an existing non-folder objectIOException- if an I/O error occurs while creating the folder
-