@Test public void testDecoding() { final String url = "/testing.do;jsessionid=67CFB560B6EC2677D51814A2A2B16B24"; long time = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 1000000; i++) { try { HDIVUtil.decodeValue(sb, url, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } System.out.println("Time:" + (System.currentTimeMillis() - time)); time = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { try { URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } System.out.println("Time:" + (System.currentTimeMillis() - time)); }
public static String decodeValue(final StringBuilder sb, final String s, final String enc) throws UnsupportedEncodingException { sb.setLength(0); boolean needToChange = false; int numChars = s.length(); int i = 0; if (enc.length() == 0) { throw new UnsupportedEncodingException("URLDecoder: empty string enc parameter"); } char c; byte[] bytes = null; while (i < numChars) { c = s.charAt(i); switch (c) { case '+': sb.append(' '); i++; needToChange = true; break; case '%': try { if (bytes == null) { bytes = new byte[(numChars - i) / 3]; } int pos = 0; while (i + 2 < numChars && c == '%') { int v = Integer.parseInt(s.substring(i + 1, i + 3), 16); if (v < 0) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); } bytes[pos++] = (byte) v; i += 3; if (i < numChars) { c = s.charAt(i); } } if (i < numChars && c == '%') { throw new IllegalArgumentException("URLDecoder: Incomplete trailing escape (%) pattern"); } sb.append(new String(bytes, 0, pos, enc)); } catch (NumberFormatException e) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - " + e.getMessage()); } needToChange = true; break; default: sb.append(c); i++; break; } } return needToChange ? sb.toString() : s; }
HDIVUtil { public static String decodeValue(final StringBuilder sb, final String s, final String enc) throws UnsupportedEncodingException { sb.setLength(0); boolean needToChange = false; int numChars = s.length(); int i = 0; if (enc.length() == 0) { throw new UnsupportedEncodingException("URLDecoder: empty string enc parameter"); } char c; byte[] bytes = null; while (i < numChars) { c = s.charAt(i); switch (c) { case '+': sb.append(' '); i++; needToChange = true; break; case '%': try { if (bytes == null) { bytes = new byte[(numChars - i) / 3]; } int pos = 0; while (i + 2 < numChars && c == '%') { int v = Integer.parseInt(s.substring(i + 1, i + 3), 16); if (v < 0) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); } bytes[pos++] = (byte) v; i += 3; if (i < numChars) { c = s.charAt(i); } } if (i < numChars && c == '%') { throw new IllegalArgumentException("URLDecoder: Incomplete trailing escape (%) pattern"); } sb.append(new String(bytes, 0, pos, enc)); } catch (NumberFormatException e) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - " + e.getMessage()); } needToChange = true; break; default: sb.append(c); i++; break; } } return needToChange ? sb.toString() : s; } }
HDIVUtil { public static String decodeValue(final StringBuilder sb, final String s, final String enc) throws UnsupportedEncodingException { sb.setLength(0); boolean needToChange = false; int numChars = s.length(); int i = 0; if (enc.length() == 0) { throw new UnsupportedEncodingException("URLDecoder: empty string enc parameter"); } char c; byte[] bytes = null; while (i < numChars) { c = s.charAt(i); switch (c) { case '+': sb.append(' '); i++; needToChange = true; break; case '%': try { if (bytes == null) { bytes = new byte[(numChars - i) / 3]; } int pos = 0; while (i + 2 < numChars && c == '%') { int v = Integer.parseInt(s.substring(i + 1, i + 3), 16); if (v < 0) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); } bytes[pos++] = (byte) v; i += 3; if (i < numChars) { c = s.charAt(i); } } if (i < numChars && c == '%') { throw new IllegalArgumentException("URLDecoder: Incomplete trailing escape (%) pattern"); } sb.append(new String(bytes, 0, pos, enc)); } catch (NumberFormatException e) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - " + e.getMessage()); } needToChange = true; break; default: sb.append(c); i++; break; } } return needToChange ? sb.toString() : s; } private  HDIVUtil(); }
HDIVUtil { public static String decodeValue(final StringBuilder sb, final String s, final String enc) throws UnsupportedEncodingException { sb.setLength(0); boolean needToChange = false; int numChars = s.length(); int i = 0; if (enc.length() == 0) { throw new UnsupportedEncodingException("URLDecoder: empty string enc parameter"); } char c; byte[] bytes = null; while (i < numChars) { c = s.charAt(i); switch (c) { case '+': sb.append(' '); i++; needToChange = true; break; case '%': try { if (bytes == null) { bytes = new byte[(numChars - i) / 3]; } int pos = 0; while (i + 2 < numChars && c == '%') { int v = Integer.parseInt(s.substring(i + 1, i + 3), 16); if (v < 0) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); } bytes[pos++] = (byte) v; i += 3; if (i < numChars) { c = s.charAt(i); } } if (i < numChars && c == '%') { throw new IllegalArgumentException("URLDecoder: Incomplete trailing escape (%) pattern"); } sb.append(new String(bytes, 0, pos, enc)); } catch (NumberFormatException e) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - " + e.getMessage()); } needToChange = true; break; default: sb.append(c); i++; break; } } return needToChange ? sb.toString() : s; } private  HDIVUtil(); static boolean isServlet3(); static IApplication getApplication(final ServletContext servletContext); static void setApplication(final IApplication newApplication, final ServletContext servletContext); static HDIVConfig getHDIVConfig(final ServletContext servletContext); static void setHDIVConfig(final HDIVConfig hdivConfig, final ServletContext servletContext); static LinkUrlProcessor getLinkUrlProcessor(final ServletContext servletContext); static void setLinkUrlProcessor(final LinkUrlProcessor urlProcessor, final ServletContext servletContext); static FormUrlProcessor getFormUrlProcessor(final ServletContext servletContext); static void setFormUrlProcessor(final FormUrlProcessor urlProcessor, final ServletContext servletContext); static MessageSource getMessageSource(final HttpServletRequest request); static MessageSource getMessageSource(final ServletContext servletContext); static void setMessageSource(final MessageSource msgSource, final ServletContext servletContext); static String getMessage(final HttpServletRequest request, final String key); static String getMessage(final HttpServletRequest request, final String key, final String o); static String getMessage(final HttpServletRequest request, final String key, final String o, final Locale userLocale); @SuppressWarnings("deprecation") static RequestContextHolder getRequestContext(final ServletRequest request); static HttpServletRequest getCurrentHttpRequest(); @Deprecated static String getHdivState(final HttpServletRequest request); @Deprecated static void setHdivState(final HttpServletRequest request, final String value); static boolean isObfuscatedTarget(final String target); static String createRandomToken(final int n); static String stripSession(final String url); static String stripAndFillSessionData(final String url, final UrlDataImpl urldata); @SuppressWarnings("unchecked") static T getNativeRequest(final ServletRequest request, final Class<T> requiredType); static ApplicationContext findWebApplicationContext(final ServletContext sc); static void registerApplicationContext(final ApplicationContext context, final ServletContext scontext); static String getDecodedValue(final StringBuilder sb, final String value, final String charEncoding); static boolean isTheSameEncodedValue(final String parameterValue, final String value); static String decodeValue(final StringBuilder sb, final String s, final String enc); static boolean isPathVariable(final String uriTemplate, final String variable); static boolean isMultipartContent(final HttpServletRequest request); @Deprecated static String getRequestURI(final HttpServletRequest request); @Deprecated static void setRequestURI(final String requestURI, final HttpServletRequest request); @Deprecated static Integer getCurrentPageId(final ServletRequest request); @Deprecated static void setCurrentPageId(final Integer pageId, final ServletRequest request); @Deprecated static String getModifyHdivStateParameterName(final HttpServletRequest request); @Deprecated static void setModifyHdivStateParameterName(final HttpServletRequest request, final String parameterName); @Deprecated static String getHdivStateParameterName(final HttpServletRequest request); @Deprecated static void setHdivStateParameterName(final HttpServletRequest request, final String parameterName); @Deprecated static String getBaseURL(final ServletRequest request); @Deprecated static void setBaseURL(final String baseURL, final ServletRequest request); @Deprecated static IDataComposer getDataComposer(final ServletRequest request); @Deprecated static void setDataComposer(final IDataComposer newDataComposer, final HttpServletRequest request); @Deprecated static void removeDataComposer(final HttpServletRequest request); static String replaceOnce(final String text, final String searchString, final String replacement); static String replace(final String text, String searchString, final String replacement, int max, final boolean ignoreCase); @SuppressWarnings({ "deprecation" }) static String getCustomImage(final HttpServletRequest request); static boolean checkCustomImage(final HttpServletRequest request); static boolean isButtonType(final String type); static boolean isNonConfidentialType(final String type); static List<T> findBeansInWebApplicationContext(final Class<T> beanType); static List<WebApplicationContext> findWebApplicationContextWithBeans(final Class<?> beanType); }
HDIVUtil { public static String decodeValue(final StringBuilder sb, final String s, final String enc) throws UnsupportedEncodingException { sb.setLength(0); boolean needToChange = false; int numChars = s.length(); int i = 0; if (enc.length() == 0) { throw new UnsupportedEncodingException("URLDecoder: empty string enc parameter"); } char c; byte[] bytes = null; while (i < numChars) { c = s.charAt(i); switch (c) { case '+': sb.append(' '); i++; needToChange = true; break; case '%': try { if (bytes == null) { bytes = new byte[(numChars - i) / 3]; } int pos = 0; while (i + 2 < numChars && c == '%') { int v = Integer.parseInt(s.substring(i + 1, i + 3), 16); if (v < 0) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - negative value"); } bytes[pos++] = (byte) v; i += 3; if (i < numChars) { c = s.charAt(i); } } if (i < numChars && c == '%') { throw new IllegalArgumentException("URLDecoder: Incomplete trailing escape (%) pattern"); } sb.append(new String(bytes, 0, pos, enc)); } catch (NumberFormatException e) { throw new IllegalArgumentException("URLDecoder: Illegal hex characters in escape (%) pattern - " + e.getMessage()); } needToChange = true; break; default: sb.append(c); i++; break; } } return needToChange ? sb.toString() : s; } private  HDIVUtil(); static boolean isServlet3(); static IApplication getApplication(final ServletContext servletContext); static void setApplication(final IApplication newApplication, final ServletContext servletContext); static HDIVConfig getHDIVConfig(final ServletContext servletContext); static void setHDIVConfig(final HDIVConfig hdivConfig, final ServletContext servletContext); static LinkUrlProcessor getLinkUrlProcessor(final ServletContext servletContext); static void setLinkUrlProcessor(final LinkUrlProcessor urlProcessor, final ServletContext servletContext); static FormUrlProcessor getFormUrlProcessor(final ServletContext servletContext); static void setFormUrlProcessor(final FormUrlProcessor urlProcessor, final ServletContext servletContext); static MessageSource getMessageSource(final HttpServletRequest request); static MessageSource getMessageSource(final ServletContext servletContext); static void setMessageSource(final MessageSource msgSource, final ServletContext servletContext); static String getMessage(final HttpServletRequest request, final String key); static String getMessage(final HttpServletRequest request, final String key, final String o); static String getMessage(final HttpServletRequest request, final String key, final String o, final Locale userLocale); @SuppressWarnings("deprecation") static RequestContextHolder getRequestContext(final ServletRequest request); static HttpServletRequest getCurrentHttpRequest(); @Deprecated static String getHdivState(final HttpServletRequest request); @Deprecated static void setHdivState(final HttpServletRequest request, final String value); static boolean isObfuscatedTarget(final String target); static String createRandomToken(final int n); static String stripSession(final String url); static String stripAndFillSessionData(final String url, final UrlDataImpl urldata); @SuppressWarnings("unchecked") static T getNativeRequest(final ServletRequest request, final Class<T> requiredType); static ApplicationContext findWebApplicationContext(final ServletContext sc); static void registerApplicationContext(final ApplicationContext context, final ServletContext scontext); static String getDecodedValue(final StringBuilder sb, final String value, final String charEncoding); static boolean isTheSameEncodedValue(final String parameterValue, final String value); static String decodeValue(final StringBuilder sb, final String s, final String enc); static boolean isPathVariable(final String uriTemplate, final String variable); static boolean isMultipartContent(final HttpServletRequest request); @Deprecated static String getRequestURI(final HttpServletRequest request); @Deprecated static void setRequestURI(final String requestURI, final HttpServletRequest request); @Deprecated static Integer getCurrentPageId(final ServletRequest request); @Deprecated static void setCurrentPageId(final Integer pageId, final ServletRequest request); @Deprecated static String getModifyHdivStateParameterName(final HttpServletRequest request); @Deprecated static void setModifyHdivStateParameterName(final HttpServletRequest request, final String parameterName); @Deprecated static String getHdivStateParameterName(final HttpServletRequest request); @Deprecated static void setHdivStateParameterName(final HttpServletRequest request, final String parameterName); @Deprecated static String getBaseURL(final ServletRequest request); @Deprecated static void setBaseURL(final String baseURL, final ServletRequest request); @Deprecated static IDataComposer getDataComposer(final ServletRequest request); @Deprecated static void setDataComposer(final IDataComposer newDataComposer, final HttpServletRequest request); @Deprecated static void removeDataComposer(final HttpServletRequest request); static String replaceOnce(final String text, final String searchString, final String replacement); static String replace(final String text, String searchString, final String replacement, int max, final boolean ignoreCase); @SuppressWarnings({ "deprecation" }) static String getCustomImage(final HttpServletRequest request); static boolean checkCustomImage(final HttpServletRequest request); static boolean isButtonType(final String type); static boolean isNonConfidentialType(final String type); static List<T> findBeansInWebApplicationContext(final Class<T> beanType); static List<WebApplicationContext> findWebApplicationContextWithBeans(final Class<?> beanType); static final Pattern intPattern; }