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, writeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitthenWriteTo, writeprotected static final boolean DEFAULT_APPEND_TO_FILE
protected static final int DEFAULT_BUFFER_SIZE
protected void doWrite(java.io.OutputStream resourceOutputStream,
byte[] data)
AbstractResourceWriterResource (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 AbstractResourceWriterresourceOutputStream - 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.OutputStreamprotected boolean isAbleToHandle(@Nullable
org.springframework.core.io.Resource resource)
AbstractResourceWriterResource.
The default implementation determines that the Resource can be handled if the Resource handle
is not null.isAbleToHandle in class AbstractResourceWriterresource - Resource to evaluate.Resource.Resourceprotected 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.OpenOptionprotected 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(),
OutputStreamprotected 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()