DirectoryArchivepublic class DirectoryArchive extends Object implements ArchiveThis is an implementation of {@link Archive} when container returns a file:
url that refers to a directory that contains an exploded jar file.
e.g. file:/tmp/a_ear/ejb_jar |
Fields Summary |
---|
private File | directoryThe directory this archive represents. | private URL | rootURLThe URL representation of this archive. | private List | entriesThe file entries that this archive contains. | private Logger | logger |
Constructors Summary |
---|
public DirectoryArchive(File directory)
this(directory, Logger.global);
| public DirectoryArchive(File directory, Logger logger)
logger.entering("DirectoryArchive", "DirectoryArchive",
new Object[]{directory});
this.logger = logger;
if (!directory.isDirectory()) {
// should never reach here, hence the msg is not internationalized.
throw new IllegalArgumentException(directory +
" is not a directory." + // NOI18N
"If it is a jar file, then use JarFileArchive."); // NOI18N
}
this.directory = directory;
rootURL = directory.toURI().toURL();
logger.logp(Level.FINER, "DirectoryArchive", "DirectoryArchive",
"rootURL = {0}", rootURL);
init(this.directory, this.directory); // initialize entries
|
Methods Summary |
---|
public java.util.Iterator | getEntries()
return entries.iterator();
| public java.io.InputStream | getEntry(java.lang.String entryPath)
File f = getFile(entryPath);
InputStream is = f.exists() ? new FileInputStream(f) : null;
return is;
| public java.net.URL | getEntryAsURL(java.lang.String entryPath)
File f = getFile(entryPath);
URL url = f.exists() ? f.toURI().toURL() : null;
return url;
| private java.io.File | getFile(java.lang.String entryPath)
File f = new File(directory, entryPath);
return f;
| public java.net.URL | getRootURL()
return rootURL;
| private void | init(java.io.File top, java.io.File directory)
File[] dirFiles = directory.listFiles();
for (File file : dirFiles) {
if (file.isDirectory()) {
continue; // exclude dir entries
}
// add only the relative path from the top.
// note: we use unix style path
String entryName = file.getPath().replace(File.separator, "/") // NOI18N
.substring(top.getPath().length() + 1);
entries.add(entryName);
}
File[] subDirs = directory.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
for (File subDir : subDirs) {
init(top, subDir); // recursion
}
|
|