Class FileResourceWriter

java.lang.Object
org.springframework.geode.core.io.AbstractResourceWriter
org.springframework.geode.core.io.support.FileResourceWriter
All Implemented Interfaces:
ResourceWriter

public class FileResourceWriter extends AbstractResourceWriter
AbstractResourceWriter implementation that writes data of a File based Resource.
Since:
1.3.1
See Also:
  • Field Details

    • DEFAULT_APPEND_TO_FILE

      protected static final boolean DEFAULT_APPEND_TO_FILE
      See Also:
    • DEFAULT_BUFFER_SIZE

      protected static final int DEFAULT_BUFFER_SIZE
      See Also:
  • Constructor Details

    • FileResourceWriter

      public FileResourceWriter()
  • Method Details

    • doWrite

      protected void doWrite(OutputStream resourceOutputStream, byte[] data)
      Description copied from class: AbstractResourceWriter
      Writes the given data to the target 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.
      Specified by:
      doWrite in class AbstractResourceWriter
      Parameters:
      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.
      See Also:
    • isAbleToHandle

      protected boolean isAbleToHandle(@Nullable org.springframework.core.io.Resource resource)
      Description copied from class: AbstractResourceWriter
      Determines whether this writer is able to handle and write to the target Resource. The default implementation determines that the Resource can be handled if the Resource handle is not null.
      Overrides:
      isAbleToHandle in class AbstractResourceWriter
      Parameters:
      resource - Resource to evaluate.
      Returns:
      a boolean value indicating whether this writer is able to handle and write to the target Resource.
      See Also:
      • Resource
    • getBufferSize

      protected int getBufferSize()
      Returns the configured 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.

      Returns:
      the configured buffer size.
    • getOpenOptions

      protected OpenOption[] getOpenOptions()
      Returns the configured 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.
      Returns:
      configured OpenOptions.
      See Also:
    • getResource

      protected Optional<org.springframework.core.io.Resource> getResource()
      Returns an Optional reference to the target Resource.
      Returns:
      an Optional reference to the target Resource.
      See Also:
    • decorate

      @NonNull protected OutputStream decorate(@Nullable OutputStream outputStream)
      Decorates the given OutputStream by adding buffering capabilities.
      Parameters:
      outputStream - OutputStream to decorate.
      Returns:
      the decorated OutputStream.
      See Also:
    • newFileOutputStream

      protected OutputStream newFileOutputStream()
      Tries to construct a new File based OutputStream from the target Resource. By default, the constructed OutputStream is also buffered (e.g. BufferedOutputStream).
      Returns:
      a OutputStream writing to a File identified by the target Resource.
      Throws:
      IllegalStateException - if the target Resource cannot be handled as a File.
      org.springframework.dao.DataAccessResourceFailureException - if the OutputStream could not be created.
      See Also: