FileSystemResource.FileSystemResource(Path)
@Deprecated 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.
Path
,
Files
Constructor and Description |
---|
PathResource(java.nio.file.Path path)
Deprecated.
Create a new PathResource from a Path handle.
|
PathResource(java.lang.String path)
Deprecated.
Create a new PathResource from a Path handle.
|
PathResource(java.net.URI uri)
Deprecated.
Create a new PathResource from a Path handle.
|
Modifier and Type | Method and Description |
---|---|
long |
contentLength()
Deprecated.
This implementation returns the underlying file's length.
|
Resource |
createRelative(java.lang.String relativePath)
Deprecated.
This implementation creates a PathResource, applying the given path
relative to the path of the underlying file of this resource descriptor.
|
boolean |
equals(java.lang.Object other)
Deprecated.
This implementation compares the underlying Path references.
|
boolean |
exists()
Deprecated.
This implementation returns whether the underlying file exists.
|
java.lang.String |
getDescription()
Deprecated.
Return a description for this resource,
to be used for error output when working with the resource.
|
java.io.File |
getFile()
Deprecated.
This implementation returns the underlying File reference.
|
java.lang.String |
getFilename()
Deprecated.
This implementation returns the name of the file.
|
java.io.InputStream |
getInputStream()
Deprecated.
This implementation opens a InputStream for the underlying file.
|
java.io.OutputStream |
getOutputStream()
Deprecated.
This implementation opens a OutputStream for the underlying file.
|
java.lang.String |
getPath()
Deprecated.
Return the file path for this resource.
|
java.net.URI |
getURI()
Deprecated.
This implementation returns a URI for the underlying file.
|
java.net.URL |
getURL()
Deprecated.
This implementation returns a URL for the underlying file.
|
int |
hashCode()
Deprecated.
This implementation returns the hash code of the underlying Path reference.
|
boolean |
isFile()
Deprecated.
This implementation always indicates a file.
|
boolean |
isReadable()
Deprecated.
This implementation checks whether the underlying file is marked as readable
(and corresponds to an actual file with content, not to a directory).
|
boolean |
isWritable()
Deprecated.
This implementation checks whether the underlying file is marked as writable
(and corresponds to an actual file with content, not to a directory).
|
long |
lastModified()
Deprecated.
This implementation returns the underlying File's timestamp.
|
java.nio.channels.ReadableByteChannel |
readableChannel()
Deprecated.
This implementation opens a Channel for the underlying file.
|
java.nio.channels.WritableByteChannel |
writableChannel()
Deprecated.
This implementation opens a Channel for the underlying file.
|
getFileForLastModifiedCheck, isOpen, toString
public PathResource(java.nio.file.Path path)
Note: Unlike FileSystemResource
, when building relative resources
via createRelative(java.lang.String)
, the relative path will be built underneath
the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
path
- a Path handlepublic PathResource(java.lang.String path)
Note: Unlike FileSystemResource
, when building relative resources
via createRelative(java.lang.String)
, the relative path will be built underneath
the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
path
- a pathPaths.get(String, String...)
public PathResource(java.net.URI uri)
Note: Unlike FileSystemResource
, when building relative resources
via createRelative(java.lang.String)
, the relative path will be built underneath
the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" -> "C:/dir1/dir2"!
uri
- a path URIPaths.get(URI)
public final java.lang.String getPath()
public boolean exists()
exists
in interface Resource
exists
in class AbstractResource
Files.exists(Path, java.nio.file.LinkOption...)
public boolean isReadable()
isReadable
in interface Resource
isReadable
in class AbstractResource
Files.isReadable(Path)
,
Files.isDirectory(Path, java.nio.file.LinkOption...)
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface InputStreamSource
null
)java.io.FileNotFoundException
- if the underlying resource doesn't existjava.io.IOException
- if the content stream could not be openedFileSystemProvider.newInputStream(Path, OpenOption...)
public boolean isWritable()
isWritable
in interface WritableResource
Files.isWritable(Path)
,
Files.isDirectory(Path, java.nio.file.LinkOption...)
public java.io.OutputStream getOutputStream() throws java.io.IOException
getOutputStream
in interface WritableResource
java.io.IOException
- if the stream could not be openedFileSystemProvider.newOutputStream(Path, OpenOption...)
public java.net.URL getURL() throws java.io.IOException
getURL
in interface Resource
getURL
in class AbstractResource
java.io.IOException
- if the resource cannot be resolved as URL,
i.e. if the resource is not available as descriptorPath.toUri()
,
URI.toURL()
public java.net.URI getURI() throws java.io.IOException
getURI
in interface Resource
getURI
in class AbstractResource
java.io.IOException
- if the resource cannot be resolved as URI,
i.e. if the resource is not available as descriptorPath.toUri()
public boolean isFile()
isFile
in interface Resource
isFile
in class AbstractResource
Resource.getFile()
public java.io.File getFile() throws java.io.IOException
getFile
in interface Resource
getFile
in class AbstractResource
java.io.FileNotFoundException
- if the resource cannot be resolved as
absolute file path, i.e. if the resource is not available in a file systemjava.io.IOException
- in case of general resolution/reading failuresInputStreamSource.getInputStream()
public java.nio.channels.ReadableByteChannel readableChannel() throws java.io.IOException
readableChannel
in interface Resource
readableChannel
in class AbstractResource
null
)java.io.FileNotFoundException
- if the underlying resource doesn't existjava.io.IOException
- if the content channel could not be openedFiles.newByteChannel(Path, OpenOption...)
public java.nio.channels.WritableByteChannel writableChannel() throws java.io.IOException
writableChannel
in interface WritableResource
null
)java.io.FileNotFoundException
- if the underlying resource doesn't existjava.io.IOException
- if the content channel could not be openedFiles.newByteChannel(Path, OpenOption...)
public long contentLength() throws java.io.IOException
contentLength
in interface Resource
contentLength
in class AbstractResource
java.io.IOException
- if the resource cannot be resolved
(in the file system or as some other known physical resource type)InputStreamSource.getInputStream()
public long lastModified() throws java.io.IOException
lastModified
in interface Resource
lastModified
in class AbstractResource
java.io.IOException
- if the resource cannot be resolved
(in the file system or as some other known physical resource type)Files.getLastModifiedTime(Path, java.nio.file.LinkOption...)
public Resource createRelative(java.lang.String relativePath) throws java.io.IOException
createRelative
in interface Resource
createRelative
in class AbstractResource
relativePath
- the relative path (relative to this resource)java.io.IOException
- if the relative resource cannot be determinedPath.resolve(String)
public java.lang.String getFilename()
getFilename
in interface Resource
getFilename
in class AbstractResource
Path.getFileName()
public java.lang.String getDescription()
Resource
Implementations are also encouraged to return this value
from their toString
method.
getDescription
in interface Resource
Object.toString()
public boolean equals(java.lang.Object other)
equals
in class AbstractResource
Resource.getDescription()
public int hashCode()
hashCode
in class AbstractResource
Resource.getDescription()