Package com.gengoai.io
Class Resources
- java.lang.Object
-
- com.gengoai.io.Resources
-
public final class Resources extends Object
Convenience methods for constructingResource
s- Author:
- David B. Bracewell
-
-
Constructor Summary
Constructors Constructor Description Resources()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Iterator<Resource>
findAllClasspathResources(String pattern)
Finds all resources with the given pattern across loaded ClassLoadersstatic Resource
from(String resource)
Constructs a resource from a string representation.static Resource
fromClasspath(String resource)
Creases a newClasspathResource
.static Resource
fromFile(File resource)
Creases a newFileResource
.static Resource
fromFile(String resource)
Creases a newFileResource
.static Resource
fromInputStream(InputStream inputStream)
From input stream resource.static Resource
fromOutputStream(OutputStream outputStream)
From output stream resource.static Resource
fromReader(Reader reader)
Creates a new Resource that wraps the given readerstatic Resource
fromStdin()
From stdin resource.static Resource
fromStdout()
From stdout resource.static Resource
fromString()
Creates aStringResource
that is empty.static Resource
fromString(String stringResource)
Creates aStringResource
from the given string.static URIResource
fromURI(String resource)
Creates a newURIResource
.static URIResource
fromURI(URI resource)
Creates a newURIResource
.static URLResource
fromUrl(URL resource)
Creates a newURLResource
.static Resource
fromWriter(Writer writer)
Creates a new Resource that wraps the given writerstatic Resource
getJar(@NonNull Class<?> clazz)
Gets the jar file that a class is stored in.static Resource
temporaryDirectory()
Creates a new Resource that points to a temporary directory.static Resource
temporaryFile()
Creates a new Resource that points to a temporary file.static Resource
temporaryFile(String name, String extension)
Creates a resource wrapping a temporary filestatic Resource
writeObject(Object o)
-
-
-
Method Detail
-
findAllClasspathResources
public static Iterator<Resource> findAllClasspathResources(String pattern)
Finds all resources with the given pattern across loaded ClassLoaders- Parameters:
pattern
- the file pattern- Returns:
- Iterator of resources
-
from
public static Resource from(String resource)
Constructs a resource from a string representation. Defaults to a file based resource if no schema is present.- Parameters:
resource
- The string representation of the resource- Returns:
- A resource representing the string representation
-
fromClasspath
public static Resource fromClasspath(String resource)
Creases a new
ClasspathResource
.- Parameters:
resource
- The classpath making up the resource- Returns:
- A new Resource associated with the classpath
-
fromFile
public static Resource fromFile(File resource)
Creases a new
FileResource
.- Parameters:
resource
- The file making up the resource- Returns:
- A new Resource associated with the file
-
fromFile
public static Resource fromFile(String resource)
Creases a new
FileResource
.- Parameters:
resource
- The file making up the resource- Returns:
- A new Resource associated with the file
-
fromInputStream
public static Resource fromInputStream(InputStream inputStream)
From input stream resource.- Parameters:
inputStream
- The input stream to wrap- Returns:
- Resource that can read from given input stream
-
fromOutputStream
public static Resource fromOutputStream(OutputStream outputStream)
From output stream resource.- Parameters:
outputStream
- The output stream to wrap- Returns:
- Resource that can write to given output stream
-
fromReader
public static Resource fromReader(Reader reader)
Creates a new Resource that wraps the given reader- Parameters:
reader
- The reader to wrap- Returns:
- Resource that can read from given reader
-
fromStdin
public static Resource fromStdin()
From stdin resource.- Returns:
- Resource that can read from standard in
-
fromStdout
public static Resource fromStdout()
From stdout resource.- Returns:
- Resource that can output to standard out
-
fromString
public static Resource fromString(String stringResource)
Creates aStringResource
from the given string.- Parameters:
stringResource
- the string resource- Returns:
- the resource
-
fromString
public static Resource fromString()
Creates aStringResource
that is empty.- Returns:
- the resource
-
fromURI
public static URIResource fromURI(URI resource)
Creates a new
URIResource
.- Parameters:
resource
- The uri to wrap.- Returns:
- A new Resource wrapping a uri.
-
fromURI
public static URIResource fromURI(String resource)
Creates a new
URIResource
.- Parameters:
resource
- The uri to wrap.- Returns:
- A new Resource wrapping a uri.
-
fromUrl
public static URLResource fromUrl(URL resource)
Creates a new
URLResource
.- Parameters:
resource
- The url to wrap.- Returns:
- A new Resource wrapping a url.
-
fromWriter
public static Resource fromWriter(Writer writer)
Creates a new Resource that wraps the given writer- Parameters:
writer
- the writer wrap- Returns:
- the resource
-
getJar
public static Resource getJar(@NonNull @NonNull Class<?> clazz)
Gets the jar file that a class is stored in.- Parameters:
clazz
- The class whose associated jar file is descried.- Returns:
- The Resource (jar file) for the class
-
temporaryDirectory
public static Resource temporaryDirectory()
Creates a new Resource that points to a temporary directory.- Returns:
- A resource which is a temporary directory on disk
-
temporaryFile
public static Resource temporaryFile()
Creates a new Resource that points to a temporary file.- Returns:
- A resource which is a temporary file on disk
-
temporaryFile
public static Resource temporaryFile(String name, String extension) throws IOException
Creates a resource wrapping a temporary file- Parameters:
name
- The file nameextension
- The file extension- Returns:
- The resource representing the temporary file
- Throws:
IOException
- the io exception
-
writeObject
public static Resource writeObject(Object o) throws IOException
- Throws:
IOException
-
-