Top Description Methods
org.springframework.core.io

public Interface WritableResource

extends Resource
Known Direct Implementers
org.springframework.core.io.FileSystemResource, org.springframework.core.io.FileUrlResource, org.springframework.core.io.PathResource
Imports
java.io.IOException, .OutputStream, java.nio.channels.Channels, .WritableByteChannel

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

Method Summary

Modifier and TypeMethod and Description
public OutputStream
getOutputStream()

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

public default boolean
isWritable()

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

public default WritableByteChannel

Returns:

the byte channel for the underlying resource (must not be null)
writableChannel
()

Return a WritableByteChannel.

Inherited from org.springframework.core.io.Resource:
contentLengthcreateRelativeexistsgetContentAsByteArraygetContentAsStringgetDescriptiongetFilegetFilenamegetURIgetURLisFileisOpenisReadablelastModifiedreadableChannel

Method Detail

getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

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

Exceptions
IOException:
if the stream could not be opened
See Also
getInputStream()
isWritableback to summary
public default boolean isWritable()

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.

See Also
getOutputStream(), isReadable()
writableChannelback to summary
public default WritableByteChannel writableChannel() throws IOException

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().

Returns:WritableByteChannel

the byte channel for the underlying resource (must not be null)

Exceptions
IOException:
if the content channel could not be opened
FileNotFoundException:
if the underlying resource doesn't exist
Since
5.0
See Also
getOutputStream()