class NioZipEncoding extends java.lang.Object implements ZipEncoding
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.
Modifier and Type | Field and Description |
---|---|
private java.nio.charset.Charset |
charset |
Constructor and Description |
---|
NioZipEncoding(java.nio.charset.Charset charset)
Construct an NIO based zip encoding, which wraps 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 NioZipEncoding(java.nio.charset.Charset charset)
charset
- The NIO charset to wrap.public boolean canEncode(java.lang.String name)
ZipEncoding
canEncode
in interface ZipEncoding
name
- A filename or ZIP comment.ZipEncoding.canEncode(java.lang.String)
public java.nio.ByteBuffer encode(java.lang.String name)
ZipEncoding
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"
encode
in interface ZipEncoding
name
- 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.ZipEncoding.encode(java.lang.String)
public java.lang.String decode(byte[] data) throws java.io.IOException
decode
in interface ZipEncoding
data
- The byte values to decode.java.io.IOException
ZipEncoding.decode(byte[])