spring-framework / org.springframework.core.io / WritableResource

WritableResource

interface WritableResource : Resource

Extended interface for a resource that supports writing to it. Provides an OutputStream accessor.

Author
Juergen Hoeller

Since
3.1

See Also
java.io.OutputStream

Functions

getOutputStream

abstract fun getOutputStream(): OutputStream

Return an OutputStream for the underlying resource, allowing to (over-)write its content.

isWritable

open fun isWritable(): Boolean

Indicate whether the contents of this resource can be written via #getOutputStream().

Will be true for typical resource descriptors; note that actual content writing may still fail when attempted. However, a value of false is a definitive indication that the resource content cannot be modified.

writableChannel

open fun writableChannel(): WritableByteChannel

Return a WritableByteChannel.

It is expected that each call creates a fresh channel.

The default implementation returns Channels#newChannel(OutputStream) with the result of #getOutputStream().

Inheritors

FileUrlResource

open class FileUrlResource : UrlResource, WritableResource

Subclass of UrlResource which assumes file resolution, to the degree of implementing the WritableResource interface for it.

This is the class resolved by DefaultResourceLoader for a "file:..." URL location, allowing a downcast to WritableResource for it.

Alternatively, for direct construction from a java.io.File handle, consider using FileSystemResource. For an NIO java.nio.file.Path, consider using PathResource instead.

PathResource

open class PathResource : AbstractResource, WritableResource

Resource implementation for java.nio.file.Path handles. Supports resolution as File, and also as URL. Implements the extended WritableResource interface.