Class UrlDecoder


  • public final class UrlDecoder
    extends java.lang.Object
    Utilities for decoding percent encoded characters.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int decode​(java.io.InputStream is, java.lang.StringBuilder sb)
      Returns the character from the stream, which encode as "%ab" (single byte UTF-8) or "%ab%cd" (two byte ).
      • Methods inherited from class java.lang.Object

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

      • decode

        public static int decode​(java.io.InputStream is,
                                 java.lang.StringBuilder sb)
                          throws java.io.IOException
        Returns the character from the stream, which encode as "%ab" (single byte UTF-8) or "%ab%cd" (two byte ). The initial % mark has been already reed. The character is represented as %ab where "a" and "b" is a hexa character (0-9, A-F) if the value of (a * 16 + b) > 127 the next 3 bytes will be read as the second byte of a two-byte UTF-8 char. When a character encoding problem is encountered, returns -1 (ffff). Since there is no unicode character with this code, this does not cause problems. When a percentage encoded UTF-16 Surrogate Pair is encountered (integer value above 0xFFFF) this method calculates the head and trail surrogate code point for the Unicode character. The head code point is inserted into the StringBuilder and the tail surrogate is returned. If the code doesn't denote a surrogate pair (value is less than 0xFFFF) simply return it.
        Parameters:
        is - the InputStream.
        sb - the StringBuilder.
        Returns:
        the original code (if code's value less than 0xFFFF) or the tail surrogate code point of the surrogate pair.
        Throws:
        java.io.IOException - if an I/O error occurred reading is.