Example usage for org.apache.commons.compress.archivers.zip GeneralPurposeBit usesUTF8ForNames

List of usage examples for org.apache.commons.compress.archivers.zip GeneralPurposeBit usesUTF8ForNames

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.zip GeneralPurposeBit usesUTF8ForNames.

Prototype

public boolean usesUTF8ForNames() 

Source Link

Document

whether the current entry uses UTF8 for file name and comment.

Usage

From source file:com.zimbra.cs.util.ZipUtil.java

public static String bestGuessAtEntryName(ZipArchiveEntry zae, Locale locale) {
    GeneralPurposeBit gbp = zae.getGeneralPurposeBit();
    if ((null != gbp) && gbp.usesUTF8ForNames()) {
        return (zae.getName());
    }/*from  ww w.  ja va  2s.c  o m*/
    byte[] rawName = zae.getRawName();
    /* First of all, assume UTF-8.  java.util.zip assumes UTF-8 names, so this is a reasonable first
     * guess.  If the name isn't US-ASCII and it isn't UTF-8 there is a reasonable chance this
     * will fail because of the way UTF-8 works - and we can try other charsets.
     */
    String guess = convertBytesIfPossible(rawName, StandardCharsets.UTF_8);
    if (guess != null) {
        return guess;
    }
    guess = getNameFromUnicodeExtraPathIfPresent(zae);
    if (guess != null) {
        return guess;
    }
    List<String> charsetsForLocale = defaultCharsetForLocale.get(locale);
    if (null != charsetsForLocale) {
        for (String charsetForLocale : charsetsForLocale) {
            guess = convertBytesIfPossible(rawName, Charset.forName(charsetForLocale));
            if (guess != null) {
                return guess;
            }
        }
    }
    return zae.getName();
}