public class PathResource extends AbstractResource implements WritableResource
Resource implementation for java.nio.file.Path handles.
Supports resolution as File, and also as URL.
Implements the extended WritableResource interface.Path| 构造器和说明 |
|---|
PathResource(Path path)
Create a new PathResource from a Path handle.
|
PathResource(String path)
Create a new PathResource from a Path handle.
|
PathResource(URI uri)
Create a new PathResource from a Path handle.
|
| 限定符和类型 | 方法和说明 |
|---|---|
long |
contentLength()
This implementation returns the underlying File's length.
|
Resource |
createRelative(String relativePath)
This implementation creates a FileResource, applying the given path
relative to the path of the underlying file of this resource descriptor.
|
boolean |
equals(Object obj)
This implementation compares the underlying Path references.
|
boolean |
exists()
This implementation returns whether the underlying file exists.
|
String |
getDescription()
Return a description for this resource, to be used for error output when
working with the resource.
|
File |
getFile()
This implementation returns the underlying File reference.
|
String |
getFilename()
This implementation returns the name of the file.
|
InputStream |
getInputStream()
This implementation opens a InputStream for the underlying file.
|
OutputStream |
getOutputStream()
This implementation opens a OutputStream for the underlying file.
|
String |
getPath()
Return the file path for this resource.
|
URI |
getURI()
This implementation returns a URI for the underlying file.
|
URL |
getURL()
This implementation returns a URL for the underlying file.
|
int |
hashCode()
This implementation returns the hash code of the underlying Path reference.
|
boolean |
isReadable()
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()
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()
This implementation returns the underlying File's timestamp.
|
getFileForLastModifiedCheck, isOpen, toStringpublic PathResource(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(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(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 String getPath()
public boolean exists()
exists 在接口中 Resourceexists 在类中 AbstractResourcepublic boolean isReadable()
isReadable 在接口中 ResourceisReadable 在类中 AbstractResourceFiles.isReadable(Path),
Files.isDirectory(Path, java.nio.file.LinkOption...)public InputStream getInputStream() throws IOException
getInputStream 在接口中 InputStreamSourcenull)IOException - if the stream could not be openedFileSystemProvider.newInputStream(Path, OpenOption...)public boolean isWritable()
public OutputStream getOutputStream() throws IOException
getOutputStream 在接口中 WritableResourceIOException - if the stream could not be openedFileSystemProvider.newOutputStream(Path, OpenOption...)public URL getURL() throws IOException
getURL 在接口中 ResourcegetURL 在类中 AbstractResourceIOException - if the resource cannot be resolved as URL, i.e. if the
resource is not available as descriptorPath.toUri(),
URI.toURL()public URI getURI() throws IOException
getURI 在接口中 ResourcegetURI 在类中 AbstractResourceIOException - if the resource cannot be resolved as URI, i.e. if the
resource is not available as descriptorPath.toUri()public File getFile() throws IOException
getFile 在接口中 ResourcegetFile 在类中 AbstractResourceIOException - if the resource cannot be resolved as absolute file path,
i.e. if the resource is not available in a file systempublic long contentLength()
throws IOException
contentLength 在接口中 ResourcecontentLength 在类中 AbstractResourceIOException - if the resource cannot be resolved (in the file system or as
some other known physical resource type)InputStreamSource.getInputStream()public long lastModified()
throws IOException
lastModified 在接口中 ResourcelastModified 在类中 AbstractResourceIOException - 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(String relativePath) throws IOException
createRelative 在接口中 ResourcecreateRelative 在类中 AbstractResourcerelativePath - the relative path (relative to this resource)IOException - if the relative resource cannot be determinedPath.resolve(String)public String getFilename()
getFilename 在接口中 ResourcegetFilename 在类中 AbstractResourcePath.getFileName()public String getDescription()
Resource
Implementations are also encouraged to return this value from their
toString method.
getDescription 在接口中 ResourceObject.toString()public boolean equals(Object obj)
equals 在类中 AbstractResourceResource.getDescription()public int hashCode()
hashCode 在类中 AbstractResourceResource.getDescription()Copyright © 2016. All rights reserved.