Class NioZipEncoding
java.lang.Object
org.apache.commons.compress.archivers.zip.NioZipEncoding
- All Implemented Interfaces:
CharsetAccessor
,ZipEncoding
A ZipEncoding, which uses a java.nio
Charset
to encode names.
The methods of this class are reentrant.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionNioZipEncoding
(Charset charset, boolean useReplacement) Construct an NioZipEncoding using the given charset. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Check, whether the given string may be losslessly encoded using this encoding.decode
(byte[] data) Encode a file name or a comment to a byte array suitable for storing it to a serialized zip entry.private static ByteBuffer
encodeFully
(CharsetEncoder enc, CharBuffer cb, ByteBuffer out) private static CharBuffer
encodeSurrogate
(CharBuffer cb, char c) private static int
estimateIncrementalEncodingSize
(CharsetEncoder enc, int charCount) Estimate the size needed for remaining charactersprivate static int
estimateInitialBufferSize
(CharsetEncoder enc, int charChount) Estimate the initial encoded size (in bytes) for a character buffer.Provides access to the character set associated with an object.private CharsetDecoder
private CharsetEncoder
-
Field Details
-
charset
-
useReplacement
private final boolean useReplacement -
REPLACEMENT
private static final char REPLACEMENT- See Also:
-
REPLACEMENT_BYTES
private static final byte[] REPLACEMENT_BYTES -
REPLACEMENT_STRING
-
HEX_CHARS
private static final char[] HEX_CHARS
-
-
Constructor Details
-
NioZipEncoding
NioZipEncoding(Charset charset, boolean useReplacement) Construct an NioZipEncoding using the given charset.- Parameters:
charset
- The character set to use.useReplacement
- should invalid characters be replaced, or reported.
-
-
Method Details
-
getCharset
Description copied from interface:CharsetAccessor
Provides access to the character set associated with an object.This allows nio oriented code to use more natural character encoding/decoding methods, whilst allowing existing code to continue to rely on special-case error handling for UTF-8.
- Specified by:
getCharset
in interfaceCharsetAccessor
- Returns:
- the character set associated with this object
-
canEncode
Description copied from interface:ZipEncoding
Check, whether the given string may be losslessly encoded using this encoding.- Specified by:
canEncode
in interfaceZipEncoding
- Parameters:
name
- A file name or ZIP comment.- Returns:
- Whether the given name may be encoded with out any losses.
- See Also:
-
encode
Description copied from interface:ZipEncoding
Encode a file name 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"
- Specified by:
encode
in interfaceZipEncoding
- Parameters:
name
- A file name or ZIP comment.- Returns:
- 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. - See Also:
-
decode
- Specified by:
decode
in interfaceZipEncoding
- Parameters:
data
- The byte values to decode.- Returns:
- The decoded string.
- Throws:
IOException
- on error- See Also:
-
encodeFully
-
encodeSurrogate
-
newEncoder
-
newDecoder
-
estimateInitialBufferSize
Estimate the initial encoded size (in bytes) for a character buffer.The estimate assumes that one character consumes uses the maximum length encoding, whilst the rest use an average size encoding. This accounts for any BOM for UTF-16, at the expense of a couple of extra bytes for UTF-8 encoded ASCII.
- Parameters:
enc
- encoder to use for estimatescharChount
- number of characters in string- Returns:
- estimated size in bytes.
-
estimateIncrementalEncodingSize
Estimate the size needed for remaining characters- Parameters:
enc
- encoder to use for estimatescharCount
- number of characters remaining- Returns:
- estimated size in bytes.
-