Package org.nd4j.common.io
Class ClassPathResource
- java.lang.Object
-
- org.nd4j.common.io.AbstractResource
-
- org.nd4j.common.io.AbstractFileResolvingResource
-
- org.nd4j.common.io.ClassPathResource
-
- All Implemented Interfaces:
InputStreamSource
,Resource
public class ClassPathResource extends AbstractFileResolvingResource
-
-
Constructor Summary
Constructors Modifier Constructor Description ClassPathResource(String path)
ClassPathResource(String path, Class<?> clazz)
ClassPathResource(String path, ClassLoader classLoader)
protected
ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copyDirectory(File destination)
Extract the directory recursively to the specified location.Resource
createRelative(String relativePath)
boolean
equals(Object obj)
boolean
exists()
Whether the resource exists on the classpathClassLoader
getClassLoader()
String
getDescription()
File
getFile()
Get the File.String
getFilename()
InputStream
getInputStream()
String
getPath()
File
getTempFileFromArchive()
Get a temp file from the classpath.
This is for resources where a file is needed and the classpath resource is in a jar file.File
getTempFileFromArchive(File rootDirectory)
Get a temp file from the classpath, and (optionally) place it in the specified directory
Note that:
- If the directory is not specified, the file is copied to the default temporary directory, usingFiles.createTempFile(String, String, FileAttribute[])
.URL
getURL()
int
hashCode()
-
Methods inherited from class org.nd4j.common.io.AbstractFileResolvingResource
contentLength, getFile, getFileForLastModifiedCheck, isReadable, lastModified
-
Methods inherited from class org.nd4j.common.io.AbstractResource
getURI, isOpen, toString
-
-
-
-
Constructor Detail
-
ClassPathResource
public ClassPathResource(String path)
-
ClassPathResource
public ClassPathResource(String path, ClassLoader classLoader)
-
ClassPathResource
protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz)
-
-
Method Detail
-
getPath
public final String getPath()
-
getClassLoader
public final ClassLoader getClassLoader()
-
getFile
public File getFile() throws IOException
Get the File. If the file cannot be accessed directly (for example, it is in a JAR file), we will attempt to extract it from the JAR and copy it to the temporary directory, usinggetTempFileFromArchive()
- Specified by:
getFile
in interfaceResource
- Overrides:
getFile
in classAbstractFileResolvingResource
- Returns:
- The File, or a temporary copy if it can not be accessed directly
- Throws:
IOException
-
getTempFileFromArchive
public File getTempFileFromArchive() throws IOException
Get a temp file from the classpath.
This is for resources where a file is needed and the classpath resource is in a jar file. The file is copied to the default temporary directory, usingFiles.createTempFile(String, String, FileAttribute[])
. Consequently, the extracted file will have a different filename to the extracted one.- Returns:
- the temp file
- Throws:
IOException
- If an error occurs when files are being copied- See Also:
getTempFileFromArchive(File)
-
getTempFileFromArchive
public File getTempFileFromArchive(File rootDirectory) throws IOException
Get a temp file from the classpath, and (optionally) place it in the specified directory
Note that:
- If the directory is not specified, the file is copied to the default temporary directory, usingFiles.createTempFile(String, String, FileAttribute[])
. Consequently, the extracted file will have a different filename to the extracted one.
- If the directory *is* specified, the file is copied directly - and the original filename is maintained- Parameters:
rootDirectory
- May be null. If non-null, copy to the specified directory- Returns:
- the temp file
- Throws:
IOException
- If an error occurs when files are being copied- See Also:
getTempFileFromArchive(File)
-
copyDirectory
public void copyDirectory(File destination) throws IOException
Extract the directory recursively to the specified location. Current ClassPathResource must point to a directory.
For example, if classpathresource points to "some/dir/", then the contents - not including the parent directory "dir" - will be extracted or copied to the specified destination.- Parameters:
destination
- Destination directory. Must exist- Throws:
IOException
-
exists
public boolean exists()
Description copied from interface:Resource
Whether the resource exists on the classpath- Specified by:
exists
in interfaceResource
- Overrides:
exists
in classAbstractFileResolvingResource
- Returns:
-
getInputStream
public InputStream getInputStream() throws IOException
- Throws:
IOException
-
getURL
public URL getURL() throws IOException
- Specified by:
getURL
in interfaceResource
- Overrides:
getURL
in classAbstractResource
- Returns:
- Throws:
IOException
-
createRelative
public Resource createRelative(String relativePath)
- Specified by:
createRelative
in interfaceResource
- Overrides:
createRelative
in classAbstractResource
- Returns:
-
getFilename
public String getFilename()
- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
- Returns:
-
getDescription
public String getDescription()
- Returns:
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classAbstractResource
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractResource
-
-