Class PathResource

java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.PathResource
All Implemented Interfaces:
InputStreamSource, Resource, WritableResource

public class PathResource extends AbstractResource implements WritableResource
Resource implementation for Path handles, performing all operations and transformations via the Path API. Supports resolution as a File and also as a URL. Implements the extended WritableResource interface.

Note: As of 5.1, Path support is also available in FileSystemResource, applying Spring's standard String-based path transformations but performing all operations via the Files API. This PathResource is effectively a pure java.nio.path.Path based alternative with different createRelative behavior.

Since:
4.0
Author:
Philippe Marschall, Juergen Hoeller
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new PathResource from a Path handle.
    Create a new PathResource from a Path handle.
    Create a new PathResource from a Path handle.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    This implementation returns the underlying file's length.
    createRelative(String relativePath)
    This implementation creates a PathResource, applying the given path relative to the path of the underlying file of this resource descriptor.
    boolean
    This implementation compares the underlying Path references.
    boolean
    This implementation returns whether the underlying file exists.
    byte[]
    Return the contents of this resource as a byte array.
    Returns the contents of this resource as a string, using the specified charset.
    Return a description for this resource, to be used for error output when working with the resource.
    This implementation returns the underlying File reference.
    This implementation returns the name of the file.
    This implementation opens a InputStream for the underlying file.
    This implementation opens a OutputStream for the underlying file.
    final String
    Return the file path for this resource.
    This implementation returns a URI for the underlying file.
    This implementation returns a URL for the underlying file.
    int
    This implementation returns the hash code of the underlying Path reference.
    boolean
    This implementation always indicates a file.
    boolean
    This implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).
    boolean
    This implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).
    long
    This implementation returns the underlying File's timestamp.
    This implementation opens a Channel for the underlying file.
    This implementation opens a Channel for the underlying file.

    Methods inherited from class org.springframework.core.io.AbstractResource

    getFileForLastModifiedCheck, isOpen, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

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

    isOpen