|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.nsftools.zip.ZipFileManager
public class ZipFileManager
ZipFileManager is a Java class that is meant to simplify the process of reading from, creating, and modifying zip files.
Here's some example code of the class in action:
// if this file doesn't exist, it will be created; otherwise, the existing file can be
// read and updated
ZipFileManager zipFile = new ZipFileManager("c:\\test.zip");
// optionally redirect debug messages to System.out, in case we want to
// read them
zipFile.setDebugStream(System.out);
// optionally set a relative path, so any files we add that are beneath this
// subdirectory will have the relative directory information stripped off
// (for example, if the relative path is "c:\\temp" and the file is at "c:\\temp\\foo.txt"
// it will be added as "foo.txt" instead of "temp\\foo.txt"; if the file is at "c:\\a1\\foo.txt"
// the relative path will be ignored and it will be added as "a1\\foo.txt")
zipFile.setRelativePath("c:\\temp");
// if an entry with a label of "foo.txt" already exists in the file, remove it (an array
// of the existing entries, if any, can be retrieved with a call to getEntryNames)
zipFile.removeEntry("foo.txt");
// add the file at "c:\\test.txt" to the zip file
zipFile.addEntry("c:\\test.txt");
// add the file at "c:\\test2.txt" only if the file on disc is newer than the existing file
// in the zip file (or if the file is not yet in the zip file)
zipFile.updateEntry("c:\\test2.txt");
// add all files in the directory "c:\\temp\\a1" to the zip file, including subdirectories
zipFile.addDirectoryEntry("c:\\temp\\a1");
// update the contents of (or create) the zip file with your changes and close it
// (you could also have called the processChanges method to update the
// file and continue modifying it)
zipFile.close();
version 1.0
December 26, 2005
Copyright 2005 Julian Robichaux -- http://www.nsftools.com
Licensed under the Academic Free License version 2.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://opensource.org/licenses/afl-2.1.php
Constructor Summary | |
---|---|
ZipFileManager(java.io.File zipFile)
Create a new ZipFileManager object, using the given zipFile as the file we'll be reading from and potentially updating. |
|
ZipFileManager(java.lang.String zipFileName)
Same as the other constructor, but allows a file name String instead of a File object. |
Method Summary | |
---|---|
void |
addDirectoryEntry(java.io.File dir)
Add all files in the specified directory to the new zip file, including all subdirectories. |
void |
addDirectoryEntry(java.io.File dir,
int howDeep)
Add all files in the specified directory to the new zip file. |
void |
addDirectoryEntry(java.io.File dir,
int howDeep,
java.io.FileFilter filter)
Add all files in the specified directory to the new zip file. |
void |
addDirectoryEntry(java.lang.String dirName)
Add all files in the specified directory to the new zip file, including all subdirectories. |
void |
addDirectoryEntry(java.lang.String dirName,
int howDeep)
Add all files in the specified directory to the new zip file. |
void |
addEntry(java.io.File file)
Add the specified file to the new zip file. |
void |
addEntry(java.lang.String fileName)
Add the specified file to the new zip file. |
void |
addEntry(java.lang.String fileName,
java.lang.String comment)
Add the specified file to the new zip file, with the specified comment. |
boolean |
areChangesPending()
Returns true if there are changes pending (adds, removes, or updates) since the last time processChanges was called. |
void |
close()
Write any outstanding changes (adds, removes, or updates) to the zip file (if any) and close the internal reference to the zip file. |
void |
close(boolean doProcessChanges)
Close the internal reference to the zip file. |
java.lang.String |
getCurrentZipFileName()
Return the name of the zip file we're currently working with, if any. |
java.util.Hashtable |
getEntries()
Return the list of entries that are currently in the zip file (not including any files you've added since the last call to processChanges). |
java.util.zip.ZipEntry |
getEntry(java.lang.String entryName)
Return the ZipEntry associated with the given entryName, if any |
java.lang.String[] |
getEntryNames()
Return a String array of the entry names that are currently in the zip file (not including any files you've added since the last call to processChanges) |
java.io.InputStream |
getEntryStream(java.lang.String entryName)
Get the given entry as an InputStream, if it currently exists in the zip file. |
java.lang.String[] |
getNewEntryNames()
Return a String array of the files that will be added to the zip file (this list is reset every time you make a call to processChanges) |
java.lang.String[] |
getNewFilesAdded()
Return a String array of the new files that have already been added to the zip file as a result to ALL previous calls to processChanges (not including any files you've added since the last call to processChanges) |
java.lang.String |
getNewZipFileName()
Return the name of the zip file that will be created when processChanges or close is called. |
java.lang.String |
getRelativePath()
Get the current relative path assignment that is in effect. |
java.lang.String |
processChanges()
Same as the other version of processChanges, with ignoreErrors set to false (which means the process will fail with an Exception if there are I/O errors reading or writing files). |
java.lang.String |
processChanges(boolean ignoreErrors)
Process all outstanding changes to the zip file. |
void |
removeEntry(java.lang.String entryName)
Remove the specified entry from the current zip file, if it exists. |
void |
saveEntryAsFile(java.lang.String entryName,
java.lang.String newFileName)
If the given entryName is found in the current zip file, decompress it and save it on disc to the given newFileName. |
void |
setDebugStream(java.io.OutputStream out)
If you want the debug messages to be piped to an OutputStream, set it here |
void |
setNewZipFileName(java.lang.String newFileName)
Change the name of the zip file we will output our changes to. |
void |
setRelativePath(java.lang.String pathName)
Set the relative path for files that are added to this zip file. |
void |
updateDirectoryEntry(java.io.File dir)
Same as addDirectoryEntry, only it uses the logic in the updateEntry method for each file instead of the logic in addEntry. |
void |
updateDirectoryEntry(java.io.File dir,
int howDeep)
Same as addDirectoryEntry, only it uses the logic in the updateEntry method for each file instead of the logic in addEntry. |
void |
updateDirectoryEntry(java.io.File dir,
int howDeep,
java.io.FileFilter filter)
Same as addDirectoryEntry, only it uses the logic in the updateEntry method for each file instead of the logic in addEntry. |
void |
updateDirectoryEntry(java.lang.String dirName)
Same as addDirectoryEntry, only it uses the logic in the updateEntry method for each file instead of the logic in addEntry. |
void |
updateDirectoryEntry(java.lang.String dirName,
int howDeep)
Same as addDirectoryEntry, only it uses the logic in the updateEntry method for each file instead of the logic in addEntry. |
void |
updateEntry(java.io.File file)
If this file already exists in the zip file (based on the relative path name of the file) and the version on disc is newer than the version in the zip file, replace the version in the zip file with the one on disc. |
void |
updateEntry(java.lang.String fileName)
Same as the other updateEntry method, only you can use a fileName String instead of a File object. |
void |
updateEntry(java.lang.String entryName,
java.io.File file)
Compare the given entry to the given file, and if the file on disc is newer than the entry in the zip file, replace the entry with the file. |
void |
updateEntry(java.lang.String entryName,
java.lang.String fileName)
Same as the other updateEntry method, only you can use a fileName String instead of a File object. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ZipFileManager(java.io.File zipFile) throws java.io.IOException
java.io.IOException
public ZipFileManager(java.lang.String zipFileName) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public void setDebugStream(java.io.OutputStream out)
public java.util.Hashtable getEntries()
public java.util.zip.ZipEntry getEntry(java.lang.String entryName)
public java.lang.String[] getEntryNames()
public java.lang.String[] getNewEntryNames()
public java.lang.String[] getNewFilesAdded()
public java.io.InputStream getEntryStream(java.lang.String entryName) throws java.io.IOException
java.io.IOException
public void saveEntryAsFile(java.lang.String entryName, java.lang.String newFileName) throws java.io.IOException
java.io.IOException
public void removeEntry(java.lang.String entryName)
public void setRelativePath(java.lang.String pathName)
public java.lang.String getRelativePath()
public void addEntry(java.lang.String fileName, java.lang.String comment) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public void addEntry(java.lang.String fileName) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public void addEntry(java.io.File file) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void addDirectoryEntry(java.lang.String dirName) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void addDirectoryEntry(java.io.File dir) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void addDirectoryEntry(java.lang.String dirName, int howDeep) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void addDirectoryEntry(java.io.File dir, int howDeep) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void addDirectoryEntry(java.io.File dir, int howDeep, java.io.FileFilter filter) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void updateEntry(java.lang.String entryName, java.io.File file) throws java.io.IOException
java.io.IOException
public void updateEntry(java.lang.String entryName, java.lang.String fileName) throws java.io.IOException
java.io.IOException
public void updateEntry(java.io.File file) throws java.io.IOException
java.io.IOException
public void updateEntry(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public void updateDirectoryEntry(java.lang.String dirName) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void updateDirectoryEntry(java.io.File dir) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void updateDirectoryEntry(java.lang.String dirName, int howDeep) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void updateDirectoryEntry(java.io.File dir, int howDeep) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public void updateDirectoryEntry(java.io.File dir, int howDeep, java.io.FileFilter filter) throws java.lang.IllegalArgumentException, java.io.IOException
java.lang.IllegalArgumentException
java.io.IOException
public java.lang.String getCurrentZipFileName()
public java.lang.String getNewZipFileName()
public void setNewZipFileName(java.lang.String newFileName)
public java.lang.String processChanges() throws java.io.IOException
java.io.IOException
public java.lang.String processChanges(boolean ignoreErrors) throws java.io.IOException
java.io.IOException
public boolean areChangesPending()
public void close() throws java.io.IOException
java.io.IOException
public void close(boolean doProcessChanges) throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |