public class ClassPathResource extends AbstractFileResolvingResource
Resource
実装。リソースのロードに、指定された ClassLoader
または指定された Class
のいずれかを使用します。 クラスパスリソースがファイルシステムにある場合は java.io.File
として解決をサポートしますが、JAR 内のリソースはサポートしません。常に URL としての解決をサポートします。
ClassLoader.getResourceAsStream(String)
, Class.getResourceAsStream(String)
修飾子 | コンストラクターと説明 |
---|---|
| ClassPathResource(java.lang.String path) ClassLoader 用の新しい ClassPathResource を作成します。 |
| ClassPathResource(java.lang.String path, java.lang.Class<?> clazz) Class 用の新しい ClassPathResource を作成します。 |
| ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader) ClassLoader 用の新しい ClassPathResource を作成します。 |
protected | ClassPathResource(java.lang.String path, java.lang.ClassLoader classLoader, java.lang.Class<?> clazz) 使用すべきではありません。 4.3.13 の時点で、 ClassPathResource(String, ClassLoader) と ClassPathResource(String, Class) の選択的使用を推奨 |
修飾子と型 | メソッドと説明 |
---|---|
Resource | createRelative(java.lang.String relativePath) この実装は ClassPathResource を作成し、この記述子の基礎となるリソースのパスに対して指定されたパスを適用します。 |
boolean | equals(java.lang.Object other) この実装は、基になるクラスパスの場所を比較します。 |
boolean | exists() この実装は、リソース URL の解決をチェックします。 |
java.lang.ClassLoader | getClassLoader() このリソースを取得する ClassLoader を返します。 |
java.lang.String | getDescription() この実装は、クラスパスの場所を含む説明を返します。 |
java.lang.String | getFilename() この実装は、このクラスパスリソースが参照するファイルの名前を返します。 |
java.io.InputStream | getInputStream() この実装は、指定されたクラスパスリソースの InputStream を開きます。 |
java.lang.String | getPath() このリソースのパスを(クラスパス内のリソースパスとして)返します。 |
java.net.URL | getURL() この実装は、利用可能な場合、基になるクラスパスリソースの URL を返します。 |
int | hashCode() この実装は、基になるクラスパスの場所のハッシュコードを返します。 |
protected java.net.URL | resolveURL() 基になるクラスパスリソースの URL を解決します。 |
contentLength, customizeConnection, customizeConnection, getFile, getFile, getFileForLastModifiedCheck, isFile, isFile, isReadable, lastModified, readableChannel
getURI, isOpen, toString
public ClassPathResource(java.lang.String path)
ClassLoader
を使用するための新しい ClassPathResource
を作成します。ClassLoader リソースアクセスメソッドはスラッシュを受け入れないため、先頭のスラッシュは削除されます。リソースのロードには、スレッドコンテキストクラスローダーが使用されます。
path
- クラスパス内の絶対パス ClassLoader.getResourceAsStream(String)
, ClassUtils.getDefaultClassLoader()
public ClassPathResource(java.lang.String path, @Nullable java.lang.ClassLoader classLoader)
ClassLoader
を使用するための新しい ClassPathResource
を作成します。ClassLoader リソースアクセスメソッドはスラッシュを受け入れないため、先頭のスラッシュは削除されます。path
- クラスパス内の絶対パス classLoader
- リソースをロードするクラスローダー、またはスレッドコンテキストクラスローダーの null
ClassLoader.getResourceAsStream(String)
public ClassPathResource(java.lang.String path, @Nullable java.lang.Class<?> clazz)
Class
を使用するための新しい ClassPathResource
を作成します。パスは、特定のクラスへの相対パス、または先頭のスラッシュを介したクラスパス内の絶対パスにすることができます。path
- クラスパス内の相対パスまたは絶対パス clazz
- リソースをロードするクラス Class.getResourceAsStream(java.lang.String)
@Deprecated protected ClassPathResource(java.lang.String path, @Nullable java.lang.ClassLoader classLoader, @Nullable java.lang.Class<?> clazz)
ClassLoader
および Class
を使用して新しい ClassPathResource
を作成します。内部使用のみ。path
- クラスパス内の相対パスまたは絶対パス classLoader
- リソースをロードするクラスローダー(存在する場合)clazz
- リソースをロードするクラス(ある場合)public final java.lang.String getPath()
@Nullable public final java.lang.ClassLoader getClassLoader()
public boolean exists()
Resource
の exists
AbstractFileResolvingResource
の exists
ClassLoader.getResource(String)
, Class.getResource(String)
@Nullable protected java.net.URL resolveURL()
null
public java.io.InputStream getInputStream() throws java.io.IOException
null
であってはなりません)java.io.FileNotFoundException
- 基になるリソースが存在しない場合 java.io.IOException
- コンテンツストリームを開けなかった場合 ClassLoader.getResourceAsStream(String)
, Class.getResourceAsStream(String)
public java.net.URL getURL() throws java.io.IOException
Resource
の getURL
AbstractResource
の getURL
java.io.IOException
- リソースを URL として解決できない場合、つまりリソースが記述子として利用できない場合 ClassLoader.getResource(String)
, Class.getResource(String)
public Resource createRelative(java.lang.String relativePath)
Resource
の createRelative
AbstractResource
の createRelative
relativePath
- 相対パス (このリソースに関連して)StringUtils.applyRelativePath(String, String)
@Nullable public java.lang.String getFilename()
Resource
の getFilename
AbstractResource
の getFilename
StringUtils.getFilename(String)
public java.lang.String getDescription()
Object.toString()
public boolean equals(java.lang.Object other)
AbstractResource
の equals
Resource.getDescription()
public int hashCode()
AbstractResource
の hashCode
Resource.getDescription()