public class FileSystemResource extends AbstractResource implements WritableResource
java.io.File
および java.nio.file.Path
の Resource
実装は、ファイルシステムターゲットで処理します。File
および URL
としての解決をサポートします。拡張 WritableResource
インターフェースを実装します。 メモ: Spring Framework 5.0 以降、この Resource
実装は、読み取り / 書き込みの対話に NIO.2 API を使用します。5.1 以降では、Path
SE ハンドルを使用して構築できます。この場合、NIO.2 を介してすべてのファイルシステムの対話を実行し、getFile()
上の File
SE にのみ頼ります。
FileSystemResource(String)
, FileSystemResource(File)
, FileSystemResource(Path)
, File
SE, Files
SEコンストラクターと説明 |
---|
FileSystemResource(FileSE file) File SE ハンドルから新しい FileSystemResource を作成します。 |
FileSystemResource(FileSystemSE fileSystem, StringSE path) FileSystem SE ハンドルから新しい FileSystemResource を作成し、指定されたパスを見つけます。 |
FileSystemResource(PathSE filePath) |
FileSystemResource(StringSE path) ファイルパスから新しい FileSystemResource を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
long | contentLength() この実装は、基になるファイル / パスの長さを返します。 |
Resource | createRelative(StringSE relativePath) この実装は FileSystemResource を作成し、このリソース記述子の元となるファイルのパスに対して指定されたパスを適用します。 |
boolean | equals(ObjectSE other) この実装は、元となるファイル参照を比較します。 |
boolean | exists() この実装は、元となるファイルが存在するかどうかを返します。 |
StringSE | getDescription() この実装は、ファイルの絶対パスを含む説明を返します。 |
FileSE | getFile() この実装は、元となるファイル参照を返します。 |
StringSE | getFilename() この実装は、ファイルの名前を返します。 |
InputStreamSE | getInputStream() この実装は、元となるファイルの NIO ファイルストリームを開きます。 |
OutputStreamSE | getOutputStream() この実装は、基になるファイルの FileOutputStream を開きます。 |
StringSE | getPath() このリソースのファイルパスを返します。 |
URISE | getURI() この実装は、元となるファイルの URI を返します。 |
URLSE | getURL() この実装は、元となるファイルの URL を返します。 |
int | hashCode() この実装は、元となるファイル参照のハッシュコードを返します。 |
boolean | isFile() この実装は常にファイルを示します。 |
boolean | isReadable() この実装は、元となるファイルが読み取り可能としてマークされているかどうかを確認します(ディレクトリではなく、コンテンツを含む実際のファイルに対応します)。 |
boolean | isWritable() この実装は、元となるファイルが書き込み可能としてマークされているかどうかを確認します(また、ディレクトリではなくコンテンツを含む実際のファイルに対応します)。 |
long | lastModified() この実装は、基になるファイル / パスの最終変更時刻を返します。 |
ReadableByteChannelSE | readableChannel() この実装は、基になるファイルの FileChannel を開きます。 |
WritableByteChannelSE | writableChannel() この実装は、基になるファイルの FileChannel を開きます。 |
getFileForLastModifiedCheck, isOpen, toString
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public FileSystemResource(StringSE path)
FileSystemResource
を作成します。 メモ: createRelative(java.lang.String)
を介して相対リソースを構築する場合、ここで指定されたリソースベースパスがスラッシュで終わるかどうかが異なります。"C:/dir1/"" の場合、相対パスはそのルートに作成されます: たとえば相対パス "dir2"→ "C:/dir1/dir2"." C:/dir1" の場合、相対パスは同じディレクトリレベルで適用されます。: 相対パス "dir2"→ 「C:/dir2"。
path
- ファイルパス FileSystemResource(Path)
public FileSystemResource(FileSE file)
File
SE ハンドルから新しい FileSystemResource
を作成します。 メモ: createRelative(java.lang.String)
を介して相対リソースを構築する場合、相対パスは同じディレクトリレベルで適用されます : たとえば new File("C:/dir1")、相対パス " dir2 "→" C:/dir2"! 指定されたルートディレクトリに相対パスを作成する場合は、constructor with a file path
を使用してルートパスに末尾のスラッシュを追加します: 「C:/dir1/"。これは、このディレクトリをすべての相対パスのルートとして示します。
file
- ファイルハンドル FileSystemResource(Path)
, getFile()
public FileSystemResource(PathSE filePath)
Path
SE ハンドルから新しい FileSystemResource
を作成し、File
SE ではなく NIO.2 を介してすべてのファイルシステムの対話を実行します。PathResource
とは対照的に、このバリアントは、特にパスのクリーニングと createRelative(String)
の処理に関して、一般的な FileSystemResource
の規則に厳密に従います。
メモ: createRelative(java.lang.String)
を介して相対リソースを構築する場合、相対パスは同じディレクトリレベルで適用されます : たとえば Paths.get("C:/dir1")、相対パス " dir2 "→" C:/dir2"! 指定されたルートディレクトリに相対パスを作成する場合は、constructor with a file path
を使用してルートパスに末尾のスラッシュを追加します: 「C:/dir1/"。これは、このディレクトリをすべての相対パスのルートとして示します。または、createRelative
の java.nio.path.Path
解決に PathResource(Path)
を使用し、常に相対パスをネストすることを検討してください。
filePath
- ファイルへのパスハンドル FileSystemResource(File)
public FileSystemResource(FileSystemSE fileSystem, StringSE path)
FileSystem
SE ハンドルから新しい FileSystemResource
を作成し、指定されたパスを見つけます。 これは FileSystemResource(String)
の代替であり、File
SE ではなく NIO.2 を介してすべてのファイルシステムの対話を実行します。
fileSystem
- FileSystem 内でパスを見つける path
- ファイルパス FileSystemResource(File)
public final StringSE getPath()
public boolean exists()
Resource
の exists
AbstractResource
の exists
File.exists()
SEpublic boolean isReadable()
Resource
の isReadable
AbstractResource
の isReadable
File.canRead()
SE, File.isDirectory()
SEpublic InputStreamSE getInputStream() throws IOExceptionSE
InputStreamSource
の getInputStream
null
であってはなりません)FileNotFoundExceptionSE
- 基盤となるリソースが存在しない場合 IOExceptionSE
- コンテンツストリームを開けなかった場合 FileInputStream
SEpublic boolean isWritable()
WritableResource
の isWritable
File.canWrite()
SE, File.isDirectory()
SEpublic OutputStreamSE getOutputStream() throws IOExceptionSE
WritableResource
の getOutputStream
IOExceptionSE
- ストリームを開けなかった場合 FileOutputStream
SEpublic URLSE getURL() throws IOExceptionSE
Resource
の getURL
AbstractResource
の getURL
IOExceptionSE
- リソースを URL として解決できない場合、つまりリソースが記述子として利用できない場合 File.toURI()
SEpublic URISE getURI() throws IOExceptionSE
Resource
の getURI
AbstractResource
の getURI
IOExceptionSE
- リソースが URI として解決できない場合、つまりリソースが記述子として利用できない場合 File.toURI()
SEpublic boolean isFile()
Resource
の isFile
AbstractResource
の isFile
Resource.getFile()
public FileSE getFile()
Resource
の getFile
AbstractResource
の getFile
InputStreamSource.getInputStream()
public ReadableByteChannelSE readableChannel() throws IOExceptionSE
Resource
の readableChannel
AbstractResource
の readableChannel
null
であってはなりません)FileNotFoundExceptionSE
- 基になるリソースが存在しない場合 IOExceptionSE
- コンテンツチャネルを開けなかった場合 FileChannel
SEpublic WritableByteChannelSE writableChannel() throws IOExceptionSE
WritableResource
の writableChannel
null
であってはなりません)FileNotFoundExceptionSE
- 基になるリソースが存在しない場合 IOExceptionSE
- コンテンツチャネルを開けなかった場合 FileChannel
SEpublic long contentLength() throws IOExceptionSE
Resource
の contentLength
AbstractResource
の contentLength
IOExceptionSE
- リソースを解決できない場合 (ファイルシステム内、または他の既知の物理リソース型として)InputStreamSource.getInputStream()
public long lastModified() throws IOExceptionSE
Resource
の lastModified
AbstractResource
の lastModified
IOExceptionSE
- リソースを解決できない場合 (ファイルシステム内、または他の既知の物理リソース型として)AbstractResource.getFileForLastModifiedCheck()
public Resource createRelative(StringSE relativePath)
Resource
の createRelative
AbstractResource
の createRelative
relativePath
- 相対パス (このリソースに関連して)StringUtils.applyRelativePath(String, String)
public StringSE getFilename()
Resource
の getFilename
AbstractResource
の getFilename
File.getName()
SEpublic StringSE getDescription()
Resource
の getDescription
File.getAbsolutePath()
SEpublic boolean equals(@Nullable ObjectSE other)
AbstractResource
の equals
Resource.getDescription()
public int hashCode()
AbstractResource
の hashCode
Resource.getDescription()