Top Description Methods
org.apache.tools.zip

public Interface ZipEncoding

Known Direct Implementers
org.apache.tools.zip.FallbackZipEncoding, org.apache.tools.zip.NioZipEncoding, org.apache.tools.zip.Simple8BitZipEncoding
Imports
java.io.IOException, java.nio.ByteBuffer

An interface for encoders that do a pretty encoding of ZIP filenames.

There are mostly two implementations, one that uses java.nio Charset and one implementation, which copes with simple 8 bit charsets, because java-1.4 did not support Cp437 in java.nio.

The main reason for defining an own encoding layer comes from the problems with String.getBytes, which encodes unknown characters as ASCII quotation marks ('?'). Quotation marks are per definition an invalid filename on some operating systems like Windows, which leads to ignored ZIP entries.

All implementations should implement this interface in a reentrant way.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

Whether the given name may be encoded with out any losses.
canEncode
(String
A filename or ZIP comment.
name
)

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

public String

Returns:

The decoded string.
decode
(byte[]
The byte values to decode.
data
)

public ByteBuffer

Returns:

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.
encode
(String
A filename or ZIP comment.
name
)

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

Method Detail

canEncodeback to summary
public boolean canEncode(String name)

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.

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

The byte values to decode.

Returns:String

The decoded string.

Exceptions
IOException:
if something goes wrong
encodeback to summary
public ByteBuffer encode(String name) throws IOException

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.

Exceptions
IOException:
if something goes wrong