Java String Encode encodeURNComponent(String value)

Here you can find the source of encodeURNComponent(String value)

Description

Encode data to URN fragment.

License

Apache License

Parameter

Parameter Description
value value

Return

encoded urn fragment

Declaration

public static String encodeURNComponent(String value) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    /**// w  ww  .  java  2s  .c  o  m
     * Encode data to URN fragment.
     * <br/><b>NOTE:</b> similar to JavaScript's encodeURIComponent for basic ascii set
     *
     * @param value value
     * @return encoded urn fragment
     */
    public static String encodeURNComponent(String value) {
        try {
            return URLEncoder.encode(value, "UTF-8").replace("+", "%20").replace("%21", "!").replace("%27", "\'")
                    .replace("%28", "(").replace("%29", ")").replace("%7E", "~");
        } catch (UnsupportedEncodingException e) {
            // must not happen, utf-8 is part of java spec
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. encodeTextValue(char[] characters, int offset, int length, Writer writer)
  2. encodeThoroughly(String s)
  3. encodeToFlex(Object o)
  4. encodeToForm(Map msg)
  5. encodeToString(String s)
  6. encodeUTF8(String input, boolean keepSpaces)
  7. encodeUTF8(String s)
  8. encodeUTF8(String s)
  9. encodeValue(String dirtyValue)