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)protectedClassPathResource(String path, ClassLoader classLoader, Class<?> clazz)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopyDirectory(File destination)Extract the directory recursively to the specified location.ResourcecreateRelative(String relativePath)booleanequals(Object obj)booleanexists()Whether the resource exists on the classpathClassLoadergetClassLoader()StringgetDescription()FilegetFile()Get the File.StringgetFilename()InputStreamgetInputStream()StringgetPath()FilegetTempFileFromArchive()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.FilegetTempFileFromArchive(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[]).URLgetURL()inthashCode()-
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:
getFilein interfaceResource- Overrides:
getFilein 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:ResourceWhether the resource exists on the classpath- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractFileResolvingResource- Returns:
-
getInputStream
public InputStream getInputStream() throws IOException
- Throws:
IOException
-
getURL
public URL getURL() throws IOException
- Specified by:
getURLin interfaceResource- Overrides:
getURLin classAbstractResource- Returns:
- Throws:
IOException
-
createRelative
public Resource createRelative(String relativePath)
- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classAbstractResource- Returns:
-
getFilename
public String getFilename()
- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource- Returns:
-
getDescription
public String getDescription()
- Returns:
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classAbstractResource
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractResource
-
-