// Path: src/main/java/org/xbib/io/Packet.java
// public interface Packet<P> {
// 
//     Map<String, Object> meta();
// 
//     Packet<P> meta(String key, Object value);
// 
//     P payload();
// 
//     Packet<P> payload(P packet);
// }
// 
// Path: src/main/java/org/xbib/io/StringPacket.java
// public class StringPacket implements Packet<String> {
// 
//     private Map<String, Object> meta = new HashMap<>();
//     private String name;
//     private String string;
// 
//     public StringPacket() {
//     }
// 
//     public StringPacket name(String name) {
//         this.name = name;
//         return this;
//     }
// 
//     public String name() {
//         return name;
//     }
// 
//     public StringPacket packet(String string) {
//         this.string = string;
//         return this;
//     }
// 
//     @Override
//     public Map<String, Object> meta() {
//         return meta;
//     }
// 
//     @Override
//     public Packet<String> meta(String key, Object value) {
//         meta.put(key, value);
//         return this;
//     }
// 
//     public String payload() {
//         return string;
//     }
// 
//     @Override
//     public Packet<String> payload(String packet) {
//         this.string = packet;
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return string;
//     }
// 
// 
// }
// 
// Path: src/main/java/org/xbib/io/archive/entry/ArchiveEntryEncoding.java
// public interface ArchiveEntryEncoding {
//     /**
//      * Check, whether the given string may be losslessly encoded using this
//      * encoding.
//      *
//      * @param name A filename or ZIP comment.
//      * @return Whether the given name may be encoded with out any losses.
//      */
//     boolean canEncode(String name);
// 
//     /**
//      * Encode a filename or a comment to a byte array suitable for
//      * storing it to a zip entry.
//      *
//      * <p>Examples for CP 437 (in pseudo-notation, right hand side is
//      * C-style notation):</p>
//      * <pre>
//      *  encode("\u20AC_for_Dollar.txt") = "%U20AC_for_Dollar.txt"
//      *  encode("\u00D6lf\u00E4sser.txt") = "\231lf\204sser.txt"
//      * </pre>
//      *
//      * @param name A filename or ZIP comment.
//      * @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 <code>%Uxxxx</code>.  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 java.io.IOException
//      */
//     ByteBuffer encode(String name) throws IOException;
// 
//     /**
//      * @param data The byte values to decode.
//      * @return The decoded string.
//      * @throws java.io.IOException
//      */
//     String decode(byte[] data) throws IOException;
// }


import org.xbib.io.Packet;
import org.xbib.io.StringPacket;
import org.xbib.io.archive.entry.ArchiveEntryEncoding;
import org.xbib.io.archive.entry.ArchiveEntryEncodingHelper;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.StringTokenizer;
        try {
            return formatNameBytes(name, buf, offset, length, DEFAULT_ENCODING);
        } catch (IOException ex) {
            try {
                return formatNameBytes(name, buf, offset, length, ArchiveUtils.FALLBACK_ENCODING);
            } catch (IOException ex2) {
                // impossible
                throw new RuntimeException(ex2);
            }
        }
    }

    /**
     * Copy a name into a buffer.
     * Copies characters from the name into the buffer
     * starting at the specified offset.
     * If the buffer is longer than the name, the buffer
     * is filled with trailing NULs.
     * If the name is longer than the buffer,
     * the output is truncated.
     *
     * @param name     The header name from which to copy the characters.
     * @param buf      The buffer where the name is to be stored.
     * @param offset   The starting offset into the buffer
     * @param length   The maximum number of header bytes to copy.
     * @param encoding name of the encoding to use for file names
     * @return The updated offset, i.e. offset + length
     */
    public static int formatNameBytes(String name, byte[] buf, final int offset,
                                      final int length,
// Path: src/main/java/org/xbib/io/Packet.java
// public interface Packet<P> {
// 
//     Map<String, Object> meta();
// 
//     Packet<P> meta(String key, Object value);
// 
//     P payload();
// 
//     Packet<P> payload(P packet);
// }
// 
// Path: src/main/java/org/xbib/io/StringPacket.java
// public class StringPacket implements Packet<String> {
// 
//     private Map<String, Object> meta = new HashMap<>();
//     private String name;
//     private String string;
// 
//     public StringPacket() {
//     }
// 
//     public StringPacket name(String name) {
//         this.name = name;
//         return this;
//     }
// 
//     public String name() {
//         return name;
//     }
// 
//     public StringPacket packet(String string) {
//         this.string = string;
//         return this;
//     }
// 
//     @Override
//     public Map<String, Object> meta() {
//         return meta;
//     }
// 
//     @Override
//     public Packet<String> meta(String key, Object value) {
//         meta.put(key, value);
//         return this;
//     }
// 
//     public String payload() {
//         return string;
//     }
// 
//     @Override
//     public Packet<String> payload(String packet) {
//         this.string = packet;
//         return this;
//     }
// 
//     @Override
//     public String toString() {
//         return string;
//     }
// 
// 
// }
// 
// Path: src/main/java/org/xbib/io/archive/entry/ArchiveEntryEncoding.java
// public interface ArchiveEntryEncoding {
//     /**
//      * Check, whether the given string may be losslessly encoded using this
//      * encoding.
//      *
//      * @param name A filename or ZIP comment.
//      * @return Whether the given name may be encoded with out any losses.
//      */
//     boolean canEncode(String name);
// 
//     /**
//      * Encode a filename or a comment to a byte array suitable for
//      * storing it to a zip entry.
//      *
//      * <p>Examples for CP 437 (in pseudo-notation, right hand side is
//      * C-style notation):</p>
//      * <pre>
//      *  encode("\u20AC_for_Dollar.txt") = "%U20AC_for_Dollar.txt"
//      *  encode("\u00D6lf\u00E4sser.txt") = "\231lf\204sser.txt"
//      * </pre>
//      *
//      * @param name A filename or ZIP comment.
//      * @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 <code>%Uxxxx</code>.  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 java.io.IOException
//      */
//     ByteBuffer encode(String name) throws IOException;
// 
//     /**
//      * @param data The byte values to decode.
//      * @return The decoded string.
//      * @throws java.io.IOException
//      */
//     String decode(byte[] data) throws IOException;
// }


// Path: src/main/java/org/xbib/io/archive/ArchiveUtils.java
import org.xbib.io.Packet;
import org.xbib.io.StringPacket;
import org.xbib.io.archive.entry.ArchiveEntryEncoding;
import org.xbib.io.archive.entry.ArchiveEntryEncodingHelper;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.StringTokenizer;

        try {
            return formatNameBytes(name, buf, offset, length, DEFAULT_ENCODING);
        } catch (IOException ex) {
            try {
                return formatNameBytes(name, buf, offset, length, ArchiveUtils.FALLBACK_ENCODING);
            } catch (IOException ex2) {
                // impossible
                throw new RuntimeException(ex2);
            }
        }
    }

    /**
     * Copy a name into a buffer.
     * Copies characters from the name into the buffer
     * starting at the specified offset.
     * If the buffer is longer than the name, the buffer
     * is filled with trailing NULs.
     * If the name is longer than the buffer,
     * the output is truncated.
     *
     * @param name     The header name from which to copy the characters.
     * @param buf      The buffer where the name is to be stored.
     * @param offset   The starting offset into the buffer
     * @param length   The maximum number of header bytes to copy.
     * @param encoding name of the encoding to use for file names
     * @return The updated offset, i.e. offset + length
     */
    public static int formatNameBytes(String name, byte[] buf, final int offset,
                                      final int length,
                                      final ArchiveEntryEncoding encoding)