01: package liquibase.commandline;
02:
03: import liquibase.FileOpener;
04:
05: import java.io.IOException;
06: import java.io.InputStream;
07: import java.net.URL;
08: import java.util.Enumeration;
09:
10: /**
11: * Implementation of liquibase.FileOpener for the command line app.
12: *
13: * @see liquibase.FileOpener
14: */
15: public class CommandLineFileOpener implements FileOpener {
16: private ClassLoader loader;
17:
18: public CommandLineFileOpener(ClassLoader loader) {
19: this .loader = loader;
20: }
21:
22: public InputStream getResourceAsStream(String file)
23: throws IOException {
24: URL resource = loader.getResource(file);
25: if (resource == null) {
26: throw new IOException(file + " could not be found");
27: }
28: return resource.openStream();
29: }
30:
31: public Enumeration<URL> getResources(String packageName)
32: throws IOException {
33: return loader.getResources(packageName);
34: }
35:
36: public ClassLoader toClassLoader() {
37: return loader;
38: }
39: }
|