java.lang.Object
io.inverno.mod.base.resource.AbstractResource
io.inverno.mod.base.resource.AbstractAsyncResource
- All Implemented Interfaces:
AsyncResource
,Resource
,AutoCloseable
- Direct Known Subclasses:
ClasspathResource
,FileResource
,ModuleResource
,NativeResource
,PathResource
,URLResource
,ZipResource
Base implementation for AsyncResource
.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Thrown when the end of the file is reached when reading a resource. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default read buffer capacity.Fields inherited from class io.inverno.mod.base.resource.AbstractResource
IS_WINDOWS_PATH
-
Constructor Summary
ModifierConstructorDescriptionCreates an asnc resource.protected
AbstractAsyncResource
(MediaTypeService mediaTypeService) Creates an async resource with the specified media type service. -
Method Summary
Modifier and TypeMethodDescriptionReturns the executor service.read()
Reads the resource in a reactive way.void
setExecutor
(ExecutorService executor) Sets the executor service to use when reading or writing the resource asynchronously.void
setReadBufferCapacity
(int readBufferCapacity) Sets the buffer read capacity.Writes content to the resource in a reactive way appending or not content to an existing resource and create or not missing parent directories.Methods inherited from class io.inverno.mod.base.resource.AbstractResource
getMediaType, getMediaTypeService, pathToSanitizedString, setMediaTypeService
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.inverno.mod.base.resource.Resource
close, delete, exists, getFilename, getMediaType, getURI, isFile, lastModified, openReadableByteChannel, openWritableByteChannel, openWritableByteChannel, openWritableByteChannel, resolve, resolve, size, write, write
-
Field Details
-
DEFAULT_READ_BUFFER_CAPACITY
public static final int DEFAULT_READ_BUFFER_CAPACITYThe default read buffer capacity.- See Also:
-
-
Constructor Details
-
AbstractAsyncResource
public AbstractAsyncResource()Creates an asnc resource.
-
AbstractAsyncResource
Creates an async resource with the specified media type service.
- Parameters:
mediaTypeService
- a media type service
-
-
Method Details
-
setReadBufferCapacity
public void setReadBufferCapacity(int readBufferCapacity) Sets the buffer read capacity.
- Parameters:
readBufferCapacity
- the buffer read capacity to set
-
setExecutor
Description copied from interface:AsyncResource
Sets the executor service to use when reading or writing the resource asynchronously.
- Specified by:
setExecutor
in interfaceAsyncResource
- Parameters:
executor
- the executor service to set
-
getExecutor
Description copied from interface:AsyncResource
Returns the executor service.
- Specified by:
getExecutor
in interfaceAsyncResource
- Returns:
- an executor service
-
read
Description copied from interface:Resource
Reads the resource in a reactive way.
- Specified by:
read
in interfaceResource
- Returns:
- a stream of ByteBuf
- Throws:
NotReadableResourceException
- if the resource is not readableResourceException
- if there was an error reading the resource
-
write
public Publisher<Integer> write(Publisher<ByteBuf> data, boolean append, boolean createParents) throws NotWritableResourceException, ResourceException Description copied from interface:Resource
Writes content to the resource in a reactive way appending or not content to an existing resource and create or not missing parent directories.
- Specified by:
write
in interfaceResource
- Parameters:
data
- the stream of data to writeappend
- true to append content to an existing resourcecreateParents
- true to create missing parent directories- Returns:
- a stream of integer emitting number of bytes written
- Throws:
ResourceException
- if there was an error writing to the resourceNotWritableResourceException
-