Package liquibase.resource
Interface ResourceAccessor
-
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractPathResourceAccessor
,AbstractResourceAccessor
,AntResourceAccessor
,ClassLoaderResourceAccessor
,CompositeResourceAccessor
,DirectoryResourceAccessor
,FileSystemResourceAccessor
,MavenResourceAccessor
,MockResourceAccessor
,OSGiResourceAccessor
,SearchPathResourceAccessor
,SpringResourceAccessor
,ZipResourceAccessor
public interface ResourceAccessor extends AutoCloseable
ResourceAccessors abstract file access so they can be read in a variety of environments. Implementations may look for local files in known locations, read from the network, or do whatever else they need to find files. Think of ResourceAccessors as aClassLoader
but for finding and reading files, not finding and loading classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ResourceAccessor.NotFoundResource
static class
ResourceAccessor.SearchOptions
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method 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 allResource
s at the given path.default Resource
getExisting(String path)
Convenience version ofget(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.default List<Resource>
search(String path, ResourceAccessor.SearchOptions searchOptions)
Returns the path to all resources contained in the given path that match the searchOptions criteria.-
Methods inherited from interface java.lang.AutoCloseable
close
-
-
-
-
Method Detail
-
openStreams
@Deprecated default InputStreamList openStreams(String relativeTo, String streamPath) throws IOException
Deprecated.Return the streams for each resource mapped by the given path. The path is often a URL but does not have to be. Should accept both / and \ chars for file paths to be platform-independent. If path points to a compressed resource, return a stream of the uncompressed contents of the file. ReturnsInputStreamList
since multiple resources can map to the same path, such as "META-INF/MAINFEST.MF". Remember to close streams when finished with them.- Parameters:
relativeTo
- Location that streamPath should be found relative to. If null, streamPath is an absolute path- Returns:
- Empty list if the resource does not exist.
- Throws:
IOException
- if there is an error reading an existing path.
-
openStream
@Deprecated default InputStream openStream(String relativeTo, String streamPath) throws IOException
Deprecated.Returns a single stream matching the given path. SeeopenStreams(String, String)
for details about path options. Implementations should respectGlobalConfiguration.DUPLICATE_FILE_MODE
- Parameters:
relativeTo
- Location that streamPath should be found relative to. If null, streamPath is an absolute path- Returns:
- null if the resource does not exist
- Throws:
IOException
- if multiple paths matched the streamIOException
- if there is an error reading an existing path
-
list
@Deprecated default SortedSet<String> list(String relativeTo, String path, boolean recursive, boolean includeFiles, boolean includeDirectories) throws IOException
Deprecated.Returns the path to all resources contained in the given path. The passed path is not included in the returned set. Returned strings should use "/" for file path separators, regardless of the OS and should accept both / and \ chars for file paths to be platform-independent. Returned set is sorted, normally alphabetically but subclasses can use different comparators. The values returned should be able to be passed intoopenStreams(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.- Parameters:
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.- Returns:
- empty set if nothing was found
- Throws:
IOException
- if there is an error reading an existing root.
-
search
default List<Resource> search(String path, ResourceAccessor.SearchOptions searchOptions) throws IOException
Returns the path to all resources contained in the given path that match the searchOptions criteria. Multiple resources may be returned with the same path, but only if they are actually unique files. Order is important to pay attention to, they should be returned in a user-expected manner based on this resource accessor.
Should return an empty list if:- Path does not exist or maxDepth less or equals than zero
- Path is null
- Path is not a "directory"
- Path exists but cannot be read from
- Parameters:
path
- The path to lookup resources in.searchOptions
- A set of criteria for how resources should be found/filtered- Returns:
- empty set if nothing was found
- Throws:
IOException
- if there is an error searching the system.
-
search
List<Resource> search(String path, boolean recursive) throws IOException
Returns the path to all resources contained in the given path. Multiple resources may be returned with the same path, but only if they are actually unique files. Order is important to pay attention to, they should be returned in a user-expected manner based on this resource accessor.
Should return an empty list if:- Path does not exist
- Path is null
- Path is not a "directory"
- Path exists but cannot be read from
- Parameters:
path
- The path to lookup resources in.recursive
- Set to true and will return paths to contents in subdirectories as well.- Returns:
- empty set if nothing was found
- Throws:
IOException
- if there is an error searching the system.
-
getAll
List<Resource> getAll(String path) throws IOException
Returns allResource
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 asCompositeResourceAccessor
orClassLoaderResourceAccessor
) 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 setGlobalConfiguration.DUPLICATE_FILE_MODE
to pick the "best" file which is defined as "the first file from this function".- Returns:
- null if no resources match the path
- Throws:
IOException
- if there is an unexpected error determining what is at the path
-
getExisting
default Resource getExisting(String path) throws IOException
Convenience version ofget(String)
which throws an exception if the file does not exist.- Throws:
FileNotFoundException
- if the file does not existIOException
-
get
default Resource get(String path) throws IOException
Finds a single specific . If multiple files match the given path, handle based on theGlobalConfiguration.DUPLICATE_FILE_MODE
setting. Default implementation callsgetAll(String)
.- Returns:
- a Resource even if the path does not exist
- Throws:
IOException
-
-