类 PathResource
- 所有已实现的接口:
InputStreamSource,Resource,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.
- 从以下版本开始:
- 4.0
- 作者:
- Philippe Marschall, Juergen Hoeller
- 另请参阅:
-
构造器概要
构造器构造器说明PathResource(String path) Create a new PathResource from a Path handle.PathResource(URI uri) Create a new PathResource from a Path handle.PathResource(Path path) Create a new PathResource from a Path handle. -
方法概要
修饰符和类型方法说明longThis 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.booleanThis implementation compares the underlying Path references.booleanexists()This implementation returns whether the underlying file exists.Return a description for this resource, to be used for error output when working with the resource.getFile()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 StringgetPath()Return the file path for this resource.getUri()This implementation returns a URI for the underlying file.getUrl()This implementation returns a URL for the underlying file.inthashCode()This implementation returns the hash code of the underlying Path reference.booleanisFile()This implementation always indicates a file.booleanThis implementation checks whether the underlying file is marked as readable (and corresponds to an actual file with content, not to a directory).booleanThis implementation checks whether the underlying file is marked as writable (and corresponds to an actual file with content, not to a directory).longThis 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.从类继承的方法 com.alibaba.nacos.common.packagescan.resource.AbstractResource
getFileForLastModifiedCheck, isOpen, toString
-
构造器详细资料
-
PathResource
Create a new PathResource from a Path handle.Note: Unlike
FileSystemResource, when building relative resources viacreateRelative(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 handle
-
PathResource
Create a new PathResource from a Path handle.Note: Unlike
FileSystemResource, when building relative resources viacreateRelative(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- 另请参阅:
-
PathResource
Create a new PathResource from a Path handle.Note: Unlike
FileSystemResource, when building relative resources viacreateRelative(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 URI- 另请参阅:
-
-
方法详细资料
-
getPath
Return the file path for this resource. -
exists
public boolean exists()This implementation returns whether the underlying file exists.- 指定者:
exists在接口中Resource- 覆盖:
exists在类中AbstractResource- 另请参阅:
-
isReadable
public 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).- 指定者:
isReadable在接口中Resource- 覆盖:
isReadable在类中AbstractResource- 另请参阅:
-
getInputStream
This implementation opens a InputStream for the underlying file.- 指定者:
getInputStream在接口中InputStreamSource- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource does not existIOException- if the content stream could not be opened- 另请参阅:
-
isWritable
public 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). -
getOutputStream
This implementation opens a OutputStream for the underlying file.- 指定者:
getOutputStream在接口中WritableResource- 抛出:
IOException- if the stream could not be opened- 另请参阅:
-
getUrl
This implementation returns a URL for the underlying file.- 指定者:
getUrl在接口中Resource- 覆盖:
getUrl在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- 另请参阅:
-
getUri
This implementation returns a URI for the underlying file.- 指定者:
getUri在接口中Resource- 覆盖:
getUri在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as descriptor- 另请参阅:
-
isFile
public boolean isFile()This implementation always indicates a file.- 指定者:
isFile在接口中Resource- 覆盖:
isFile在类中AbstractResource- 另请参阅:
-
getFile
This implementation returns the underlying File reference.- 指定者:
getFile在接口中Resource- 覆盖:
getFile在类中AbstractResource- 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures- 另请参阅:
-
readableChannel
This implementation opens a Channel for the underlying file.- 指定者:
readableChannel在接口中Resource- 覆盖:
readableChannel在类中AbstractResource- 返回:
- the byte channel for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource doesn't existIOException- if the content channel could not be opened- 另请参阅:
-
writableChannel
This implementation opens a Channel for the underlying file.- 指定者:
writableChannel在接口中WritableResource- 返回:
- the byte channel for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource doesn't existIOException- if the content channel could not be opened- 另请参阅:
-
contentLength
This implementation returns the underlying file's length.- 指定者:
contentLength在接口中Resource- 覆盖:
contentLength在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
-
lastModified
This implementation returns the underlying File's timestamp.- 指定者:
lastModified在接口中Resource- 覆盖:
lastModified在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
-
createRelative
This implementation creates a PathResource, applying the given path relative to the path of the underlying file of this resource descriptor.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中AbstractResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 另请参阅:
-
getFilename
This implementation returns the name of the file.- 指定者:
getFilename在接口中Resource- 覆盖:
getFilename在类中AbstractResource- 另请参阅:
-
getDescription
从接口复制的说明:ResourceReturn a description for this resource, to be used for error output when working with the resource.Implementations are also encouraged to return this value from their
toStringmethod.- 指定者:
getDescription在接口中Resource- 另请参阅:
-
equals
This implementation compares the underlying Path references.- 覆盖:
equals在类中AbstractResource- 另请参阅:
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying Path reference.- 覆盖:
hashCode在类中AbstractResource- 另请参阅:
-