liquibase.resource.CompositeResourceAccessor Maven / Gradle / Ivy
package liquibase.resource;
import liquibase.util.CollectionUtil;
import java.io.IOException;
import java.util.*;
/**
* A {@link liquibase.resource.ResourceAccessor} that contains multiple sub-accessors and combines the results of all of them.
*/
public class CompositeResourceAccessor extends AbstractResourceAccessor {
private List resourceAccessors;
public CompositeResourceAccessor(ResourceAccessor... resourceAccessors) {
this.resourceAccessors = Arrays.asList(CollectionUtil.createIfNull(resourceAccessors));
}
public CompositeResourceAccessor(Collection resourceAccessors) {
this.resourceAccessors = new ArrayList<>(resourceAccessors);
}
public CompositeResourceAccessor addResourceAccessor(ResourceAccessor resourceAccessor) {
this.resourceAccessors.add(resourceAccessor);
return this;
}
@Override
@java.lang.SuppressWarnings("squid:S2095")
public InputStreamList openStreams(String relativeTo, String streamPath) throws IOException {
InputStreamList returnList = new InputStreamList();
for (ResourceAccessor accessor : resourceAccessors) {
returnList.addAll(accessor.openStreams(relativeTo, streamPath));
}
return returnList;
}
@Override
public SortedSet list(String relativeTo, String path, boolean recursive, boolean includeFiles, boolean includeDirectories) throws IOException {
SortedSet returnSet = new TreeSet<>();
for (ResourceAccessor accessor : resourceAccessors) {
final SortedSet list = accessor.list(relativeTo, path, recursive, includeFiles, includeDirectories);
if (list != null) {
returnSet.addAll(list);
}
}
return returnSet;
}
@Override
public SortedSet describeLocations() {
SortedSet returnSet = new TreeSet<>();
for (ResourceAccessor accessor : resourceAccessors) {
returnSet.addAll(accessor.describeLocations());
}
return returnSet;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy