Methods Summary |
---|
public void | close()close the abstract archive
// nothing to do
|
public void | closeEntry()Closes the current entry
if (os!=null) {
os.flush();
os.close();
os = null;
}
|
public void | closeEntry(AbstractArchive os)close a previously returned @see java.io.OutputStream returned
by an addEntry call
os.close();
|
public void | create(java.lang.String path)creates a new abstract archive with the given path
this.path = path.replace('/", File.separatorChar);
archive = new File(path);
archive.mkdirs();
|
public boolean | delete()delete the archive
// delete the directory structure...
try {
return deleteDir(archive);
} catch (IOException e) {
return false;
}
|
private boolean | deleteDir(java.io.File directory)utility method for deleting a directory and all its content
if (!directory.isDirectory()) {
throw new FileNotFoundException(directory.getPath());
}
// delete contents
File[] entries = directory.listFiles();
for (int i=0;i<entries.length;i++) {
if (entries[i].isDirectory()) {
deleteDir(entries[i]);
} else {
FileUtils.deleteFile(entries[i]);
}
}
// delete self
return FileUtils.deleteFile(directory);
|
public boolean | deleteEntry(java.lang.String name)delete an entry in the archive
name = name.replace('/", File.separatorChar);
File input = new File(archive, name);
if (!input.exists()) {
return false;
}
return input.delete();
|
public java.util.Enumeration | entries(java.lang.String prefix)Returns an enumeration of the module file entries with the
specified prefix. All elements in the enumeration are of
type String. Each String represents a file name relative
to the root of the module.
prefix = prefix.replace('/", File.separatorChar);
File file = new File(archive, prefix);
Vector namesList = new Vector();
getListOfFiles(file, namesList, null);
return namesList.elements();
|
public java.util.Enumeration | entries()
Vector namesList = new Vector();
getListOfFiles(archive, namesList, null);
return namesList.elements();
|
public java.util.Enumeration | entries(java.util.Enumeration embeddedArchives)
Vector nameList = new Vector();
List massagedNames = new ArrayList();
while (embeddedArchives.hasMoreElements()) {
String subArchiveName = (String) embeddedArchives.nextElement();
massagedNames.add(FileUtils.makeFriendlyFileName(subArchiveName));
}
getListOfFiles(archive, nameList, massagedNames);
return nameList.elements();
|
public boolean | exists()
return archive.exists();
|
public long | getArchiveSize()Get the size of the archive
if(getArchiveUri() == null) {
return -1;
}
File tmpFile = new File(getArchiveUri());
return(tmpFile.length());
|
public java.lang.String | getArchiveUri()
return path;
|
public AbstractArchive | getEmbeddedArchive(java.lang.String name)create or obtain an embedded archive within this abstraction.
// Convert name to native form. See bug #6345029 for more details.
name = name.replace('/", File.separatorChar);
File file = new File(name);
File subDir;
if (file.isAbsolute()) {
subDir = file;
} else {
// first we try to see if a sub directory with the right file
// name exist
subDir = new File(archive, FileUtils.makeFriendlyFileName(name));
if (!subDir.exists()) {
// now we try to open a sub jar file...
subDir = new File(archive, name);
if (!subDir.exists()) {
// ok, nothing worked, reassing the name to the
// sub directory one
subDir = new File(archive, FileUtils.makeFriendlyFileName(name));
}
}
}
String subName = subDir.getPath();
if (!subDir.exists()) {
// time to create a new sub directory
File newDir = new File(subName);
newDir.mkdirs();
}
AbstractArchive sub;
if (subDir.isDirectory()) {
sub = new FileArchive();
((FileArchive) sub).open(subName);
} else {
sub = new InputJarArchive();
((InputJarArchive) sub).open(subName);
}
return sub;
|
public java.io.InputStream | getEntry(java.lang.String name)
name = name.replace('/", File.separatorChar);
File input = new File(archive, name);
if (!input.exists() || input.isDirectory()) {
return null;
}
FileInputStream fis = new FileInputStream(input);
try {
BufferedInputStream bis = new BufferedInputStream(fis);
return bis;
} catch (Throwable tx) {
if (fis != null) {
try {
fis.close();
} catch (Throwable thr) {
IOException ioe = new IOException("Error closing FileInputStream after error opening BufferedInputStream for entry " + name);
ioe.initCause(thr);
throw ioe;
}
}
IOException ioe = new IOException("Error opening BufferedInputStream for entry " + name);
ioe.initCause(tx);
throw ioe;
}
|
private void | getListOfFiles(java.io.File directory, java.util.Vector files, java.util.List embeddedArchives)utility method for getting contents of directory and
sub directories
File[] list = directory.listFiles();
if (list == null) {
return;
}
for (int i=0;i<list.length;i++) {
String fileName = list[i].getAbsolutePath().substring(archive.getAbsolutePath().length()+1);
if (!list[i].isDirectory()) {
fileName = fileName.replace(File.separatorChar, '/");
if (!fileName.equals(JarFile.MANIFEST_NAME)) {
files.add(fileName);
}
} else {
if (embeddedArchives!=null) {
if (!embeddedArchives.contains(fileName)) {
getListOfFiles(list[i], files, null);
}
} else {
getListOfFiles(list[i], files, null);
}
}
}
|
public java.util.jar.Manifest | getManifest()
InputStream is = null;
try {
is = getEntry(JarFile.MANIFEST_NAME);
if (is!=null) {
Manifest m = new Manifest(is);
return m;
}
} finally {
if (is != null) {
is.close();
}
}
return null;
|
public java.net.URI | getURI()
return archive.toURI();
|
public void | open(java.lang.String path)Open an abstract archive
this.path = path.replace('/", File.separatorChar);
archive = new File(path);
if (!archive.exists()) {
throw new FileNotFoundException(path);
}
|
public java.io.OutputStream | putNextEntry(java.lang.String name)
name = name.replace('/", File.separatorChar);
File newFile = new File(archive, name);
if (newFile.exists()) {
if (!deleteEntry(name))
throw new IOException(name + " already exists and cannot be deleted");
}
// if the entry name contains directory structure, we need
// to create those directories first.
if (name.lastIndexOf(File.separatorChar)!=-1) {
String dirs = name.substring(0, name.lastIndexOf(File.separatorChar));
(new File(archive, dirs)).mkdirs();
}
os = new BufferedOutputStream(new FileOutputStream(newFile));
return os;
|
public boolean | renameTo(java.lang.String name)rename the archive
return FileUtils.renameFile(archive, new File(name));
|
public boolean | supportsElementsOverwriting()
return true;
|