org.apache.commons.compress.archivers.zip
Class ZipEncodingHelper

java.lang.Object
  extended by org.apache.commons.compress.archivers.zip.ZipEncodingHelper

abstract class ZipEncodingHelper
extends java.lang.Object

Static helper functions for robustly encoding filenames in zip files.


Nested Class Summary
private static class ZipEncodingHelper.SimpleEncodingHolder
          A class, which holds the high characters of a simple encoding and lazily instantiates a Simple8BitZipEncoding instance in a thread-safe manner.
 
Field Summary
private static byte[] HEX_DIGITS
          The hexadecimal digits 0,...,9,A,...,F encoded as ASCII bytes.
private static java.util.Map simpleEncodings
           
private static java.lang.String UTF_DASH_8
          variant name of the encoding UTF-8 used for comparisions.
(package private) static java.lang.String UTF8
          name of the encoding UTF-8
(package private) static ZipEncoding UTF8_ZIP_ENCODING
          name of the encoding UTF-8
 
Constructor Summary
ZipEncodingHelper()
           
 
Method Summary
(package private) static void appendSurrogate(java.nio.ByteBuffer bb, char c)
          Append %Uxxxx to the given byte buffer.
(package private) static ZipEncoding getZipEncoding(java.lang.String name)
          Instantiates a zip encoding.
(package private) static java.nio.ByteBuffer growBuffer(java.nio.ByteBuffer b, int newCapacity)
          Grow a byte buffer, so it has a minimal capacity or at least the double capacity of the original buffer
(package private) static boolean isUTF8(java.lang.String encoding)
          Whether a given encoding - or the platform's default encoding if the parameter is null - is UTF-8.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

simpleEncodings

private static final java.util.Map simpleEncodings

HEX_DIGITS

private static final byte[] HEX_DIGITS
The hexadecimal digits 0,...,9,A,...,F encoded as ASCII bytes.


UTF8

static final java.lang.String UTF8
name of the encoding UTF-8

See Also:
Constant Field Values

UTF_DASH_8

private static final java.lang.String UTF_DASH_8
variant name of the encoding UTF-8 used for comparisions.

See Also:
Constant Field Values

UTF8_ZIP_ENCODING

static final ZipEncoding UTF8_ZIP_ENCODING
name of the encoding UTF-8

Constructor Detail

ZipEncodingHelper

ZipEncodingHelper()
Method Detail

growBuffer

static java.nio.ByteBuffer growBuffer(java.nio.ByteBuffer b,
                                      int newCapacity)
Grow a byte buffer, so it has a minimal capacity or at least the double capacity of the original buffer

Parameters:
b - The original buffer.
newCapacity - The minimal requested new capacity.
Returns:
A byte buffer r with r.capacity() = max(b.capacity()*2,newCapacity) and all the data contained in b copied to the beginning of r.

appendSurrogate

static void appendSurrogate(java.nio.ByteBuffer bb,
                            char c)
Append %Uxxxx to the given byte buffer. The caller must assure, that bb.remaining()>=6.

Parameters:
bb - The byte buffer to write to.
c - The character to write.

getZipEncoding

static ZipEncoding getZipEncoding(java.lang.String name)
Instantiates a zip encoding.

Parameters:
name - The name of the zip encoding. Specify null for the platform's default encoding.
Returns:
A zip encoding for the given encoding name.

isUTF8

static boolean isUTF8(java.lang.String encoding)
Whether a given encoding - or the platform's default encoding if the parameter is null - is UTF-8.