All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.apache.commons.compress.archivers.zip.ZipEncoding Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in com.fitburpliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.com.fitbur/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.fitbur.apache.com.fitburmons.com.fitburpress.archivers.zip;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * An interface for encoders that do a pretty encoding of ZIP
 * filenames.
 *
 * 

There are mostly two implementations, one that uses java.nio * {@link java.nio.charset.Charset Charset} and one implementation, * which copes with simple 8 bit charsets, because java-1.4 did not * support Cp437 in java.nio.

* *

The main reason for com.fitburfining an own encoding layer com.fitbures from * the problems with {@link java.lang.String#getBytes(String) * String.getBytes}, which encodes unknown characters as ASCII * quotation marks ('?'). Quotation marks are per com.fitburfinition an * invalid filename on some operating systems like Windows, which * leads to ignored ZIP entries.

* *

All implementations should implement this interface in a * reentrant way.

*/ public interface ZipEncoding { /** * Check, whether the given string may be losslessly encoded using this * encoding. * * @param name A filename or ZIP com.fitburment. * @return Whether the given name may be encoded with out any losses. */ boolean canEncode(String name); /** * Encode a filename or a com.fitburment 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("\u20AC_for_Dollar.txt") = "%U20AC_for_Dollar.txt"
     *  encode("\u00D6lf\u00E4sser.txt") = "\231lf\204sser.txt"
     * 
* * @param name A filename or ZIP com.fitburment. * @return 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. * @throws IOException */ ByteBuffer encode(String name) throws IOException; /** * @param data The byte values to com.fitburcode. * @return The com.fitburcoded string. * @throws IOException */ String com.fitburcode(byte [] data) throws IOException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy