public interface ResourceAccessor extends AutoCloseable
ClassLoader
but for finding and reading files, not finding and loading classes.Modifier and Type | Interface and Description |
---|---|
static class |
ResourceAccessor.NotFoundResource |
Modifier and Type | Method and Description |
---|---|
List<String> |
describeLocations()
Returns a description of the places this classloader will look for paths.
|
default Resource |
get(String path)
Finds a single specific .
|
List<Resource> |
getAll(String path)
Returns all
Resource s at the given path. |
default Resource |
getExisting(String path)
Convenience version of
get(String) which throws an exception if the file does not exist. |
default SortedSet<String> |
list(String relativeTo,
String path,
boolean recursive,
boolean includeFiles,
boolean includeDirectories)
Deprecated.
|
default InputStream |
openStream(String relativeTo,
String streamPath)
Deprecated.
|
default InputStreamList |
openStreams(String relativeTo,
String streamPath)
Deprecated.
|
List<Resource> |
search(String path,
boolean recursive)
Returns the path to all resources contained in the given path.
|
close
@Deprecated default InputStreamList openStreams(String relativeTo, String streamPath) throws IOException
search(String, boolean)
or getAll(String)
InputStreamList
since multiple resources can map to the same path, such as "META-INF/MAINFEST.MF".
Remember to close streams when finished with them.relativeTo
- Location that streamPath should be found relative to. If null, streamPath is an absolute pathIOException
- if there is an error reading an existing path.@Deprecated default InputStream openStream(String relativeTo, String streamPath) throws IOException
search(String, boolean)
or getAll(String)
openStreams(String, String)
for details about path options.
Implementations should respect GlobalConfiguration.DUPLICATE_FILE_MODE
relativeTo
- Location that streamPath should be found relative to. If null, streamPath is an absolute pathIOException
- if multiple paths matched the streamIOException
- if there is an error reading an existing path@Deprecated default SortedSet<String> list(String relativeTo, String path, boolean recursive, boolean includeFiles, boolean includeDirectories) throws IOException
search(String, boolean)
openStreams(String, String)
and return the contents.
Returned paths should normally be root-relative and therefore not be an absolute path, unless there is a good reason to be absolute.
Default implementation calls search(String, boolean)
and collects the paths from the resources.
Because the new method no longer supports listing directories, it will silently ignore the includeDirectories argument UNLESS includeFiles is false. In that case, it will throw an exception.
relativeTo
- Location that streamPath should be found relative to. If null, path is an absolute pathpath
- The path to lookup resources in.recursive
- Set to true and will return paths to contents in sub directories as well.includeFiles
- Set to true and will return paths to files.includeDirectories
- Set to true and will return paths to directories.IOException
- if there is an error reading an existing root.List<Resource> search(String path, boolean recursive) throws IOException
path
- The path to lookup resources in.recursive
- Set to true and will return paths to contents in subdirectories as well.IOException
- if there is an error searching the system.List<Resource> getAll(String path) throws IOException
Resource
s at the given path.
For many resource accessors (such as a file system), only one resource can exist at a given spot,
but some accessors (such as CompositeResourceAccessor
or ClassLoaderResourceAccessor
) can have multiple resources for a single path.
If the resourceAccessor returns multiple values, the returned List should be considered sorted for that resource accessor.
For example, ClassLoaderResourceAccessor
returns them in order based on the configured classloader.
Order is important to pay attention to, because users may set GlobalConfiguration.DUPLICATE_FILE_MODE
to pick the "best" file which is defined as
"the first file from this function".
IOException
- if there is an unexpected error determining what is at the pathdefault Resource getExisting(String path) throws IOException
get(String)
which throws an exception if the file does not exist.FileNotFoundException
- if the file does not existIOException
default Resource get(String path) throws IOException
GlobalConfiguration.DUPLICATE_FILE_MODE
setting.
Default implementation calls getAll(String)
.IOException
Copyright © 2023 Liquibase.org. All rights reserved.