liquibase.resource.FileSystemResourceAccessor Maven / Gradle / Ivy
package liquibase.resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
/**
* A FileOpener implementation which finds Files in the
* File System.
*
* FileSystemFileOpeners can use a BaseDirectory to determine
* where relative paths should be resolved from.
*
* @author getResources(String packageName) throws IOException {
String directoryPath = (new File(packageName).isAbsolute() || baseDirectory == null) ? packageName : baseDirectory + File.separator + packageName;
File directoryFile = new File(directoryPath);
if (!directoryFile.exists()) {
return new Vector().elements();
}
File[] files = directoryFile.listFiles();
List results = new ArrayList();
for (File f : files) {
if (!f.isDirectory())
results.add(f.toURI().toURL());
}
final Iterator it = results.iterator();
return new Enumeration() {
public boolean hasMoreElements() {
return it.hasNext();
}
public URL nextElement() {
return it.next();
}
};
}
public ClassLoader toClassLoader() {
try {
return new URLClassLoader(new URL[]{new URL("file://" + baseDirectory)});
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
@Override
public String toString() {
String dir = baseDirectory;
if (dir == null) {
dir = new File(".").getAbsolutePath();
}
return getClass().getName()+"("+ dir +")";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy