Package helma.util

Class UrlEncoded

java.lang.Object
helma.util.UrlEncoded

public final class UrlEncoded extends Object
A proxy to java.net.URLEncoder which only encodes when there is actual work to do. This is necessary because URLEncoder is quite inefficient (e.g. it preallocates buffers and stuff), and we call it often with short string that don't need encoding.
  • Constructor Details

    • UrlEncoded

      public UrlEncoded()
  • Method Details

    • encode

      public static String encode(String str, String encoding) throws UnsupportedEncodingException
      URL-encodes a string using the given encoding, or return it unchanged if no encoding was necessary.
      Parameters:
      str - The string to be URL-encoded
      encoding - the encoding to use
      Returns:
      the URL-encoded string, or str if no encoding necessary
      Throws:
      UnsupportedEncodingException - encoding is not supported
    • decode

      public static String decode(String str, String encoding) throws UnsupportedEncodingException
      URL-decode a string using the given encoding, or return it unchanged if no encoding was necessary.
      Parameters:
      str - The string to be URL-decoded
      encoding - the encoding to use
      Returns:
      the URL-decoded string, or str if no decoding necessary
      Throws:
      UnsupportedEncodingException - encoding is not supported