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

public abstract Class ZipEncodingHelper

extends Object
Class Inheritance
Imports
java.nio.Buffer, .ByteBuffer, java.nio.charset.Charset, .UnsupportedCharsetException, java.util.Collections, .HashMap, .Map

Static helper functions for robustly encoding filenames in zip files.

Nested and Inner Type Summary

Modifier and TypeClass and Description
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

Modifier and TypeField and Description
private static final byte[]
HEX_DIGITS

The hexadecimal digits 0,...,9,A,...,F encoded as ASCII bytes.

private static final Map<String, ZipEncodingHelper.SimpleEncodingHolder>
pack-priv static final String
UTF8

name of the encoding UTF-8

pack-priv static final ZipEncoding
UTF8_ZIP_ENCODING

name of the encoding UTF-8

private static final String
UTF_DASH_8

variant name of the encoding UTF-8 used for comparisons.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
appendSurrogate(final ByteBuffer
The byte buffer to write to.
bb
,
final char
The character to write.
c
)

Append %Uxxxx to the given byte buffer.

public static ZipEncoding

Returns:

A zip encoding for the given encoding name.
getZipEncoding
(final String
The name of the zip encoding. Specify null for the platform's default encoding.
name
)

Instantiates a zip encoding.

pack-priv static ByteBuffer

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.
growBuffer
(final ByteBuffer
The original buffer.
b
,
final int
The minimal requested new capacity.
newCapacity
)

Grow a byte buffer, so it has a minimal capacity or at least the double capacity of the original buffer

pack-priv static boolean
isUTF8(String encoding)

Whether a given encoding - or the platform's default encoding if the parameter is null - is UTF-8.

pack-priv static void
prepareBufferForRead(final Buffer
The buffer
b
)

Prepares a buffer to be read after writing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEX_DIGITSback to summary
private static final byte[] HEX_DIGITS

The hexadecimal digits 0,...,9,A,...,F encoded as ASCII bytes.

simpleEncodingsback to summary
private static final Map<String, ZipEncodingHelper.SimpleEncodingHolder> simpleEncodings
UTF8back to summary
pack-priv static final String UTF8

name of the encoding UTF-8

UTF8_ZIP_ENCODINGback to summary
pack-priv static final ZipEncoding UTF8_ZIP_ENCODING

name of the encoding UTF-8

UTF_DASH_8back to summary
private static final String UTF_DASH_8

variant name of the encoding UTF-8 used for comparisons.

Constructor Detail

ZipEncodingHelperback to summary
public ZipEncodingHelper()

Method Detail

appendSurrogateback to summary
pack-priv static void appendSurrogate(final ByteBuffer bb, final char c)

Append %Uxxxx to the given byte buffer. The caller must assure, that bb.remaining()>=6.

Parameters
bb:ByteBuffer

The byte buffer to write to.

c:char

The character to write.

getZipEncodingback to summary
public static ZipEncoding getZipEncoding(final String name)

Instantiates a zip encoding.

Parameters
name:String

The name of the zip encoding. Specify null for the platform's default encoding.

Returns:ZipEncoding

A zip encoding for the given encoding name.

growBufferback to summary
pack-priv static ByteBuffer growBuffer(final ByteBuffer b, final int newCapacity)

Grow a byte buffer, so it has a minimal capacity or at least the double capacity of the original buffer

Parameters
b:ByteBuffer

The original buffer.

newCapacity:int

The minimal requested new capacity.

Returns:ByteBuffer

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.

isUTF8back to summary
pack-priv static boolean isUTF8(String encoding)

Whether a given encoding - or the platform's default encoding if the parameter is null - is UTF-8.

prepareBufferForReadback to summary
pack-priv static void prepareBufferForRead(final Buffer b)

Prepares a buffer to be read after writing.

Parameters
b:Buffer

The buffer

org.apache.tools.zip back to summary

private Class ZipEncodingHelper.SimpleEncodingHolder

extends Object
Class Inheritance

A class, which holds the high characters of a simple encoding and lazily instantiates a Simple8BitZipEncoding instance in a thread-safe manner.

Field Summary

Modifier and TypeField and Description
private Simple8BitZipEncoding
private final char[]

Constructor Summary

AccessConstructor and Description
pack-priv
SimpleEncodingHolder(final char[]
The characters for byte codes 128 to 255.
highChars
)

Instantiate a simple encoding holder.

Method Summary

Modifier and TypeMethod and Description
public synchronized Simple8BitZipEncoding

Returns:

The associated Simple8BitZipEncoding, which is instantiated if not done so far.
getEncoding
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

encodingback to summary
private Simple8BitZipEncoding encoding
highCharsback to summary
private final char[] highChars

Constructor Detail

SimpleEncodingHolderback to summary
pack-priv SimpleEncodingHolder(final char[] highChars)

Instantiate a simple encoding holder.

Parameters
highChars:char[]

The characters for byte codes 128 to 255.

See Also
Simple8BitZipEncoding#Simple8BitZipEncoding(char[])

Method Detail

getEncodingback to summary
public synchronized Simple8BitZipEncoding getEncoding()
Returns:Simple8BitZipEncoding

The associated Simple8BitZipEncoding, which is instantiated if not done so far.