@Test public void testHost() { assertEquals("[fec0::abcd%251]", UriComponent.decode("[fec0::abcd%251]", UriComponent.Type.HOST)); }
public static String decode(final String s, final Type t) { if (s == null) { throw new IllegalArgumentException(); } final int n = s.length(); if (n == 0) { return s; } if (s.indexOf('%') < 0) { if (t == Type.QUERY_PARAM) { if (s.indexOf('+') < 0) { return s; } } else { return s; } } else { if (n < 2) { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(1)); } if (s.charAt(n - 2) == '%') { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(n - 2)); } } if (t == null) { return decode(s, n); } switch (t) { case HOST: return decodeHost(s, n); case QUERY_PARAM: return decodeQueryParam(s, n); default: return decode(s, n); } }
UriComponent { public static String decode(final String s, final Type t) { if (s == null) { throw new IllegalArgumentException(); } final int n = s.length(); if (n == 0) { return s; } if (s.indexOf('%') < 0) { if (t == Type.QUERY_PARAM) { if (s.indexOf('+') < 0) { return s; } } else { return s; } } else { if (n < 2) { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(1)); } if (s.charAt(n - 2) == '%') { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(n - 2)); } } if (t == null) { return decode(s, n); } switch (t) { case HOST: return decodeHost(s, n); case QUERY_PARAM: return decodeQueryParam(s, n); default: return decode(s, n); } } }
UriComponent { public static String decode(final String s, final Type t) { if (s == null) { throw new IllegalArgumentException(); } final int n = s.length(); if (n == 0) { return s; } if (s.indexOf('%') < 0) { if (t == Type.QUERY_PARAM) { if (s.indexOf('+') < 0) { return s; } } else { return s; } } else { if (n < 2) { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(1)); } if (s.charAt(n - 2) == '%') { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(n - 2)); } } if (t == null) { return decode(s, n); } switch (t) { case HOST: return decodeHost(s, n); case QUERY_PARAM: return decodeQueryParam(s, n); default: return decode(s, n); } } private  UriComponent(); }
UriComponent { public static String decode(final String s, final Type t) { if (s == null) { throw new IllegalArgumentException(); } final int n = s.length(); if (n == 0) { return s; } if (s.indexOf('%') < 0) { if (t == Type.QUERY_PARAM) { if (s.indexOf('+') < 0) { return s; } } else { return s; } } else { if (n < 2) { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(1)); } if (s.charAt(n - 2) == '%') { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(n - 2)); } } if (t == null) { return decode(s, n); } switch (t) { case HOST: return decodeHost(s, n); case QUERY_PARAM: return decodeQueryParam(s, n); default: return decode(s, n); } } private  UriComponent(); static void validate(final String s, final Type t); static void validate(final String s, final Type t, final boolean template); static boolean valid(final String s, final Type t); static boolean valid(final String s, final Type t, final boolean template); static String contextualEncode(final String s, final Type t); static String contextualEncode(final String s, final Type t, final boolean template); static String encode(final String s, final Type t); static String encode(final String s, final Type t, final boolean template); static String encodeTemplateNames(String s); static String decode(final String s, final Type t); static MultivaluedMap<String, String> decodeQuery(final URI u, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decodeNames,
                                                             final boolean decodeValues); static List<PathSegment> decodePath(final URI u, final boolean decode); static List<PathSegment> decodePath(final String path, final boolean decode); static void decodePathSegment(final List<PathSegment> segments, final String segment, final boolean decode); static MultivaluedMap<String, String> decodeMatrix(final String pathSegment, final boolean decode); static boolean isHexCharacter(final char c); static String fullRelativeUri(final URI uri); }
UriComponent { public static String decode(final String s, final Type t) { if (s == null) { throw new IllegalArgumentException(); } final int n = s.length(); if (n == 0) { return s; } if (s.indexOf('%') < 0) { if (t == Type.QUERY_PARAM) { if (s.indexOf('+') < 0) { return s; } } else { return s; } } else { if (n < 2) { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(1)); } if (s.charAt(n - 2) == '%') { throw new IllegalArgumentException(LocalizationMessages.URI_COMPONENT_ENCODED_OCTET_MALFORMED(n - 2)); } } if (t == null) { return decode(s, n); } switch (t) { case HOST: return decodeHost(s, n); case QUERY_PARAM: return decodeQueryParam(s, n); default: return decode(s, n); } } private  UriComponent(); static void validate(final String s, final Type t); static void validate(final String s, final Type t, final boolean template); static boolean valid(final String s, final Type t); static boolean valid(final String s, final Type t, final boolean template); static String contextualEncode(final String s, final Type t); static String contextualEncode(final String s, final Type t, final boolean template); static String encode(final String s, final Type t); static String encode(final String s, final Type t, final boolean template); static String encodeTemplateNames(String s); static String decode(final String s, final Type t); static MultivaluedMap<String, String> decodeQuery(final URI u, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decode); static MultivaluedMap<String, String> decodeQuery(final String q, final boolean decodeNames,
                                                             final boolean decodeValues); static List<PathSegment> decodePath(final URI u, final boolean decode); static List<PathSegment> decodePath(final String path, final boolean decode); static void decodePathSegment(final List<PathSegment> segments, final String segment, final boolean decode); static MultivaluedMap<String, String> decodeMatrix(final String pathSegment, final boolean decode); static boolean isHexCharacter(final char c); static String fullRelativeUri(final URI uri);  }