de.janrufmonitor.repository.zip
Class ZipArchive

java.lang.Object
  extended by de.janrufmonitor.repository.zip.ZipArchive

public class ZipArchive
extends Object

This class is an implementation of a ZIP archive, which is used for several storage activities in jAnrufmonitor. It simple creates a new archive or open an existing one by the specified path.

Author:
Thilo Brandt

Field Summary
static String VERSION_ENTRY
          Version String which is stored as dummy entry in the zip as a signature.
 
Constructor Summary
ZipArchive(File archive, boolean useLock)
          Constructor with a File reference to a zip archive.
ZipArchive(String archive)
          Constructor with a path to a zip archive.
ZipArchive(String archive, boolean useLock)
          Constructor with a path to a zip archive.
 
Method Summary
 void add(Map m)
          Adds multiple entries to the zip archive.
 void add(String[] entries, InputStream[] contents)
          Adds multiple entries to the zip archive.
 void add(String entry, InputStream content)
          Adds a single new entry.
 boolean available()
          Checks if the archive is already opened.
 void backup()
          Backs up the content of the archive to a ~ file.
 void close()
          Closes the archive.
 boolean existEntry(String entry)
          Checks wether an extry exists or not
 InputStream get(String entry)
          Gets a single entry's InputStream by its entryname.
 byte[] getContent(String entry)
          Gets the content as byte array for a single entryname
 boolean isCorrupted()
          Checks the consistency of the ZipArchive and returns true if the archive is not consistent.
 boolean isCreatedByCurrentVersion()
          Return wether this archive was created by the current program version.
 List list()
          Returns a list of all entrynames in this archive.
 List list(FilenameFilter filter)
          Returns a list of all entrynames in this archive, filtered by a FilenameFilter object.
 void open()
          Opens the existing archive or creates a new onw if archive does not exist.
 void remove(List entries)
          Removes multiple entries as a List with Strings.
 void remove(String entry)
          Removes a single entry.
 void remove(String[] entries)
          Removes multiple entries.
 void restore()
          Restores a backed up file with ~ extension.
 int size()
          Returns the number of entries stored in the archive.
 File toFile()
          Returns the ZipArchive as a java.io.File representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION_ENTRY

public static String VERSION_ENTRY
Version String which is stored as dummy entry in the zip as a signature.

Constructor Detail

ZipArchive

public ZipArchive(String archive)
Constructor with a path to a zip archive. If archive does not exist it will be created.

Parameters:
archive -

ZipArchive

public ZipArchive(String archive,
                  boolean useLock)
Constructor with a path to a zip archive. If archive does not exist it will be created.

Parameters:
archive -
useLock - lock the archive during usage

ZipArchive

public ZipArchive(File archive,
                  boolean useLock)
Constructor with a File reference to a zip archive. If archive does not exist it will be created.

Parameters:
archive -
useLock - lock the archive during usage
Method Detail

open

public void open()
          throws ZipArchiveException
Opens the existing archive or creates a new onw if archive does not exist.

Throws:
ZipArchiveException

isCorrupted

public boolean isCorrupted()
Checks the consistency of the ZipArchive and returns true if the archive is not consistent.

Returns:
true wether the ZipArchive is courrupted, otherwise false.

close

public void close()
           throws ZipArchiveException
Closes the archive.

Throws:
ZipArchiveException

available

public boolean available()
Checks if the archive is already opened.

Returns:

size

public int size()
         throws ZipArchiveException
Returns the number of entries stored in the archive.

Returns:
number of entries
Throws:
ZipArchiveException

add

public void add(String entry,
                InputStream content)
         throws ZipArchiveException
Adds a single new entry.

Parameters:
entry - specifies the path in the Zip
content - content object as InputStream
Throws:
ZipArchiveException

add

public void add(String[] entries,
                InputStream[] contents)
         throws ZipArchiveException
Adds multiple entries to the zip archive.

Parameters:
entries - array of entry strings
contents - array of InputStreams with content
Throws:
ZipArchiveException

add

public void add(Map m)
         throws ZipArchiveException
Adds multiple entries to the zip archive. The key of the map entry must be a String which is used as zip entry name. The value of the map element must be a java.io.InputStream, which should be buffered.

Parameters:
m - Map of contents. Key of map must be a String and is used as zip entry name
Throws:
ZipArchiveException

existEntry

public boolean existEntry(String entry)
                   throws ZipArchiveException
Checks wether an extry exists or not

Parameters:
entry - entry to check
Returns:
true id entry is existing, false if not.
Throws:
ZipArchiveException

get

public InputStream get(String entry)
                throws ZipArchiveException
Gets a single entry's InputStream by its entryname.

Parameters:
entry -
Returns:
the entry's content or null if entry does not exist.
Throws:
ZipArchiveException

getContent

public byte[] getContent(String entry)
                  throws ZipArchiveException
Gets the content as byte array for a single entryname

Parameters:
entry -
Returns:
the content of the entry as byte array
Throws:
ZipArchiveException

toFile

public File toFile()
Returns the ZipArchive as a java.io.File representation.

Returns:
a valid File object

isCreatedByCurrentVersion

public boolean isCreatedByCurrentVersion()
                                  throws ZipArchiveException
Return wether this archive was created by the current program version.

Returns:
true if the current version has created this file, otherwise false.
Throws:
ZipArchiveException

list

public List list()
          throws ZipArchiveException
Returns a list of all entrynames in this archive.

Returns:
Throws:
ZipArchiveException

list

public List list(FilenameFilter filter)
          throws ZipArchiveException
Returns a list of all entrynames in this archive, filtered by a FilenameFilter object.

Parameters:
filter -
Returns:
Throws:
ZipArchiveException

remove

public void remove(String entry)
            throws ZipArchiveException
Removes a single entry.

Parameters:
entry -
Throws:
ZipArchiveException

remove

public void remove(String[] entries)
            throws ZipArchiveException
Removes multiple entries.

Parameters:
entries -
Throws:
ZipArchiveException

remove

public void remove(List entries)
            throws ZipArchiveException
Removes multiple entries as a List with Strings.

Parameters:
entries -
Throws:
ZipArchiveException

restore

public void restore()
             throws ZipArchiveException
Restores a backed up file with ~ extension.

Throws:
ZipArchiveException

backup

public void backup()
            throws ZipArchiveException
Backs up the content of the archive to a ~ file.

Throws:
ZipArchiveException


Copyright © 2010 by Thilo Brandt. All Rights Reserved.