TrueZIP 6.8.3

de.schlichtherle.util.zip
Class ExtraField

java.lang.Object
  extended by de.schlichtherle.util.zip.ExtraField
Direct Known Subclasses:
DefaultExtraField

abstract class ExtraField
extends Object

Abstract base class for an Extra Field in a Local or Central Header of a ZIP archive. It defines the common properties of all Extra Fields and how to serialize/deserialize them to/from byte arrays.

This class is not thread-safe.

Since:
TrueZIP 6.7
Author:
Christian Schlichtherle

Field Summary
private static Map registry
           
static int ZIP64_HEADER_ID
          The Header ID of a ZIP64 Extended Information Extra Field.
 
Constructor Summary
ExtraField()
           
 
Method Summary
static ExtraField create(int headerID)
          A static factory method which creates a new Extra Field based on the given Header ID.
(package private)  byte[] getDataBlock()
          Returns a protective copy of the Data Block.
(package private) abstract  int getDataSize()
          Returns the Data Size of this Extra Field.
abstract  int getHeaderID()
          Returns the Header ID (type) of this Extra Field.
(package private) abstract  void readFrom(byte[] data, int off, int size)
          Initializes this Extra Field by deserializing a Data Block of size bytes from the byte array data at the zero based offset off.
static void register(Class c)
          Registers a concrete implementation of this abstract base class for use with the static factory method create(int).
(package private) abstract  void writeTo(byte[] data, int off)
          Serializes a Data Block of getDataSize() bytes to the byte array data at the zero based offset off.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZIP64_HEADER_ID

public static final int ZIP64_HEADER_ID
The Header ID of a ZIP64 Extended Information Extra Field.

See Also:
Constant Field Values

registry

private static final Map registry
Constructor Detail

ExtraField

ExtraField()
Method Detail

register

public static void register(Class c)
Registers a concrete implementation of this abstract base class for use with the static factory method create(int).

Parameters:
c - The implementation class of this abstract base class.
Throws:
IllegalArgumentException - If c is null, cannot get instantiated, is not a subclass of ExtraField or its Header ID is out of range. A more descriptive exception may be associated to it as its cause.
See Also:
create(int)

create

public static ExtraField create(int headerID)
A static factory method which creates a new Extra Field based on the given Header ID. The returned Extra Field still requires proper initialization, for example by calling readFrom(byte[], int, int).

Parameters:
headerID - An unsigned short integer (two bytes) which indicates the type of the returned Extra Field.
Returns:
A new Extra Field - never null!
Throws:
IllegalArgumentException - If headerID is out of range.
See Also:
register(java.lang.Class)

getHeaderID

public abstract int getHeaderID()
Returns the Header ID (type) of this Extra Field. The Header ID is an unsigned short integer (two bytes) which must be constant during the life cycle of this object.


getDataSize

abstract int getDataSize()
Returns the Data Size of this Extra Field. The Data Size is an unsigned short integer (two bytes) which indicates the length of the Data Block in bytes and does not include its own size in this Extra Field. This property may be initialized by calling readFrom(byte[], int, int).

Returns:
The size of the Data Block in bytes or 0 if unknown.
See Also:
getDataBlock()

getDataBlock

final byte[] getDataBlock()
Returns a protective copy of the Data Block. null is never returned.

See Also:
getDataSize()

readFrom

abstract void readFrom(byte[] data,
                       int off,
                       int size)
Initializes this Extra Field by deserializing a Data Block of size bytes from the byte array data at the zero based offset off. Upon return, this Extra Field shall not access data subsequently and getDataSize() must equal size.

Parameters:
data - The byte array to read the Data Block from.
off - The zero based offset in the byte array where the first byte of the Data Block is read from.
size - The length of the Data Block in bytes.
Throws:
IndexOutOfBoundsException - If the byte array data does not hold at least size bytes at the zero based offset off.
RuntimeException - If size is illegal or the deserialized Data Block contains illegal data.
See Also:
getDataSize()

writeTo

abstract void writeTo(byte[] data,
                      int off)
Serializes a Data Block of getDataSize() bytes to the byte array data at the zero based offset off. Upon return, this Extra Field shall not access data subsequently.

Parameters:
data - The byte array to write the Data Block to.
off - The zero based offset in the byte array where the first byte of the Data Block is written to.
Throws:
IndexOutOfBoundsException - If the byte array data does not hold at least getDataSize() bytes at the zero based offset off.
See Also:
getDataSize()

TrueZIP 6.8.3

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