Package org.springframework.core.io

# Interface WritableResource

All Superinterfaces:
  `InputStreamSource`, `Resource`

All Known Implementing Classes:
  `FileSystemResource`, `FileUrlResource`, `PathResource`

public interface WritableResource extends Resource
Extended interface for a resource that supports writing to it. Provides an `OutputStream accessor`.

Since:
  3.1
Author:
  Juergen Hoeller
See Also:
  - `OutputStream`

## Method Summary

Modifier and Type
Method
Description
`OutputStream`
`getOutputStream()`
Return an `OutputStream` for the underlying resource, allowing to (over-)write its content.
`default boolean`
`isWritable()`
Indicate whether the contents of this resource can be written via `getOutputStream()`.
`default WritableByteChannel`
`writableChannel()`
Return a `WritableByteChannel`.

### Methods inherited from interface org.springframework.core.io.InputStreamSource

`getInputStream`

### Methods inherited from interface org.springframework.core.io.Resource

`contentLength, createRelative, exists, getContentAsByteArray, getContentAsString, getDescription, getFile, getFilename, getURI, getURL, isFile, isOpen, isReadable, lastModified, readableChannel`

## Method Details

### isWritable

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()`
  - `Resource.isReadable()`

### getOutputStream

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

Throws:
  `IOException` - if the stream could not be opened
See Also:
  - `InputStreamSource.getInputStream()`

### writableChannel

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:
  the byte channel for the underlying resource (must not be `null`)
Throws:
  `FileNotFoundException` - if the underlying resource doesn't exist
  `IOException` - if the content channel could not be opened
Since:
  5.0
See Also:
  - `getOutputStream()`