public class PathResource extends AbstractResource implements WritableResource
Path
SE ハンドルの Resource
実装。Path
API を介してすべての操作と変換を実行します。File
SE および URL
SE としての解決をサポートします。拡張 WritableResource
インターフェースを実装します。 メモ: 5.1 以降、Path
SE サポートは FileSystemResource
でも利用でき、Spring の標準の文字列ベースのパス変換を適用しますが、Files
SE API を介してすべての操作を実行します。この PathResource
は事実上、createRelative
の動作が異なる純粋な java.nio.path.Path
ベースの代替です。
Path
SE, Files
SE, FileSystemResource
コンストラクターと説明 |
---|
PathResource(PathSE path) パスハンドルから新しい PathResource を作成します。 |
PathResource(StringSE path) パスハンドルから新しい PathResource を作成します。 |
PathResource(URISE uri) パスハンドルから新しい PathResource を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
long | contentLength() この実装は、元となるファイルの長さを返します。 |
Resource | createRelative(StringSE relativePath) この実装は PathResource を作成し、このリソース記述子の元となるファイルのパスに対して指定されたパスを適用します。 |
boolean | equals(ObjectSE other) この実装は、基になるパス参照を比較します。 |
boolean | exists() この実装は、元となるファイルが存在するかどうかを返します。 |
StringSE | getDescription() このリソースの説明を返します。これは、リソースを操作する際のエラー出力に使用されます。 |
FileSE | getFile() この実装は、元となるファイル参照を返します。 |
StringSE | getFilename() この実装は、ファイルの名前を返します。 |
InputStreamSE | getInputStream() この実装は、基になるファイルの InputStream を開きます。 |
OutputStreamSE | getOutputStream() この実装は、基になるファイルの OutputStream を開きます。 |
StringSE | getPath() このリソースのファイルパスを返します。 |
URISE | getURI() この実装は、元となるファイルの URI を返します。 |
URLSE | getURL() この実装は、元となるファイルの URL を返します。 |
int | hashCode() この実装は、基になる Path 参照のハッシュコードを返します。 |
boolean | isFile() この実装は常にファイルを示します。 |
boolean | isReadable() この実装は、元となるファイルが読み取り可能としてマークされているかどうかを確認します(ディレクトリではなく、コンテンツを含む実際のファイルに対応します)。 |
boolean | isWritable() この実装は、元となるファイルが書き込み可能としてマークされているかどうかを確認します(また、ディレクトリではなくコンテンツを含む実際のファイルに対応します)。 |
long | lastModified() この実装は、基になるファイルのタイムスタンプを返します。 |
ReadableByteChannelSE | readableChannel() この実装は、基になるファイルのチャネルを開きます。 |
WritableByteChannelSE | writableChannel() この実装は、基になるファイルのチャネルを開きます。 |
getFileForLastModifiedCheck, isOpen, toString
cloneSE, finalizeSE, getClassSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public PathResource(PathSE path)
メモ: FileSystemResource
とは異なり、createRelative(java.lang.String)
を介して相対リソースを構築する場合、相対パスは指定されたルートの下に構築されます : たとえば Paths.get("C:/dir1/")、相対パス " dir2 "→" C:/dir1/dir2"!
path
- パスハンドル public PathResource(StringSE path)
メモ: FileSystemResource
とは異なり、createRelative(java.lang.String)
を介して相対リソースを構築する場合、相対パスは指定されたルートの下に構築されます : たとえば Paths.get("C:/dir1/")、相対パス " dir2 "→" C:/dir1/dir2"!
path
- 通り Paths.get(String, String...)
SEpublic PathResource(URISE uri)
メモ: FileSystemResource
とは異なり、createRelative(java.lang.String)
を介して相対リソースを構築する場合、相対パスは指定されたルートの下に構築されます : たとえば Paths.get("C:/dir1/")、相対パス " dir2 "→" C:/dir1/dir2"!
uri
- パス URIPaths.get(URI)
SEpublic final StringSE getPath()
public boolean exists()
Resource
の exists
AbstractResource
の exists
Files.exists(Path, java.nio.file.LinkOption...)
SEpublic boolean isReadable()
Resource
の isReadable
AbstractResource
の isReadable
Files.isReadable(Path)
SE, Files.isDirectory(Path, java.nio.file.LinkOption...)
SEpublic InputStreamSE getInputStream() throws IOExceptionSE
InputStreamSource
の getInputStream
null
であってはなりません)FileNotFoundExceptionSE
- 基盤となるリソースが存在しない場合 IOExceptionSE
- コンテンツストリームを開けなかった場合 FileSystemProvider.newInputStream(Path, OpenOption...)
SEpublic boolean isWritable()
WritableResource
の isWritable
Files.isWritable(Path)
SE, Files.isDirectory(Path, java.nio.file.LinkOption...)
SEpublic OutputStreamSE getOutputStream() throws IOExceptionSE
WritableResource
の getOutputStream
IOExceptionSE
- ストリームを開けなかった場合 FileSystemProvider.newOutputStream(Path, OpenOption...)
SEpublic URLSE getURL() throws IOExceptionSE
Resource
の getURL
AbstractResource
の getURL
IOExceptionSE
- リソースを URL として解決できない場合、つまりリソースが記述子として利用できない場合 Path.toUri()
SE, URI.toURL()
SEpublic URISE getURI() throws IOExceptionSE
Resource
の getURI
AbstractResource
の getURI
IOExceptionSE
- リソースが URI として解決できない場合、つまりリソースが記述子として利用できない場合 Path.toUri()
SEpublic boolean isFile()
Resource
の isFile
AbstractResource
の isFile
Resource.getFile()
public FileSE getFile() throws IOExceptionSE
Resource
の getFile
AbstractResource
の getFile
FileNotFoundExceptionSE
- リソースが絶対ファイルパスとして解決できない場合、つまりリソースがファイルシステムで使用できない場合 IOExceptionSE
- 一般的な解決 / 読み取りエラーの場合 InputStreamSource.getInputStream()
public ReadableByteChannelSE readableChannel() throws IOExceptionSE
Resource
の readableChannel
AbstractResource
の readableChannel
null
であってはなりません)FileNotFoundExceptionSE
- 基になるリソースが存在しない場合 IOExceptionSE
- コンテンツチャネルを開けなかった場合 Files.newByteChannel(Path, OpenOption...)
SEpublic WritableByteChannelSE writableChannel() throws IOExceptionSE
WritableResource
の writableChannel
null
であってはなりません)FileNotFoundExceptionSE
- 基になるリソースが存在しない場合 IOExceptionSE
- コンテンツチャネルを開けなかった場合 Files.newByteChannel(Path, OpenOption...)
SEpublic long contentLength() throws IOExceptionSE
Resource
の contentLength
AbstractResource
の contentLength
IOExceptionSE
- リソースを解決できない場合 (ファイルシステム内、または他の既知の物理リソース型として)InputStreamSource.getInputStream()
public long lastModified() throws IOExceptionSE
Resource
の lastModified
AbstractResource
の lastModified
IOExceptionSE
- リソースを解決できない場合 (ファイルシステム内、または他の既知の物理リソース型として)Files.getLastModifiedTime(Path, java.nio.file.LinkOption...)
SEpublic Resource createRelative(StringSE relativePath)
Resource
の createRelative
AbstractResource
の createRelative
relativePath
- 相対パス (このリソースに関連して)Path.resolve(String)
SEpublic StringSE getFilename()
Resource
の getFilename
AbstractResource
の getFilename
Path.getFileName()
SEpublic StringSE getDescription()
Resource
実装では、toString
メソッドからこの値を返すことも推奨されます。
Resource
の getDescription
Object.toString()
SEpublic boolean equals(@Nullable ObjectSE other)
AbstractResource
の equals
Resource.getDescription()
public int hashCode()
AbstractResource
の hashCode
Resource.getDescription()