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

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.

Author
Philippe Marschall

Author
Juergen Hoeller

Since
4.0

See Also
FileSystemResourcejava.nio.file.Pathjava.nio.file.Files

Constructors

<init>

PathResource(path: Path)
PathResource(path: String)
PathResource(uri: URI)

Create a new PathResource from a Path handle.

Note: Unlike FileSystemResource, when building relative resources via #createRelative, the relative path will be built underneath the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!

Functions

contentLength

open fun contentLength(): Long

This implementation returns the underlying File's length.

createRelative

open fun createRelative(relativePath: String): Resource

This implementation creates a PathResource, applying the given path relative to the path of the underlying file of this resource descriptor.

equals

open fun equals(other: Any?): Boolean

This implementation compares the underlying Path references.

exists

open fun exists(): Boolean

This implementation returns whether the underlying file exists.

getDescription

open fun getDescription(): String

getFile

open fun getFile(): File

This implementation returns the underlying File reference.

getFilename

open fun getFilename(): String

This implementation returns the name of the file.

getInputStream

open fun getInputStream(): InputStream

This implementation opens a InputStream for the underlying file.

getOutputStream

open fun getOutputStream(): OutputStream

This implementation opens a OutputStream for the underlying file.

getPath

fun getPath(): String

Return the file path for this resource.

getURI

open fun getURI(): URI

This implementation returns a URI for the underlying file.

getURL

open fun getURL(): URL

This implementation returns a URL for the underlying file.

hashCode

open fun hashCode(): Int

This implementation returns the hash code of the underlying Path reference.

isFile

open fun isFile(): Boolean

This implementation always indicates a file.

isReadable

open fun isReadable(): Boolean

This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).

isWritable

open fun isWritable(): Boolean

This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).

lastModified

open fun lastModified(): Long

This implementation returns the underlying File's timestamp.

readableChannel

open fun readableChannel(): ReadableByteChannel

This implementation opens a Channel for the underlying file.

writableChannel

open fun writableChannel(): WritableByteChannel

This implementation opens a Channel for the underlying file.