2.17.2: 2011-06-17

net.sf.basedb.util.zip
Class ZipUnpacker

java.lang.Object
  extended by net.sf.basedb.util.zip.ZipUnpacker

public class ZipUnpacker
extends Object

This class can be used to unpack zip files into the BASE directory structure. The class supports unpacking multiple zip files in the same transaction.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Field Summary
private  DbControl dc
           
private  Map<String,Directory> paths
          Cache of directories.
 
Constructor Summary
ZipUnpacker(DbControl dc)
          Create a new zip unpacker.
 
Method Summary
private  Directory getDirectory(Path path)
          Get the directory for the specified path.
 int unpackZipFile(Directory rootDir, ZipInputStream zip, boolean overwrite, AbsoluteProgressReporter progress)
          Unpack a zip file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dc

private final DbControl dc

paths

private Map<String,Directory> paths
Cache of directories.

Constructor Detail

ZipUnpacker

public ZipUnpacker(DbControl dc)
Create a new zip unpacker.

Parameters:
dc - The DbControl to use for database access
Method Detail

unpackZipFile

public int unpackZipFile(Directory rootDir,
                         ZipInputStream zip,
                         boolean overwrite,
                         AbsoluteProgressReporter progress)
                  throws IOException,
                         BaseException
Unpack a zip file.

Parameters:
rootDir - The directory where the contents of the zip file should be placed
zip - The contents of the zip file
overwrite - If existing files should be overwritten or ignored
progress - An optional progress reporter for displaying progress
Returns:
The number of files unpacked
Throws:
IOException - If there is an error when unpacking the zip file
BaseException - If there is a BASE error

getDirectory

private Directory getDirectory(Path path)
Get the directory for the specified path. We first check the internal cache. If not found we try to load it from the database. If still not found we create a new directory and save it to the database.

Parameters:
path - The path
Returns:
The directory

2.17.2: 2011-06-17