All Downloads are FREE. Search and download functionalities are using the official Maven repository.

liquibase.sdk.resource.MockResourceAccessor Maven / Gradle / Ivy

There is a newer version: 3.6.2.5.inovus
Show newest version
package liquibase.sdk.resource;

import liquibase.configuration.GlobalConfiguration;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.resource.ResourceAccessor;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class MockResourceAccessor implements ResourceAccessor {

    private Map contentByFileName;

    public MockResourceAccessor() {
        this(new HashMap());
    }

    public MockResourceAccessor(Map contentByFileName) {
        this.contentByFileName = contentByFileName;
    }

    @Override
    public Set getResourcesAsStream(String path) throws IOException {
        InputStream stream = null;
        if (contentByFileName.containsKey(path)) {
            stream = new ByteArrayInputStream(contentByFileName.get(path).getBytes(LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).getOutputEncoding()));
        }
        if (stream == null) {
            return null;
        } else {
            return new HashSet<>(Arrays.asList(stream));
        }
    }

    @Override
    public Set list(String relativeTo, String path, boolean includeFiles, boolean includeDirectories, boolean recursive) throws IOException {
        Set returnSet = new HashSet<>();
        for (String file : contentByFileName.keySet()) {
            if (file.startsWith(path)) {
                returnSet.add(file);
            }
        }
        return returnSet;
    }

    public ClassLoader toClassLoader() {
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy