2 * Licensed to the Apache Software Foundation (ASF) under one
\r
3 * or more contributor license agreements. See the NOTICE file
\r
4 * distributed with this work for additional information
\r
5 * regarding copyright ownership. The ASF licenses this file
\r
6 * to you under the Apache License, Version 2.0 (the
\r
7 * "License"); you may not use this file except in compliance
\r
8 * with the License. You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing,
\r
13 * software distributed under the License is distributed on an
\r
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
15 * KIND, either express or implied. See the License for the
\r
16 * specific language governing permissions and limitations
\r
17 * under the License.
\r
20 package org.apache.tools.zip;
\r
22 import java.io.IOException;
\r
23 import java.nio.ByteBuffer;
\r
26 * An interface for encoders that do a pretty encoding of ZIP
\r
29 * <p>There are mostly two implementations, one that uses java.nio
\r
30 * {@link java.nio.charset.Charset Charset} and one implementation,
\r
31 * which copes with simple 8 bit charsets, because java-1.4 did not
\r
32 * support Cp437 in java.nio.</p>
\r
34 * <p>The main reason for defining an own encoding layer comes from
\r
35 * the problems with {@link java.lang.String#getBytes(String)
\r
36 * String.getBytes}, which encodes unknown characters as ASCII
\r
37 * quotation marks ('?'). Quotation marks are per definition an
\r
38 * invalid filename on some operating systems like Windows, which
\r
39 * leads to ignored ZIP entries.</p>
\r
41 * <p>All implementations should implement this interface in a
\r
42 * reentrant way.</p>
\r
44 interface ZipEncoding {
\r
46 * Check, whether the given string may be losslessly encoded using this
\r
49 * @param name A filename or ZIP comment.
\r
50 * @return Whether the given name may be encoded with out any losses.
\r
52 boolean canEncode(String name);
\r
55 * Encode a filename or a comment to a byte array suitable for
\r
56 * storing it to a serialized zip entry.
\r
58 * <p>Examples for CP 437 (in pseudo-notation, right hand side is
\r
59 * C-style notation):</p>
\r
61 * encode("\u20AC_for_Dollar.txt") = "%U20AC_for_Dollar.txt"
\r
62 * encode("\u00D6lf\u00E4sser.txt") = "\231lf\204sser.txt"
\r
65 * @param name A filename or ZIP comment.
\r
66 * @return A byte buffer with a backing array containing the
\r
67 * encoded name. Unmappable characters or malformed
\r
68 * character sequences are mapped to a sequence of utf-16
\r
69 * words encoded in the format <code>%Uxxxx</code>. It is
\r
70 * assumed, that the byte buffer is positioned at the
\r
71 * beinning of the encoded result, the byte buffer has a
\r
72 * backing array and the limit of the byte buffer points
\r
73 * to the end of the encoded result.
\r
74 * @throws IOException
\r
76 ByteBuffer encode(String name) throws IOException;
\r
79 * @param data The byte values to decode.
\r
80 * @return The decoded string.
\r
81 * @throws IOException
\r
83 String decode(byte [] data) throws IOException;
\r