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

pack-priv Class NioZipEncoding

extends Object
implements ZipEncoding
Class Inheritance
All Implemented Interfaces
org.apache.tools.zip.ZipEncoding
Imports
java.io.IOException, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, .CoderResult, .CodingErrorAction

A ZipEncoding, which uses a java.nio Charset to encode names.

This implementation works for all cases under java-1.5 or later. However, in java-1.4, some charsets don't have a java.nio implementation, most notably the default ZIP encoding Cp437.

The methods of this class are reentrant.

Field Summary

Modifier and TypeField and Description
private final Charset

Constructor Summary

AccessConstructor and Description
public
NioZipEncoding(final Charset
The NIO charset to wrap.
charset
)

Construct an NIO based zip encoding, which wraps the given charset.

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 String
decode(final byte[]
The byte values to decode.
data
)

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

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.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charsetback to summary
private final Charset charset

Constructor Detail

NioZipEncodingback to summary
public NioZipEncoding(final Charset charset)

Construct an NIO based zip encoding, which wraps the given charset.

Parameters
charset:Charset

The NIO charset to wrap.

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)
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[])
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)