Class IOResources
Resource
content.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Content.Source
asContentSource
(Resource resource, ByteBufferPool bufferPool, int bufferSize, boolean direct) Gets aContent.Source
with the contents of a resource.static Content.Source
asContentSource
(Resource resource, ByteBufferPool bufferPool, int bufferSize, boolean direct, long first, long length) Gets aContent.Source
with a range of the contents of a resource.static InputStream
asInputStream
(Resource resource) Gets anInputStream
with the contents of a resource.static void
copy
(Resource resource, Content.Sink sink, ByteBufferPool bufferPool, int bufferSize, boolean direct, long first, long length, Callback callback) Performs an asynchronous copy of a subset of the contents of a resource to a sink, using the given buffer pool and buffer characteristics.static void
copy
(Resource resource, Content.Sink sink, ByteBufferPool bufferPool, int bufferSize, boolean direct, Callback callback) Performs an asynchronous copy of the contents of a resource to a sink, using the given buffer pool and buffer characteristics.static RetainableByteBuffer
toRetainableByteBuffer
(Resource resource, ByteBufferPool bufferPool, boolean direct) Reads the contents of a Resource into a RetainableByteBuffer.
-
Constructor Details
-
IOResources
public IOResources()
-
-
Method Details
-
toRetainableByteBuffer
public static RetainableByteBuffer toRetainableByteBuffer(Resource resource, ByteBufferPool bufferPool, boolean direct) throws IllegalArgumentException Reads the contents of a Resource into a RetainableByteBuffer.
The resource must not be a directory, must exists and there must be a way to access its contents.
Multiple optimized methods are used to access the resource's contents but if they all fail,
Resource.newInputStream()
is used as a fallback.- Parameters:
resource
- the resource to be read.bufferPool
- theByteBufferPool
to get buffers from. null means allocate new buffers as needed.direct
- the directness of the buffers.- Returns:
- a
RetainableByteBuffer
containing the resource's contents. - Throws:
IllegalArgumentException
- if the resource is a directory or does not exist or there is no way to access its contents.
-
asContentSource
public static Content.Source asContentSource(Resource resource, ByteBufferPool bufferPool, int bufferSize, boolean direct) throws IllegalArgumentException Gets a
Content.Source
with the contents of a resource.The resource must not be a directory, must exists and there must be a way to access its contents.
Multiple optimized methods are used to access the resource's contents but if they all fail,
Resource.newInputStream()
is used as a fallback.- Parameters:
resource
- the resource from which to get aContent.Source
.bufferPool
- theByteBufferPool
to get buffers from. null means allocate new buffers as needed.bufferSize
- the size of the buffer to be used for the copy. Any value < 1 means use a default value.direct
- the directness of the buffers, this parameter is ignored ifbufferSize
is < 1.- Returns:
- the
Content.Source
. - Throws:
IllegalArgumentException
- if the resource is a directory or does not exist or there is no way to access its contents.
-
asContentSource
public static Content.Source asContentSource(Resource resource, ByteBufferPool bufferPool, int bufferSize, boolean direct, long first, long length) throws IllegalArgumentException Gets a
Content.Source
with a range of the contents of a resource.The resource must not be a directory, must exists and there must be a way to access its contents.
Multiple optimized methods are used to access the resource's contents but if they all fail,
Resource.newInputStream()
is used as a fallback.- Parameters:
resource
- the resource from which to get aContent.Source
.bufferPool
- theByteBufferPool
to get buffers from. null means allocate new buffers as needed.bufferSize
- the size of the buffer to be used for the copy. Any value < 1 means use a default value.direct
- the directness of the buffers, this parameter is ignored ifbufferSize
is < 1.first
- the first byte from which to read from.length
- the length of the content to read.- Returns:
- the
Content.Source
. - Throws:
IllegalArgumentException
- if the resource is a directory or does not exist or there is no way to access its contents.
-
asInputStream
Gets an
InputStream
with the contents of a resource.The resource must not be a directory, must exist and must return non-null to
Resource.newInputStream()
.- Parameters:
resource
- the resource from which to get anInputStream
.- Returns:
- the
InputStream
. - Throws:
IllegalArgumentException
- if the resource is a directory or does not exist orResource.newInputStream()
returns null.
-
copy
public static void copy(Resource resource, Content.Sink sink, ByteBufferPool bufferPool, int bufferSize, boolean direct, Callback callback) throws IllegalArgumentException Performs an asynchronous copy of the contents of a resource to a sink, using the given buffer pool and buffer characteristics.
The resource must not be a directory, must exist and there must be a way to access its contents.
Multiple optimized methods are used to access the resource's contents but if they all fail,
asContentSource(Resource, ByteBufferPool, int, boolean)
is used as a fallback to perform thecopy
.- Parameters:
resource
- the resource to copy from.sink
- the sink to copy to.bufferPool
- theByteBufferPool
to get buffers from. null means allocate new buffers as needed.bufferSize
- the size of the buffer to be used for the copy. Any value < 1 means use a default value.direct
- the directness of the buffers, this parameter is ignored ifbufferSize
is < 1.callback
- the callback to notify when the copy is done.- Throws:
IllegalArgumentException
- if the resource is a directory or does not exist or there is no way to access its contents.
-
copy
public static void copy(Resource resource, Content.Sink sink, ByteBufferPool bufferPool, int bufferSize, boolean direct, long first, long length, Callback callback) throws IllegalArgumentException Performs an asynchronous copy of a subset of the contents of a resource to a sink, using the given buffer pool and buffer characteristics.
The resource must not be a directory, must exist and there must be a way to access its contents.
Multiple optimized methods are used to access the resource's contents but if they all fail,
asContentSource(Resource, ByteBufferPool, int, boolean, long, long)
is used as a fallback to perform thecopy
.- Parameters:
resource
- the resource to copy from.sink
- the sink to copy to.bufferPool
- theByteBufferPool
to get buffers from. null means allocate new buffers as needed.bufferSize
- the size of the buffer to be used for the copy. Any value < 1 means use a default value.direct
- the directness of the buffers, this parameter is ignored ifbufferSize
is < 1.first
- the first byte of the resource to start from.length
- the length of the resource's contents to copy.callback
- the callback to notify when the copy is done.- Throws:
IllegalArgumentException
- if the resource is a directory or does not exist or there is no way to access its contents.
-