/** * Whether to set the language encoding flag if the file name * encoding is UTF-8. * * <p>Defaults to true.</p> * * @param b whether to set the language encoding flag if the file * name encoding is UTF-8 */ public void setUseLanguageEncodingFlag(final boolean b) { useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); }
/** * The encoding to use for filenames and the file comment. * * <p>For a list of possible values see <a * href="http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html">http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html</a>. * Defaults to UTF-8.</p> * @param encoding the encoding to use for file names, use null * for the platform's default encoding */ public void setEncoding(final String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); if (useUTF8Flag && !ZipEncodingHelper.isUTF8(encoding)) { useUTF8Flag = false; } }
/** * Instantiates a zip encoding. An NIO based character set encoder/decoder will be returned. * As a special case, if the character set is UTF-8, the nio encoder will be configured replace malformed and * unmappable characters with '?'. This matches existing behavior from the older fallback encoder. * <p> * If the requested characer set cannot be found, the platform default will * be used instead. * </p> * @param name The name of the zip encoding. Specify {@code null} for * the platform's default encoding. * @return A zip encoding for the given encoding name. */ public static ZipEncoding getZipEncoding(final String name) { Charset cs = Charset.defaultCharset(); if (name != null) { try { cs = Charset.forName(name); } catch (UnsupportedCharsetException e) { // NOSONAR we use the default encoding instead } } boolean useReplacement = isUTF8(cs.name()); return new NioZipEncoding(cs, useReplacement); }
/** * Whether to set the language encoding flag if the file name * encoding is UTF-8. * * <p>Defaults to true.</p> * * @param b whether to set the language encoding flag if the file * name encoding is UTF-8 */ public void setUseLanguageEncodingFlag(final boolean b) { useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding); }
/** * The encoding to use for filenames and the file comment. * * <p>For a list of possible values see <a * href="http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html">http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html</a>. * Defaults to UTF-8.</p> * @param encoding the encoding to use for file names, use null * for the platform's default encoding */ public void setEncoding(final String encoding) { this.encoding = encoding; this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); if (useUTF8Flag && !ZipEncodingHelper.isUTF8(encoding)) { useUTF8Flag = false; } }
/** * Instantiates a zip encoding. An NIO based character set encoder/decoder will be returned. * As a special case, if the character set is UTF-8, the nio encoder will be configured replace malformed and * unmappable characters with '?'. This matches existing behavior from the older fallback encoder. * <p> * If the requested characer set cannot be found, the platform default will * be used instead. * </p> * @param name The name of the zip encoding. Specify {@code null} for * the platform's default encoding. * @return A zip encoding for the given encoding name. */ public static ZipEncoding getZipEncoding(final String name) { Charset cs = Charset.defaultCharset(); if (name != null) { try { cs = Charset.forName(name); } catch (UnsupportedCharsetException e) { // NOSONAR we use the default encoding instead } } boolean useReplacement = isUTF8(cs.name()); return new NioZipEncoding(cs, useReplacement); }