Top Description Inners Fields Constructors Methods
org.apache.tools.zip

pack-priv Class Simple8BitZipEncoding

extends Object
implements ZipEncoding
Class Inheritance
All Implemented Interfaces
org.apache.tools.zip.ZipEncoding
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.ArrayList, .Collections, .List

This ZipEncoding implementation implements a simple 8 bit character set, which meets the following restrictions:

These restrictions most notably apply to the most prominent omissions of Java 1.4 Charset implementation, Cp437 and Cp850.

The methods of this class are reentrant.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Simple8BitZipEncoding.Simple8BitChar

A character entity, which is put to the reverse mapping table of a simple encoding.

Field Summary

Modifier and TypeField and Description
private final char[]
highChars

The characters for byte values of 128 to 255 stored as an array of 128 chars.

private final List<Simple8BitZipEncoding.Simple8BitChar>
reverseMapping

A list of Simple8BitChar objects sorted by the unicode field.

Constructor Summary

AccessConstructor and Description
public
Simple8BitZipEncoding(final char[]
The characters for byte values of 128 to 255 stored as an array of 128 chars.
highChars
)

Method Summary

Modifier and TypeMethod and Description
public boolean
canEncode(final String
A filename or ZIP comment.
name
)

Implements org.apache.tools.zip.ZipEncoding.canEncode.

Check, whether the given string may be losslessly encoded using this encoding.
public boolean

Returns:

Whether the given unicode character is covered by this encoding.
canEncodeChar
(final char
The character to encode.
c
)

public String
decode(final byte[]
The byte values to decode.
data
)

Implements org.apache.tools.zip.ZipEncoding.decode.

public char

Returns:

The associated character value.
decodeByte
(final byte
The byte to decode.
b
)

Return the character code for a given encoded byte.

public ByteBuffer
encode(final String
A filename or ZIP comment.
name
)

Implements org.apache.tools.zip.ZipEncoding.encode.

Encode a filename or a comment to a byte array suitable for storing it to a serialized zip entry.
private Simple8BitZipEncoding.Simple8BitChar

Returns:

A Simple8BitChar, if this character is covered by this encoding. A null value is returned, if this character is not covered by this encoding.
encodeHighChar
(final char
A unicode character in the range from 0x0080 to 0x7f00
c
)

public boolean

Returns:

Whether the given unicode character is covered by this encoding. If false is returned, nothing is pushed to the byte buffer.
pushEncodedChar
(final ByteBuffer
The byte buffer to write to.
bb
,
final char
The character to encode.
c
)

Pushes the encoded form of the given character to the given byte buffer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

highCharsback to summary
private final char[] highChars

The characters for byte values of 128 to 255 stored as an array of 128 chars.

reverseMappingback to summary
private final List<Simple8BitZipEncoding.Simple8BitChar> reverseMapping

A list of Simple8BitChar objects sorted by the unicode field. This list is used to binary search reverse mapping of unicode characters with a character code greater than 127.

Constructor Detail

Simple8BitZipEncodingback to summary
public Simple8BitZipEncoding(final char[] highChars)
Parameters
highChars:char[]

The characters for byte values of 128 to 255 stored as an array of 128 chars.

Method Detail

canEncodeback to summary
public boolean canEncode(final String name)

Implements org.apache.tools.zip.ZipEncoding.canEncode.

Doc from org.apache.tools.zip.ZipEncoding.canEncode.

Check, whether the given string may be losslessly encoded using this encoding.

Parameters
name:String

A filename or ZIP comment.

Returns:boolean

Whether the given name may be encoded with out any losses.

See Also
org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String)
canEncodeCharback to summary
public boolean canEncodeChar(final char c)
Parameters
c:char

The character to encode.

Returns:boolean

Whether the given unicode character is covered by this encoding.

decodeback to summary
public String decode(final byte[] data) throws IOException

Implements org.apache.tools.zip.ZipEncoding.decode.

Parameters
data:byte[]

Doc from org.apache.tools.zip.ZipEncoding.decode.

The byte values to decode.

Returns:String

Doc from org.apache.tools.zip.ZipEncoding.decode.

The decoded string.

Exceptions
IOException:

Doc from org.apache.tools.zip.ZipEncoding.decode.

if something goes wrong

See Also
org.apache.tools.zip.ZipEncoding#decode(byte[])
decodeByteback to summary
public char decodeByte(final byte b)

Return the character code for a given encoded byte.

Parameters
b:byte

The byte to decode.

Returns:char

The associated character value.

encodeback to summary
public ByteBuffer encode(final String name)

Implements org.apache.tools.zip.ZipEncoding.encode.

Doc from org.apache.tools.zip.ZipEncoding.encode.

Encode a filename or a comment to a byte array suitable for storing it to a serialized zip entry.

Examples for CP 437 (in pseudo-notation, right hand side is C-style notation):

 encode("€_for_Dollar.txt") = "%U20AC_for_Dollar.txt"
 encode("Ölfässer.txt") = "\231lf\204sser.txt"
Parameters
name:String

A filename or ZIP comment.

Returns:ByteBuffer

A byte buffer with a backing array containing the encoded name. Unmappable characters or malformed character sequences are mapped to a sequence of utf-16 words encoded in the format %Uxxxx. It is assumed, that the byte buffer is positioned at the beginning of the encoded result, the byte buffer has a backing array and the limit of the byte buffer points to the end of the encoded result.

See Also
org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
encodeHighCharback to summary
private Simple8BitZipEncoding.Simple8BitChar encodeHighChar(final char c)
Parameters
c:char

A unicode character in the range from 0x0080 to 0x7f00

Returns:Simple8BitZipEncoding.Simple8BitChar

A Simple8BitChar, if this character is covered by this encoding. A null value is returned, if this character is not covered by this encoding.

pushEncodedCharback to summary
public boolean pushEncodedChar(final ByteBuffer bb, final char c)

Pushes the encoded form of the given character to the given byte buffer.

Parameters
bb:ByteBuffer

The byte buffer to write to.

c:char

The character to encode.

Returns:boolean

Whether the given unicode character is covered by this encoding. If false is returned, nothing is pushed to the byte buffer.

org.apache.tools.zip back to summary

private final Class Simple8BitZipEncoding.Simple8BitChar

extends Object
implements Comparable<Simple8BitZipEncoding.Simple8BitChar>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

A character entity, which is put to the reverse mapping table of a simple encoding.

Field Summary

Modifier and TypeField and Description
public final byte
public final char

Constructor Summary

AccessConstructor and Description
pack-priv
Simple8BitChar(final byte code, final char unicode)

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(final Simple8BitZipEncoding.Simple8BitChar
the object to be compared.
a
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(final Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

codeback to summary
public final byte code
unicodeback to summary
public final char unicode

Constructor Detail

Simple8BitCharback to summary
pack-priv Simple8BitChar(final byte code, final char unicode)

Method Detail

compareToback to summary
public int compareTo(final Simple8BitZipEncoding.Simple8BitChar a)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
a:Simple8BitZipEncoding.Simple8BitChar

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override