public class FileResourceWriter extends AbstractResourceWriter
File
,
OutputStream
,
Files
,
OpenOption
,
Resource
,
AbstractResourceWriter
Modifier and Type | Field and Description |
---|---|
protected static boolean |
DEFAULT_APPEND_TO_FILE |
protected static int |
DEFAULT_BUFFER_SIZE |
Constructor and Description |
---|
FileResourceWriter() |
Modifier and Type | Method and Description |
---|---|
protected java.io.OutputStream |
decorate(java.io.OutputStream outputStream)
Decorates the given
OutputStream by adding buffering capabilities. |
protected void |
doWrite(java.io.OutputStream resourceOutputStream,
byte[] data)
Writes the given data to the target
Resource (intentionally) by using the OutputStream
returned by WritableResource.getOutputStream() . |
protected int |
getBufferSize()
Returns the configured
buffer size used by this writer to chunk the data written to
the File . |
protected java.nio.file.OpenOption[] |
getOpenOptions()
Returns the configured
OpenOptions used to configure the stream writing to the File . |
protected java.util.Optional<org.springframework.core.io.Resource> |
getResource()
Returns an
Optional reference to the target Resource . |
protected boolean |
isAbleToHandle(org.springframework.core.io.Resource resource)
Determines whether this writer is able to handle and write to the target
Resource . |
protected java.io.OutputStream |
newFileOutputStream()
Tries to construct a new
File based OutputStream from the target Resource . |
preProcess, write
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
thenWriteTo, write
protected static final boolean DEFAULT_APPEND_TO_FILE
protected static final int DEFAULT_BUFFER_SIZE
protected void doWrite(java.io.OutputStream resourceOutputStream, byte[] data)
AbstractResourceWriter
Resource
(intentionally) by using the OutputStream
returned by WritableResource.getOutputStream()
.
However, other algorithm/strategy implementations are free to write to the Resource
as is appropriate
for the given context (e.g. cloud environment). In those cases, implementors should override
the AbstractResourceWriter.write(Resource, byte[])
method.doWrite
in class AbstractResourceWriter
resourceOutputStream
- OutputStream
returned from WritableResource.getOutputStream()
used to write the given data to the locations identified by the target Resource
.data
- array of bytes containing the data to write.OutputStream
protected boolean isAbleToHandle(@Nullable org.springframework.core.io.Resource resource)
AbstractResourceWriter
Resource
.
The default implementation determines that the Resource
can be handled if the Resource
handle
is not null.isAbleToHandle
in class AbstractResourceWriter
resource
- Resource
to evaluate.Resource
.Resource
protected int getBufferSize()
buffer size
used by this writer to chunk the data written to
the File
.
Subclasses should override this method to tune the buffer size based on the context and requirements.
buffer size
.protected java.nio.file.OpenOption[] getOpenOptions()
OpenOptions
used to configure the stream writing to the File
.
By default, the File
will be created
,
truncated
and written
to.
Subclasses should override this method to tune the File
stream based on context and requirements.OpenOptions
.OpenOption
protected java.util.Optional<org.springframework.core.io.Resource> getResource()
Optional
reference to the target Resource
.Optional
reference to the target Resource
.Resource
,
Optional
@NonNull protected java.io.OutputStream decorate(@Nullable java.io.OutputStream outputStream)
OutputStream
by adding buffering capabilities.outputStream
- OutputStream
to decorate.OutputStream
.newFileOutputStream()
,
OutputStream
protected java.io.OutputStream newFileOutputStream()
File
based OutputStream
from the target Resource
.
By default, the constructed OutputStream
is also buffered (e.g. BufferedOutputStream
).OutputStream
writing to a File
identified by the target Resource
.java.lang.IllegalStateException
- if the target Resource
cannot be handled as a File
.org.springframework.dao.DataAccessResourceFailureException
- if the OutputStream
could not be created.BufferedOutputStream
,
OutputStream
,
getBufferSize()
,
getOpenOptions()
,
getResource()