TrueZIP 6.8.3

de.schlichtherle.io.archive.spi
Class AbstractArchiveDriver

java.lang.Object
  extended by de.schlichtherle.io.archive.spi.AbstractArchiveDriver
All Implemented Interfaces:
ArchiveDriver, Serializable
Direct Known Subclasses:
TarDriver, ZipDriver

public abstract class AbstractArchiveDriver
extends Object
implements ArchiveDriver, Serializable

An abstract archive driver implementation to ease the task of developing an archive driver. It provides default implementations for character sets and icon handling.

Since TrueZIP 6.4, this class is serializable in order to meet the requirements of the File class.

Since:
TrueZIP 6.0
Author:
Christian Schlichtherle
See Also:
Serialized Form

Nested Class Summary
protected static class AbstractArchiveDriver.InconsistentCharsetSupportError
          Thrown to indicate that the character set implementation in the Java Runtime Environment (JRE) for the Java Standard Edition (JSE) is broken and needs fixing.
private  class AbstractArchiveDriver.ThreadLocalEncoder
           
 
Field Summary
private  String charset
           
private static String CLASS_NAME
           
private  Icon closedIcon
           
private  AbstractArchiveDriver.ThreadLocalEncoder encoder
          This field should be considered to be final!
private static Logger logger
           
private  Icon openIcon
           
private static long serialVersionUID
           
 
Constructor Summary
protected AbstractArchiveDriver(String charset, Icon openIcon, Icon closedIcon)
          Constructs a new abstract archive driver.
 
Method Summary
protected  void ensureEncodable(String entryName)
          Ensures that the given entry name is representable in this driver's character set charset.
 String getCharset()
          Returns the value of the property charset which was provided to the constructor.
 Icon getClosedIcon(Archive archive)
          Returns the value of the property closedIcon which was provided to the constructor.
 String getEncoding()
          Deprecated. Use getCharset() instead.
 Icon getOpenIcon(Archive archive)
          Returns the value of the property openIcon which was provided to the constructor.
private  boolean invariants()
          Checks the invariants of this class and throws an AssertionError if any is violated even if assertion checking is disabled.
private  void readObject(ObjectInputStream in)
          Postfixes the instance after its default deserialization.
private static UnsupportedEncodingException testJSE11Support(String charset)
           
private static UnsupportedCharsetException testJSE14Support(String charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.schlichtherle.io.archive.spi.ArchiveDriver
createArchiveEntry, createInputArchive, createOutputArchive, equals, hashCode
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

CLASS_NAME

private static final String CLASS_NAME
See Also:
Constant Field Values

logger

private static final Logger logger

charset

private final String charset

openIcon

private final Icon openIcon

closedIcon

private final Icon closedIcon

encoder

private transient AbstractArchiveDriver.ThreadLocalEncoder encoder
This field should be considered to be final!

See Also:
ensureEncodable(java.lang.String)
Constructor Detail

AbstractArchiveDriver

protected AbstractArchiveDriver(String charset,
                                Icon openIcon,
                                Icon closedIcon)
Constructs a new abstract archive driver.

Parameters:
charset - The name of a character set to use by default for all entry names and probably other meta data when reading or writing archive files.
openIcon - The icon to return by getOpenIcon(de.schlichtherle.io.archive.Archive). May be null.
closedIcon - The icon to return by getClosedIcon(de.schlichtherle.io.archive.Archive). May be null.
Throws:
NullPointerException - If charset is null.
UnsupportedCharsetException - If charset is not supported by both the JSE 1.1 API and JSE 1.4 API.
AbstractArchiveDriver.InconsistentCharsetSupportError - If charset is supported by the JSE 1.1 API, but not the JSE 1.4 API, or vice versa.
Method Detail

testJSE11Support

private static UnsupportedEncodingException testJSE11Support(String charset)

testJSE14Support

private static UnsupportedCharsetException testJSE14Support(String charset)

readObject

private void readObject(ObjectInputStream in)
                 throws IOException,
                        ClassNotFoundException
Postfixes the instance after its default deserialization.

Throws:
InvalidObjectException - If the instance invariants are not met.
IOException
ClassNotFoundException

invariants

private boolean invariants()
Checks the invariants of this class and throws an AssertionError if any is violated even if assertion checking is disabled.

The constructors call this method like this:

assert invariants(); 
This calls the method if and only if assertions are enabled in order to assert that the instance invariants are properly obeyed. If assertions are disabled, the call to this method is thrown away by the HotSpot compiler, so there is no performance penalty.

When deserializing however, this method is called regardless of the assertion status. On error, the AssertionError is wrapped in an InvalidObjectException and thrown instead.

Returns:
true
Throws:
AssertionError - If any invariant is violated even if assertions are disabled.

ensureEncodable

protected final void ensureEncodable(String entryName)
                              throws CharConversionException
Ensures that the given entry name is representable in this driver's character set charset. Should be called by sub classes in their implementation of the method ArchiveDriver.createArchiveEntry(de.schlichtherle.io.archive.Archive, java.lang.String, de.schlichtherle.io.archive.spi.ArchiveEntry).

Parameters:
entryName - A valid archive entry name - null is not permissible.
Throws:
CharConversionException - If the entry name contains characters which cannot get encoded.
See Also:
getCharset(), Requirements for Archive Entry Names

getCharset

public final String getCharset()
Returns the value of the property charset which was provided to the constructor.


getEncoding

public final String getEncoding()
Deprecated. Use getCharset() instead.


getOpenIcon

public final Icon getOpenIcon(Archive archive)
Returns the value of the property openIcon which was provided to the constructor.

Specified by:
getOpenIcon in interface ArchiveDriver
Parameters:
archive - Ignored.
Returns:
The icon that should be displayed for the given archive if is is open/expanded in the view. If null is returned, a default icon should be used.

getClosedIcon

public final Icon getClosedIcon(Archive archive)
Returns the value of the property closedIcon which was provided to the constructor.

Specified by:
getClosedIcon in interface ArchiveDriver
Parameters:
archive - Ignored.
Returns:
The icon that should be displayed for the given archive if is is closed/collapsed in the view. If null is returned, a default icon should be used.

TrueZIP 6.8.3

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.