类 FileSystemResource
- 所有已实现的接口:
InputStreamSource,OutputStreamSource,Resource,WritableResource,ThrowingConsumer<OutputStream>,Consumer<OutputStream>
Resource implementation for java.io.File and
java.nio.file.Path handles with a file system target.
Supports resolution as a File and also as a URL.
Implements the extended WritableResource interface.
Note: this Resource implementation uses
NIO.2 API for read/write interactions. it may be constructed with a
Path handle in which case it will perform all file system
interactions via NIO.2, only resorting to File on getFile().
-
字段概要
字段从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明FileSystemResource(File file) Create a newFileSystemResourcefrom aFilehandle.FileSystemResource(String path) Create a newFileSystemResourcefrom a file path.FileSystemResource(FileSystem fileSystem, String path) Create a newFileSystemResourcefrom aFileSystemhandle, locating the specified path.FileSystemResource(Path filePath) -
方法概要
修饰符和类型方法说明longThis implementation returns the underlying File/Path length.createRelative(String relativePath) Create a resource relative to this resource.booleanbooleanexists()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 underlying File reference.This implementation opens an NIO file stream for the underlying file.getName()Determine the filename for this resource — typically the last part of the path — for example,"myfile.txt".This implementation opens a FileOutputStream for the underlying file.final StringgetPath()Return the file path for this resource.getURI()Return a URI handle for this resource.getURL()This implementation returns a URL for the underlying file.inthashCode()booleanTests whether the resource denoted by this abstract pathname is a directory.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).longThis implementation returns the underlying File/Path last-modified time.String[]list()listResourceunder the directoryResource[]list(ResourceFilter filter) listResourceunder the directoryThis implementation opens a FileChannel for the underlying file.toString()Return a description for this resource, to be used for error output when working with the resource.This implementation opens a FileChannel for the underlying file.从类继承的方法 cn.taketoday.core.io.AbstractResource
customizeConnection, customizeConnection, getFileForLastModifiedCheck, isOpen从接口继承的方法 cn.taketoday.core.io.InputStreamSource
acceptWithException, getReader, getReader, transferTo从接口继承的方法 cn.taketoday.core.io.OutputStreamSource
getWriter从接口继承的方法 cn.taketoday.util.function.ThrowingConsumer
accept, accept, throwing从接口继承的方法 cn.taketoday.core.io.WritableResource
isWritable
-
字段详细资料
-
file
-
path
-
filePath
-
-
构造器详细资料
-
FileSystemResource
Create a newFileSystemResourcefrom a file path.Note: When building relative resources via
createRelative(java.lang.String), it makes a difference whether the specified resource base path here ends with a slash or not. In the case of "C:/dir1/", relative paths will be built underneath that root: e.g. relative path "dir2" → "C:/dir1/dir2". In the case of "C:/dir1", relative paths will apply at the same directory level: relative path "dir2" → "C:/dir2".- 参数:
path- a file path- 另请参阅:
-
FileSystemResource
Create a newFileSystemResourcefrom aFilehandle.Note: When building relative resources via
createRelative(java.lang.String), the relative path will apply at the same directory level: e.g. new File("C:/dir1"), relative path "dir2" → "C:/dir2"! If you prefer to have relative paths built underneath the given root directory, use theconstructor with a file pathto append a trailing slash to the root path: "C:/dir1/", which indicates this directory as root for all relative paths.- 参数:
file- a File handle- 另请参阅:
-
FileSystemResource
Create a newFileSystemResourcefrom aPathhandle, performing all file system interactions via NIO.2 instead ofFile.In contrast to
PathResource, this variant strictly follows the generalFileSystemResourceconventions, in particular in terms of path cleaning andcreateRelative(String)handling.Note: When building relative resources via
createRelative(java.lang.String), the relative path will apply at the same directory level: e.g. Paths.get("C:/dir1"), relative path "dir2" → "C:/dir2"! If you prefer to have relative paths built underneath the given root directory, use theconstructor with a file pathto append a trailing slash to the root path: "C:/dir1/", which indicates this directory as root for all relative paths. Alternatively, consider usingPathResource(Path)forjava.nio.path.Pathresolution increateRelative, always nesting relative paths.- 参数:
filePath- a Path handle to a file- 另请参阅:
-
FileSystemResource
Create a newFileSystemResourcefrom aFileSystemhandle, locating the specified path.This is an alternative to
FileSystemResource(String), performing all file system interactions via NIO.2 instead ofFile.- 参数:
fileSystem- the FileSystem to locate the path withinpath- a file path- 从以下版本开始:
- 4.0
- 另请参阅:
-
-
方法详细资料
-
getPath
Return the file path for this resource. -
getFilePath
- 从以下版本开始:
- 4.0
-
exists
public boolean exists()This implementation returns whether the underlying file exists.- 指定者:
exists在接口中Resource- 覆盖:
exists在类中AbstractResource- 另请参阅:
-
getInputStream
This implementation opens an NIO file stream 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- 另请参阅:
-
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
-
getOutputStream
This implementation opens a FileOutputStream for the underlying file.- 指定者:
getOutputStream在接口中OutputStreamSource- 抛出:
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 a descriptor
-
getURI
Return a URI handle for this resource.- 指定者:
getURI在接口中Resource- 覆盖:
getURI在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved as URI, i.e. if the resource is not available as a descriptor
-
getFile
This implementation returns the underlying File reference.- 指定者:
getFile在接口中Resource- 覆盖:
getFile在类中AbstractResource- 另请参阅:
-
isFile
public boolean isFile()This implementation always indicates a file.- 指定者:
isFile在接口中Resource- 覆盖:
isFile在类中AbstractResource- 另请参阅:
-
isDirectory
从接口复制的说明:ResourceTests whether the resource denoted by this abstract pathname is a directory.Where it is required to distinguish an I/O exception from the case that the file is not a directory, or where several attributes of the same file are required at the same time, then the
Files.readAttributesmethod may be used.- 指定者:
isDirectory在接口中Resource- 覆盖:
isDirectory在类中AbstractResource- 返回:
trueif and only if the file denoted by this abstract pathname exists and is a directory;falseotherwise- 抛出:
SecurityException- If a security manager exists and itsmethod denies read access to the fileSecurityManager.checkRead(java.lang.String)IOException- cannot determine resource
-
contentLength
This implementation returns the underlying File/Path 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/Path last-modified time.- 指定者:
lastModified在接口中Resource- 覆盖:
lastModified在类中AbstractResource- 抛出:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)- 另请参阅:
-
createRelative
从接口复制的说明:ResourceCreate a resource relative to this resource.- 指定者:
createRelative在接口中Resource- 覆盖:
createRelative在类中AbstractResource- 参数:
relativePath- the relative path (relative to this resource)- 返回:
- the resource handle for the relative resource
- 抛出:
IOException- if the relative resource cannot be determined
-
list
从接口复制的说明:ResourcelistResourceunder the directory- 指定者:
list在接口中Resource- 覆盖:
list在类中AbstractResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
list
从接口复制的说明:ResourcelistResourceunder the directory- 指定者:
list在接口中Resource- 覆盖:
list在类中AbstractResource- 参数:
filter- filterResource- 返回:
Resourcenames- 抛出:
IOException- if the resource is not available
-
getName
从类复制的说明:AbstractResourceDetermine the filename for this resource — typically the last part of the path — for example,"myfile.txt".Returns
nullif this type of resource does not have a filename.Implementations are encouraged to return the filename unencoded.
- 指定者:
getName在接口中Resource- 覆盖:
getName在类中AbstractResource
-
readableChannel
This implementation opens a FileChannel for 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 a FileChannel for 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- 另请参阅:
-
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). -
equals
- 覆盖:
equals在类中AbstractResource
-
hashCode
public int hashCode()- 覆盖:
hashCode在类中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- 另请参阅:
-