Class ZipEncodingHelper


  • public abstract class ZipEncodingHelper
    extends java.lang.Object
    Static helper functions for robustly encoding file names in ZIP files.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ZipEncoding getZipEncoding​(java.lang.String name)
      Instantiates a ZIP encoding.
      static ZipEncoding getZipEncoding​(java.nio.charset.Charset charset)
      Instantiates a ZIP encoding.
      (package private) static java.nio.ByteBuffer growBufferBy​(java.nio.ByteBuffer buffer, int increment)  
      (package private) static boolean isUTF8​(java.lang.String charsetName)
      Tests whether a given encoding is UTF-8.
      (package private) static boolean isUTF8​(java.nio.charset.Charset charset)
      Tests whether a given encoding is UTF-8.
      private static boolean isUTF8Alias​(java.lang.String actual)  
      private static java.nio.charset.Charset toSafeCharset​(java.lang.String name)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ZIP_ENCODING_UTF_8

        static final ZipEncoding ZIP_ENCODING_UTF_8
        UTF-8.
    • Constructor Detail

      • ZipEncodingHelper

        public ZipEncodingHelper()
    • Method Detail

      • getZipEncoding

        public static ZipEncoding getZipEncoding​(java.nio.charset.Charset charset)
        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.

        If the requested character set cannot be found, the platform default will be used instead.

        Parameters:
        charset - The charset of the ZIP encoding. Specify null for the platform's default encoding.
        Returns:
        A ZIP encoding for the given encoding name.
        Since:
        1.26.0
      • getZipEncoding

        public static ZipEncoding getZipEncoding​(java.lang.String name)
        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.

        If the requested character set cannot be found, the platform default will be used instead.

        Parameters:
        name - The name of the ZIP encoding. Specify null for the platform's default encoding.
        Returns:
        A ZIP encoding for the given encoding name.
      • growBufferBy

        static java.nio.ByteBuffer growBufferBy​(java.nio.ByteBuffer buffer,
                                                int increment)
      • isUTF8

        static boolean isUTF8​(java.nio.charset.Charset charset)
        Tests whether a given encoding is UTF-8. If the given name is null, then check the platform's default encoding.
        Parameters:
        charset - If the given charset is null, then check the platform's default encoding.
      • isUTF8

        static boolean isUTF8​(java.lang.String charsetName)
        Tests whether a given encoding is UTF-8. If the given name is null, then check the platform's default encoding.
        Parameters:
        charsetName - If the given name is null, then check the platform's default encoding.
      • isUTF8Alias

        private static boolean isUTF8Alias​(java.lang.String actual)
      • toSafeCharset

        private static java.nio.charset.Charset toSafeCharset​(java.lang.String name)