类 PathResource
- 所有已实现的接口:
InputStreamSource,OutputStreamSource,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.
Path support is also available
in FileSystemResource,
applying Infra 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 2022/3/25 11:45
- 作者:
- Philippe Marschall, Juergen Hoeller, Harry Yang
- 另请参阅:
-
字段概要
字段从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明PathResource(String path) Create a newPathResourcefrom a path string.PathResource(URI uri) Create a newPathResourcefrom aURI.PathResource(Path path) Create a newPathResourcefrom aPathhandle. -
方法概要
修饰符和类型方法说明longThis implementation returns the underlying file's length.createRelative(String relativePath) This implementation creates aPathResource, applying the given path relative to the path of the underlying file of this resource descriptor.booleanThis implementation compares the underlyingPathreferences.booleanexists()This implementation returns whether the underlying file exists.byte[]Return the contents of this resource as a byte array.getContentAsString(Charset charset) Returns the contents of this resource as a string, using the specified charset.getFile()This implementation returns the underlyingFilereference.This implementation opens anInputStreamfor the underlying file.getName()This implementation returns the name of the file.This implementation opens anOutputStreamfor the underlying file.final StringgetPath()Return the file path for this resource.getURI()This implementation returns aURIfor the underlying file.getURL()This implementation returns aURLfor 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 aReadableByteChannelfor the underlying file.toString()Return a description for this resource, to be used for error output when working with the resource.This implementation opens aWritableByteChannelfor the underlying file.从类继承的方法 cn.taketoday.core.io.AbstractResource
customizeConnection, customizeConnection, getFileForLastModifiedCheck, isDirectory, isOpen, list, list从接口继承的方法 cn.taketoday.core.io.InputStreamSource
getReader, getReader从接口继承的方法 cn.taketoday.core.io.OutputStreamSource
getWriter从接口继承的方法 cn.taketoday.core.io.Resource
isDirectory, isOpen, list, list
-
字段详细资料
-
path
-
-
构造器详细资料
-
PathResource
Create a newPathResourcefrom aPathhandle.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 newPathResourcefrom a path string.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 newPathResourcefrom aURI.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). -
getInputStream
This implementation opens anInputStreamfor 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- 另请参阅:
-
getContentAsByteArray
从接口复制的说明:ResourceReturn the contents of this resource as a byte array.- 指定者:
getContentAsByteArray在接口中Resource- 返回:
- the contents of this resource as byte array
- 抛出:
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
-
getContentAsString
从接口复制的说明:ResourceReturns the contents of this resource as a string, using the specified charset.- 指定者:
getContentAsString在接口中Resource- 参数:
charset- the charset to use for decoding- 返回:
- the contents of this resource as a
String - 抛出:
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
-
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 anOutputStreamfor the underlying file.- 指定者:
getOutputStream在接口中OutputStreamSource- 抛出:
IOException- if the stream could not be opened- 另请参阅:
-
getURL
This implementation returns aURLfor 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 a descriptor- 另请参阅:
-
getURI
This implementation returns aURIfor 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 a descriptor- 另请参阅:
-
isFile
public boolean isFile()This implementation always indicates a file.- 指定者:
isFile在接口中Resource- 覆盖:
isFile在类中AbstractResource- 另请参阅:
-
getFile
This implementation returns the underlyingFilereference.- 指定者:
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 aReadableByteChannelfor the underlying file.- 指定者:
readableChannel在接口中InputStreamSource- 返回:
- 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 aWritableByteChannelfor the underlying file.- 指定者:
writableChannel在接口中OutputStreamSource- 返回:
- 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 aPathResource, 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
- 另请参阅:
-
getName
This implementation returns the name of the file.- 指定者:
getName在接口中Resource- 覆盖:
getName在类中AbstractResource- 另请参阅:
-
toString
从接口复制的说明: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.- 指定者:
toString在接口中Resource- 覆盖:
toString在类中AbstractResource- 另请参阅:
-
equals
This implementation compares the underlyingPathreferences.- 覆盖:
equals在类中AbstractResource
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying Path reference.- 覆盖:
hashCode在类中AbstractResource
-