class FallbackZipEncoding extends java.lang.Object implements ZipEncoding
This implementation is not suitable 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 Simple8BitZipEnoding nor NioZipEncoding is
available.
The methods of this class are reentrant.
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
charsetName |
| Constructor and Description |
|---|
FallbackZipEncoding()
Construct a fallback zip encoding, which uses the platform's
default charset.
|
FallbackZipEncoding(java.lang.String charsetName)
Construct a fallback zip encoding, which uses the given charset.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canEncode(java.lang.String name)
Check, whether the given string may be losslessly encoded using this
encoding.
|
java.lang.String |
decode(byte[] data) |
java.nio.ByteBuffer |
encode(java.lang.String name)
Encode a filename or a comment to a byte array suitable for
storing it to a serialized zip entry.
|
public FallbackZipEncoding()
public FallbackZipEncoding(java.lang.String charsetName)
charsetName - The name of the charset or null for
the platform's default character set.public boolean canEncode(java.lang.String name)
ZipEncodingcanEncode in interface ZipEncodingname - A filename or ZIP comment.ZipEncoding.canEncode(java.lang.String)public java.nio.ByteBuffer encode(java.lang.String name)
throws java.io.IOException
ZipEncodingExamples 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"
encode in interface ZipEncodingname - A filename or ZIP comment.%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.java.io.IOException - on errorZipEncoding.encode(java.lang.String)public java.lang.String decode(byte[] data)
throws java.io.IOException
decode in interface ZipEncodingdata - The byte values to decode.java.io.IOException - on errorZipEncoding.decode(byte[])