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

pack-priv Class FallbackZipEncoding

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

A fallback ZipEncoding, which uses a java.io means to encode names.

This implementation is not favorable for encodings other than utf-8, because java.io encodes unmappable character as question marks leading to unreadable ZIP entries on some operating systems.

Furthermore this implementation is unable to tell whether a given name can be safely encoded or not.

This implementation acts as a last resort implementation, when neither Simple8BitZipEncoding nor NioZipEncoding is available.

The methods of this class are reentrant.

Field Summary

Modifier and TypeField and Description
private final String

Constructor Summary

AccessConstructor and Description
public
FallbackZipEncoding()

Construct a fallback zip encoding, which uses the platform's default charset.

public
FallbackZipEncoding(final String
The name of the charset or null for the platform's default character set.
charset
)

Construct a fallback zip encoding, which uses 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 String charset

Constructor Detail

FallbackZipEncodingback to summary
public FallbackZipEncoding()

Construct a fallback zip encoding, which uses the platform's default charset.

FallbackZipEncodingback to summary
public FallbackZipEncoding(final String charset)

Construct a fallback zip encoding, which uses the given charset.

Parameters
charset:String

The name of the charset or null for the platform's default character set.

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) throws IOException

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.

Exceptions
IOException:
if something goes wrong
See Also
org.apache.tools.zip.ZipEncoding#encode(java.lang.String)