Top Description Inners Methods
liquibase.resource

public Interface ResourceAccessor

extends AutoCloseable
Known Direct Implementers
liquibase.resource.AbstractResourceAccessor, liquibase.resource.PathHandlerFactory.FoundResourceAccessor
Imports
liquibase.GlobalConfiguration, .Scope, liquibase.exception.UnexpectedLiquibaseException, liquibase.logging.Logger, liquibase.util.CollectionUtil, .FileUtil, java.io.FileNotFoundException, .IOException, .InputStream, .OutputStream, java.net.URI, java.util.*

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 a ClassLoader but for finding and reading files, not finding and loading classes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class

Method Summary

Modifier and TypeMethod and Description
public List<String>
describeLocations()

Returns a description of the places this classloader will look for paths.

public default Resource

Returns:

a Resource even if the path does not exist
get
(String path)

Finds a single specific .

public List<Resource>

Returns:

null if no resources match the path
getAll
(String path)

Returns all Resources at the given path.

public default Resource
getExisting(String path)

Convenience version of get(String) which throws an exception if the file does not exist.

public default SortedSet<String>

Returns:

empty set if nothing was found
list
(String
Location that streamPath should be found relative to. If null, path is an absolute path
relativeTo
,
String
The path to lookup resources in.
path
,
boolean
Set to true and will return paths to contents in sub directories as well.
recursive
,
boolean
Set to true and will return paths to files.
includeFiles
,
boolean
Set to true and will return paths to directories.
includeDirectories
)
Deprecated use search(String, boolean)

Returns the path to all resources contained in the given path.

public default InputStream

Returns:

null if the resource does not exist
openStream
(String
Location that streamPath should be found relative to. If null, streamPath is an absolute path
relativeTo
,
String streamPath)

Returns a single stream matching the given path.

public default InputStreamList

Returns:

Empty list if the resource does not exist.
openStreams
(String
Location that streamPath should be found relative to. If null, streamPath is an absolute path
relativeTo
,
String streamPath)

Return the streams for each resource mapped by the given path.

public default List<Resource>

Returns:

empty set if nothing was found
search
(String
The path to lookup resources in.
path
,
ResourceAccessor.SearchOptions
A set of criteria for how resources should be found/filtered
searchOptions
)

Returns the path to all resources contained in the given path that match the searchOptions criteria.

public List<Resource>

Returns:

empty set if nothing was found
search
(String
The path to lookup resources in.
path
,
boolean
Set to true and will return paths to contents in subdirectories as well.
recursive
)

Returns the path to all resources contained in the given path.

Inherited from java.lang.AutoCloseable:
close

Method Detail

describeLocationsback to summary
public List<String> describeLocations()

Returns a description of the places this classloader will look for paths. Used in error messages and other troubleshooting cases.

getback to summary
public default Resource get(String path) throws IOException

Finds a single specific . If multiple files match the given path, handle based on the GlobalConfiguration#DUPLICATE_FILE_MODE setting. Default implementation calls getAll(String).

Returns:Resource

a Resource even if the path does not exist

getAllback to summary
public List<Resource> getAll(String path) throws IOException

Returns all Resources 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".

Returns:List<Resource>

null if no resources match the path

Exceptions
IOException:
if there is an unexpected error determining what is at the path
getExistingback to summary
public default Resource getExisting(String path) throws IOException

Convenience version of get(String) which throws an exception if the file does not exist.

Exceptions
FileNotFoundException:
if the file does not exist
listback to summary
public default SortedSet<String> list(String relativeTo, String path, boolean recursive, boolean includeFiles, boolean includeDirectories) throws IOException

Deprecated

use search(String, boolean)

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 into 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.

Parameters
relativeTo:String

Location that streamPath should be found relative to. If null, path is an absolute path

path:String

The path to lookup resources in.

recursive:boolean

Set to true and will return paths to contents in sub directories as well.

includeFiles:boolean

Set to true and will return paths to files.

includeDirectories:boolean

Set to true and will return paths to directories.

Returns:SortedSet<String>

empty set if nothing was found

Annotations
@Deprecated
Exceptions
IOException:
if there is an error reading an existing root.
openStreamback to summary
public default InputStream openStream(String relativeTo, String streamPath) throws IOException

Returns a single stream matching the given path. See openStreams(String, String) for details about path options. Implementations should respect liquibase.GlobalConfiguration#DUPLICATE_FILE_MODE

Parameters
relativeTo:String

Location that streamPath should be found relative to. If null, streamPath is an absolute path

Returns:InputStream

null if the resource does not exist

Annotations
@Deprecated
Exceptions
IOException:
  • if multiple paths matched the stream
  • if there is an error reading an existing path
openStreamsback to summary
public default InputStreamList openStreams(String relativeTo, String streamPath) throws IOException

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. Returns InputStreamList 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:String

Location that streamPath should be found relative to. If null, streamPath is an absolute path

Returns:InputStreamList

Empty list if the resource does not exist.

Annotations
@SuppressWarnings:java:S2095
@Deprecated
Exceptions
IOException:
if there is an error reading an existing path.
searchback to summary
public 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
Should throw an exception if:
  • Path is null
  • Path is not a "directory"
  • Path exists but cannot be read from
Parameters
path:String

The path to lookup resources in.

searchOptions:ResourceAccessor.SearchOptions

A set of criteria for how resources should be found/filtered

Returns:List<Resource>

empty set if nothing was found

Exceptions
IOException:
if there is an error searching the system.
searchback to summary
public 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
Should throw an exception if:
  • Path is null
  • Path is not a "directory"
  • Path exists but cannot be read from
Parameters
path:String

The path to lookup resources in.

recursive:boolean

Set to true and will return paths to contents in subdirectories as well.

Returns:List<Resource>

empty set if nothing was found

Exceptions
IOException:
if there is an error searching the system.
liquibase.resource back to summary

public Class ResourceAccessor.NotFoundResource

extends AbstractResource
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ResourceAccessor

Constructor Summary

AccessConstructor and Description
public
NotFoundResource(String path, ResourceAccessor resourceAccessor)

Method Summary

Modifier and TypeMethod and Description
public boolean
public boolean
isWritable()

Overrides liquibase.resource.AbstractResource.isWritable.

Implements liquibase.resource.Resource.isWritable.

Return true if the resource can be written to

public InputStream
openInputStream()

Implements liquibase.resource.Resource.openInputStream.

Opens an input stream to read from this resource.

public OutputStream
public Resource
resolve(String other)

Implements liquibase.resource.Resource.resolve.

Resolve the given path against this resource.

public Resource
resolveSibling(String other)

Implements liquibase.resource.Resource.resolveSibling.

Resolves the given path against this resource's parent path.

Inherited from liquibase.resource.AbstractResource:
equalsgetPathgetUrihashCoderesolvePathresolveSiblingPathtoString

Field Detail

resourceAccessorback to summary
private final ResourceAccessor resourceAccessor

Constructor Detail

NotFoundResourceback to summary
public NotFoundResource(String path, ResourceAccessor resourceAccessor)

Method Detail

existsback to summary
public boolean exists()

Implements liquibase.resource.Resource.exists.

Returns:boolean

Doc from liquibase.resource.Resource.exists.

true if the resource defined by this object currently exists.

Annotations
@Override
isWritableback to summary
public boolean isWritable()

Overrides liquibase.resource.AbstractResource.isWritable.

Implements liquibase.resource.Resource.isWritable.

Doc from liquibase.resource.Resource.isWritable.

Return true if the resource can be written to

Annotations
@Override
openInputStreamback to summary
public InputStream openInputStream() throws IOException

Implements liquibase.resource.Resource.openInputStream.

Doc from liquibase.resource.Resource.openInputStream.

Opens an input stream to read from this resource.

Annotations
@Override
Exceptions
IOException:
if there is an error reading from the resource, including if the resource does not exist or cannot be read.
openOutputStreamback to summary
public OutputStream openOutputStream(OpenOptions openOptions) throws IOException

Overrides liquibase.resource.AbstractResource.openOutputStream.

Implements liquibase.resource.Resource.openOutputStream.

Doc from liquibase.resource.Resource.openOutputStream.

Opens an output stream given the passed OpenOptions. Cannot pass a null OpenOptions value

Annotations
@Override
resolveback to summary
public Resource resolve(String other)

Implements liquibase.resource.Resource.resolve.

Doc from liquibase.resource.Resource.resolve.

Resolve the given path against this resource. If other is an empty path then this method trivially returns this path. Otherwise this method considers this resource to be a directory and resolves the given path against this resource. Even if "other" begins with a `/`, the returned resource should be relative to this resource.

Annotations
@Override
resolveSiblingback to summary
public Resource resolveSibling(String other)

Implements liquibase.resource.Resource.resolveSibling.

Doc from liquibase.resource.Resource.resolveSibling.

Resolves the given path against this resource's parent path. This is useful where a file name needs to be replaced with another file name. For example, suppose that the name separator is "/" and a path represents "dir1/dir2/foo", then invoking this method with the Path "bar" will result in the Path "dir1/dir2/bar". If other is an empty path then this method returns this path's parent. Even if "other" begins with a `/`, the returned resource should be relative to this resource.

Annotations
@Override
liquibase.resource back to summary

public Class ResourceAccessor.SearchOptions

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private String
private int
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public String
public int
public int
public boolean
public void
setMaxDepth(int maxDepth)

public void
setMinDepth(int minDepth)

public void
setRecursive(boolean recursive)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

endsWithFilterback to summary
private String endsWithFilter
maxDepthback to summary
private int maxDepth
minDepthback to summary
private int minDepth

Constructor Detail

SearchOptionsback to summary
public SearchOptions()

Method Detail

endsWithFilterIsSetback to summary
public boolean endsWithFilterIsSet()
getEndsWithFilterback to summary
public String getEndsWithFilter()
getMaxDepthback to summary
public int getMaxDepth()
getMinDepthback to summary
public int getMinDepth()
getRecursiveback to summary
public boolean getRecursive()
setMaxDepthback to summary
public void setMaxDepth(int maxDepth)
setMinDepthback to summary
public void setMinDepth(int minDepth)
setRecursiveback to summary
public void setRecursive(boolean recursive)
setTrimmedEndsWithFilterback to summary
public void setTrimmedEndsWithFilter(String endsWithFilter)