annotate src/org/eclipse/jetty/util/UrlEncoded.java @ 1074:6b7ff30bb990

rename putQ() to put()
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 10 Nov 2016 02:37:15 -0700
parents 9d357b9e4bcb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.util;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import static org.eclipse.jetty.util.TypeUtil.convertHexDigit;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.io.InputStream;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 import java.io.InputStreamReader;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import java.io.StringWriter;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import java.io.UnsupportedEncodingException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import java.util.Iterator;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 import java.util.Map;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
32 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
33 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 /** Handles coding of MIME "x-www-form-urlencoded".
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 * This class handles the encoding and decoding for either
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 * the query string of a URL or the _content of a POST HTTP request.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 * <h4>Notes</h4>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * The UTF-8 charset is assumed, unless otherwise defined by either
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 * passing a parameter or setting the "org.eclipse.jetty.util.UrlEncoding.charset"
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 * System property.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 * The hashtable either contains String single values, vectors
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 * of String or arrays of Strings.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 * <p>
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 * This class is only partially synchronised. In particular, simple
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 * get operations are not protected from concurrent updates.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 * @see java.net.URLEncoder
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 public class UrlEncoded extends MultiMap implements Cloneable
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 {
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 private static final Logger LOG = LoggerFactory.getLogger(UrlEncoded.class);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 public static final String ENCODING = System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset",StringUtil.__UTF8);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 public UrlEncoded(UrlEncoded url)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 super(url);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 public UrlEncoded()
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69 super(6);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 public UrlEncoded(String s)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 super(6);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 decode(s,ENCODING);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 public UrlEncoded(String s, String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 super(6);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 decode(s,charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 public void decode(String query)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 decodeTo(query,this,ENCODING,-1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 /* ----------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 public void decode(String query,String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
95 decodeTo(query,this,charset,-1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 /** Encode Hashtable with % encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 public String encode()
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 return encode(ENCODING,false);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 /** Encode Hashtable with % encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 public String encode(String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 return encode(charset,false);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 /** Encode Hashtable with % encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 * @param equalsForNullValue if True, then an '=' is always used, even
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 * for parameters without a value. e.g. "blah?a=&b=&c=".
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
118 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 public synchronized String encode(String charset, boolean equalsForNullValue)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 return encode(this,charset,equalsForNullValue);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 /** Encode Hashtable with % encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 * @param equalsForNullValue if True, then an '=' is always used, even
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 * for parameters without a value. e.g. "blah?a=&b=&c=".
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 public static String encode(MultiMap map, String charset, boolean equalsForNullValue)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 if (charset==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
132 charset=ENCODING;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 StringBuilder result = new StringBuilder(128);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 Iterator iter = map.entrySet().iterator();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 while(iter.hasNext())
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 Map.Entry entry = (Map.Entry)iter.next();
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 String key = entry.getKey().toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 Object list = entry.getValue();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 int s=LazyList.size(list);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
145 if (s==0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 result.append(encodeString(key,charset));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 if(equalsForNullValue)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 result.append('=');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 for (int i=0;i<s;i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 if (i>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 result.append('&');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 Object val=LazyList.get(list,i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 result.append(encodeString(key,charset));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
160 if (val!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 String str=val.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 if (str.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
165 result.append('=');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 result.append(encodeString(str,charset));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 else if (equalsForNullValue)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 result.append('=');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 else if (equalsForNullValue)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 result.append('=');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
174 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 if (iter.hasNext())
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 result.append('&');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 return result.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
183 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 * @param content the string containing the encoded parameters
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 public static void decodeTo(String content, MultiMap map, String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 decodeTo(content,map,charset,-1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
192 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 * @param content the string containing the encoded parameters
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 public static void decodeTo(String content, MultiMap map, String charset, int maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 if (charset==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 charset=ENCODING;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201 synchronized(map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 String key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 String value = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 int mark=-1;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 boolean encoded=false;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 for (int i=0;i<content.length();i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 char c = content.charAt(i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210 switch (c)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 case '&':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 int l=i-mark-1;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 value = l==0?"":
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 (encoded?decodeString(content,mark+1,l,charset):content.substring(mark+1,i));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 mark=i;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
217 encoded=false;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 else if (value!=null&&value.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224 map.add(value,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 value=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228 if (maxKeys>0 && map.size()>maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 throw new IllegalStateException("Form too many keys");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 case '=':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 if (key!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 key = encoded?decodeString(content,mark+1,i-mark-1,charset):content.substring(mark+1,i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 mark=i;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 encoded=false;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 case '+':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 encoded=true;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 case '%':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 encoded=true;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
249 int l=content.length()-mark-1;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
250 value = l==0?"":(encoded?decodeString(content,mark+1,l,charset):content.substring(mark+1));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
251 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
252 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
253 else if (mark<content.length())
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
254 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
255 key = encoded
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
256 ?decodeString(content,mark+1,content.length()-mark-1,charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
257 :content.substring(mark+1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
258 if (key != null && key.length() > 0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
259 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
260 map.add(key,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
261 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
262 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
263 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
264 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
265
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
266 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
267 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
268 * @param raw the byte[] containing the encoded parameters
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
269 * @param offset the offset within raw to decode from
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
270 * @param length the length of the section to decode
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
271 * @param map the {@link MultiMap} to populate
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
272 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
273 public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
274 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
275 decodeUtf8To(raw,offset,length,map,new Utf8StringBuilder());
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
276 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
278 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
279 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
280 * @param raw the byte[] containing the encoded parameters
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
281 * @param offset the offset within raw to decode from
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
282 * @param length the length of the section to decode
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
283 * @param map the {@link MultiMap} to populate
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
284 * @param buffer the buffer to decode into
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
285 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
286 public static void decodeUtf8To(byte[] raw,int offset, int length, MultiMap map,Utf8StringBuilder buffer)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
287 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
288 synchronized(map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
289 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
290 String key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
291 String value = null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
292
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
293 // TODO cache of parameter names ???
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
294 int end=offset+length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
295 for (int i=offset;i<end;i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
296 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
297 byte b=raw[i];
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
298 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
299 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
300 switch ((char)(0xff&b))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
301 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
302 case '&':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
303 value = buffer.length()==0?"":buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
304 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
305 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
306 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
307 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
308 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
309 else if (value!=null&&value.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
310 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
311 map.add(value,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
312 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
313 key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
314 value=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
315 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
316
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
317 case '=':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
318 if (key!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
319 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
320 buffer.append(b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
321 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
322 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
323 key = buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
324 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
325 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
326
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
327 case '+':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
328 buffer.append((byte)' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
329 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
330
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
331 case '%':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
332 if (i+2<end)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
333 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
334 if ('u'==raw[i+1])
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
335 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
336 i++;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
337 if (i+4<end)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
338 buffer.getStringBuilder().append(Character.toChars((convertHexDigit(raw[++i])<<12) +(convertHexDigit(raw[++i])<<8) + (convertHexDigit(raw[++i])<<4) +convertHexDigit(raw[++i])));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
339 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
340 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
341 buffer.getStringBuilder().append(Utf8Appendable.REPLACEMENT);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
342 i=end;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
343 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
344 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
345 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
346 buffer.append((byte)((convertHexDigit(raw[++i])<<4) + convertHexDigit(raw[++i])));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
347 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
348 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
349 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
350 buffer.getStringBuilder().append(Utf8Appendable.REPLACEMENT);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
351 i=end;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
352 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
353 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
354
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
355 default:
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
356 buffer.append(b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
357 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
358 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
359 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
360 catch(NotUtf8Exception e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
361 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
362 LOG.warn(e.toString());
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
363 LOG.debug("",e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
364 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
365 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
366
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
367 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
368 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
369 value = buffer.length()==0?"":buffer.toReplacedString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
370 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
371 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
372 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
373 else if (buffer.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
374 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
375 map.add(buffer.toReplacedString(),"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
376 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
377 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
378 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
379
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
380 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
381 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
382 * @param in InputSteam to read
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
383 * @param map MultiMap to add parameters to
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
384 * @param maxLength maximum number of keys to read or -1 for no limit
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
385 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
386 public static void decode88591To(InputStream in, MultiMap map, int maxLength, int maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
387 throws IOException
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
388 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
389 synchronized(map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
390 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
391 StringBuffer buffer = new StringBuffer();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
392 String key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
393 String value = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
394
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
395 int b;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
396
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
397 // TODO cache of parameter names ???
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
398 int totalLength=0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
399 while ((b=in.read())>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
400 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
401 switch ((char) b)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
402 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
403 case '&':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
404 value = buffer.length()==0?"":buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
405 buffer.setLength(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
406 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
407 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
408 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
409 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
410 else if (value!=null&&value.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
411 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
412 map.add(value,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
413 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
414 key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
415 value=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
416 if (maxKeys>0 && map.size()>maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
417 throw new IllegalStateException("Form too many keys");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
418 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
419
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
420 case '=':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
421 if (key!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
422 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
423 buffer.append((char)b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
424 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
425 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
426 key = buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
427 buffer.setLength(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
428 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
429
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
430 case '+':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
431 buffer.append(' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
432 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
433
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
434 case '%':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
435 int code0=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
436 if ('u'==code0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
437 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
438 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
439 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
440 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
441 int code2=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
442 if (code2>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
443 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
444 int code3=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
445 if (code3>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
446 buffer.append(Character.toChars((convertHexDigit(code0)<<12)+(convertHexDigit(code1)<<8)+(convertHexDigit(code2)<<4)+convertHexDigit(code3)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
447 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
448 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
449 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
450 else if (code0>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
451 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
452 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
453 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
454 buffer.append((char)((convertHexDigit(code0)<<4)+convertHexDigit(code1)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
455 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
456 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
457
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
458 default:
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
459 buffer.append((char)b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
460 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
461 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
462 if (maxLength>=0 && (++totalLength > maxLength))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
463 throw new IllegalStateException("Form too large");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
464 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
465
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
466 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
467 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
468 value = buffer.length()==0?"":buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
469 buffer.setLength(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
470 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
471 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
472 else if (buffer.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
473 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
474 map.add(buffer.toString(), "");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
475 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
476 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
477 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
478
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
479 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
480 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
481 * @param in InputSteam to read
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
482 * @param map MultiMap to add parameters to
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
483 * @param maxLength maximum number of keys to read or -1 for no limit
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
484 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
485 public static void decodeUtf8To(InputStream in, MultiMap map, int maxLength, int maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
486 throws IOException
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
487 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
488 synchronized(map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
489 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
490 Utf8StringBuilder buffer = new Utf8StringBuilder();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
491 String key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
492 String value = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
493
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
494 int b;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
495
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
496 // TODO cache of parameter names ???
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
497 int totalLength=0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
498 while ((b=in.read())>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
499 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
500 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
501 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
502 switch ((char) b)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
503 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
504 case '&':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
505 value = buffer.length()==0?"":buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
506 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
507 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
508 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
509 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
510 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
511 else if (value!=null&&value.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
512 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
513 map.add(value,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
514 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
515 key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
516 value=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
517 if (maxKeys>0 && map.size()>maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
518 throw new IllegalStateException("Form too many keys");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
519 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
520
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
521 case '=':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
522 if (key!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
523 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
524 buffer.append((byte)b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
525 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
526 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
527 key = buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
528 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
529 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
530
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
531 case '+':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
532 buffer.append((byte)' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
533 break;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
534
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
535 case '%':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
536 int code0=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
537 if ('u'==code0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
538 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
539 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
540 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
541 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
542 int code2=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
543 if (code2>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
544 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
545 int code3=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
546 if (code3>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
547 buffer.getStringBuilder().append(Character.toChars((convertHexDigit(code0)<<12)+(convertHexDigit(code1)<<8)+(convertHexDigit(code2)<<4)+convertHexDigit(code3)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
548 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
549 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
550 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
551 else if (code0>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
552 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
553 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
554 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
555 buffer.append((byte)((convertHexDigit(code0)<<4)+convertHexDigit(code1)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
556 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
557 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
558
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
559 default:
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
560 buffer.append((byte)b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
561 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
562 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
563 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
564 catch(NotUtf8Exception e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
565 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
566 LOG.warn(e.toString());
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
567 LOG.debug("",e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
568 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
569 if (maxLength>=0 && (++totalLength > maxLength))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
570 throw new IllegalStateException("Form too large");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
571 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
572
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
573 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
574 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
575 value = buffer.length()==0?"":buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
576 buffer.reset();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
577 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
578 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
579 else if (buffer.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
580 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
581 map.add(buffer.toString(), "");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
582 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
583 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
584 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
585
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
586 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
587 public static void decodeUtf16To(InputStream in, MultiMap map, int maxLength, int maxKeys) throws IOException
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
588 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
589 InputStreamReader input = new InputStreamReader(in,StringUtil.__UTF16);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
590 StringWriter buf = new StringWriter(8192);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
591 IO.copy(input,buf,maxLength);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
592
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
593 decodeTo(buf.getBuffer().toString(),map,StringUtil.__UTF16,maxKeys);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
594 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
595
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
596 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
597 /** Decoded parameters to Map.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
598 * @param in the stream containing the encoded parameters
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
599 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
600 public static void decodeTo(InputStream in, MultiMap map, String charset, int maxLength, int maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
601 throws IOException
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
602 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
603 //no charset present, use the configured default
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
604 if (charset==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
605 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
606 charset=ENCODING;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
607 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
608
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
609 if (StringUtil.__UTF8.equalsIgnoreCase(charset))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
610 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
611 decodeUtf8To(in,map,maxLength,maxKeys);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
612 return;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
613 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
614
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
615 if (StringUtil.__ISO_8859_1.equals(charset))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
616 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
617 decode88591To(in,map,maxLength,maxKeys);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
618 return;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
619 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
620
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
621 if (StringUtil.__UTF16.equalsIgnoreCase(charset)) // Should be all 2 byte encodings
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
622 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
623 decodeUtf16To(in,map,maxLength,maxKeys);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
624 return;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
625 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
626
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
627
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
628 synchronized(map)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
629 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
630 String key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
631 String value = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
632
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
633 int c;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
634
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
635 int totalLength = 0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
636 ByteArrayOutputStream2 output = new ByteArrayOutputStream2();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
637
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
638 int size=0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
639
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
640 while ((c=in.read())>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
641 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
642 switch ((char) c)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
643 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
644 case '&':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
645 size=output.size();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
646 value = size==0?"":output.toString(charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
647 output.setCount(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
648 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
649 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
650 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
651 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
652 else if (value!=null&&value.length()>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
653 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
654 map.add(value,"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
655 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
656 key = null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
657 value=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
658 if (maxKeys>0 && map.size()>maxKeys)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
659 throw new IllegalStateException("Form too many keys");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
660 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
661 case '=':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
662 if (key!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
663 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
664 output.write(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
665 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
666 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
667 size=output.size();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
668 key = size==0?"":output.toString(charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
669 output.setCount(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
670 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
671 case '+':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
672 output.write(' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
673 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
674 case '%':
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
675 int code0=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
676 if ('u'==code0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
677 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
678 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
679 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
680 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
681 int code2=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
682 if (code2>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
683 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
684 int code3=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
685 if (code3>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
686 output.write(new String(Character.toChars((convertHexDigit(code0)<<12)+(convertHexDigit(code1)<<8)+(convertHexDigit(code2)<<4)+convertHexDigit(code3))).getBytes(charset));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
687 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
688 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
689
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
690 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
691 else if (code0>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
692 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
693 int code1=in.read();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
694 if (code1>=0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
695 output.write((convertHexDigit(code0)<<4)+convertHexDigit(code1));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
696 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
697 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
698 default:
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
699 output.write(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
700 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
701 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
702
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
703 totalLength++;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
704 if (maxLength>=0 && totalLength > maxLength)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
705 throw new IllegalStateException("Form too large");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
706 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
707
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
708 size=output.size();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
709 if (key != null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
710 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
711 value = size==0?"":output.toString(charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
712 output.setCount(0);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
713 map.add(key,value);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
714 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
715 else if (size>0)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
716 map.add(output.toString(charset),"");
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
717 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
718 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
719
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
720 /* -------------------------------------------------------------- */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
721 /** Decode String with % encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
722 * This method makes the assumption that the majority of calls
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
723 * will need no decoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
724 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
725 public static String decodeString(String encoded,int offset,int length,String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
726 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
727 if (charset==null || StringUtil.isUTF8(charset))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
728 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
729 Utf8StringBuffer buffer=null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
730
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
731 for (int i=0;i<length;i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
732 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
733 char c = encoded.charAt(offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
734 if (c<0||c>0xff)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
735 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
736 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
737 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
738 buffer=new Utf8StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
739 buffer.getStringBuffer().append(encoded,offset,offset+i+1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
740 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
741 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
742 buffer.getStringBuffer().append(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
743 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
744 else if (c=='+')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
745 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
746 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
747 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
748 buffer=new Utf8StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
749 buffer.getStringBuffer().append(encoded,offset,offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
750 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
751
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
752 buffer.getStringBuffer().append(' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
753 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
754 else if (c=='%')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
755 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
756 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
757 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
758 buffer=new Utf8StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
759 buffer.getStringBuffer().append(encoded,offset,offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
760 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
761
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
762 if ((i+2)<length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
763 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
764 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
765 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
766 if ('u'==encoded.charAt(offset+i+1))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
767 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
768 if((i+5)<length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
769 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
770 int o=offset+i+2;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
771 i+=5;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
772 String unicode = new String(Character.toChars(TypeUtil.parseInt(encoded,o,4,16)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
773 buffer.getStringBuffer().append(unicode);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
774 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
775 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
776 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
777 i=length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
778 buffer.getStringBuffer().append(Utf8Appendable.REPLACEMENT);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
779 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
780 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
781 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
782 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
783 int o=offset+i+1;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
784 i+=2;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
785 byte b=(byte)TypeUtil.parseInt(encoded,o,2,16);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
786 buffer.append(b);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
787 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
788 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
789 catch(NotUtf8Exception e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
790 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
791 LOG.warn(e.toString());
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
792 LOG.debug("",e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
793 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
794 catch(NumberFormatException nfe)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
795 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
796 LOG.debug("",nfe);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
797 buffer.getStringBuffer().append(Utf8Appendable.REPLACEMENT);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
798 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
799 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
800 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
801 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
802 buffer.getStringBuffer().append(Utf8Appendable.REPLACEMENT);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
803 i=length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
804 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
805 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
806 else if (buffer!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
807 buffer.getStringBuffer().append(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
808 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
809
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
810 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
811 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
812 if (offset==0 && encoded.length()==length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
813 return encoded;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
814 return encoded.substring(offset,offset+length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
815 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
816
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
817 return buffer.toReplacedString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
818 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
819 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
820 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
821 StringBuffer buffer=null;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
822
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
823 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
824 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
825 for (int i=0;i<length;i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
826 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
827 char c = encoded.charAt(offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
828 if (c<0||c>0xff)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
829 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
830 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
831 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
832 buffer=new StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
833 buffer.append(encoded,offset,offset+i+1);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
834 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
835 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
836 buffer.append(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
837 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
838 else if (c=='+')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
839 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
840 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
841 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
842 buffer=new StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
843 buffer.append(encoded,offset,offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
844 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
845
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
846 buffer.append(' ');
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
847 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
848 else if (c=='%')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
849 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
850 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
851 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
852 buffer=new StringBuffer(length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
853 buffer.append(encoded,offset,offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
854 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
855
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
856 byte[] ba=new byte[length];
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
857 int n=0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
858 while(c>=0 && c<=0xff)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
859 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
860 if (c=='%')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
861 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
862 if(i+2<length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
863 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
864 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
865 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
866 if ('u'==encoded.charAt(offset+i+1))
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
867 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
868 if (i+6<length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
869 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
870 int o=offset+i+2;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
871 i+=6;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
872 String unicode = new String(Character.toChars(TypeUtil.parseInt(encoded,o,4,16)));
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
873 byte[] reencoded = unicode.getBytes(charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
874 System.arraycopy(reencoded,0,ba,n,reencoded.length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
875 n+=reencoded.length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
876 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
877 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
878 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
879 ba[n++] = (byte)'?';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
880 i=length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
881 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
882 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
883 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
884 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
885 int o=offset+i+1;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
886 i+=3;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
887 ba[n]=(byte)TypeUtil.parseInt(encoded,o,2,16);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
888 n++;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
889 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
890 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
891 catch(NumberFormatException nfe)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
892 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
893 LOG.trace("",nfe);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
894 ba[n++] = (byte)'?';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
895 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
896 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
897 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
898 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
899 ba[n++] = (byte)'?';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
900 i=length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
901 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
902 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
903 else if (c=='+')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
904 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
905 ba[n++]=(byte)' ';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
906 i++;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
907 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
908 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
909 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
910 ba[n++]=(byte)c;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
911 i++;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
912 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
913
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
914 if (i>=length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
915 break;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
916 c = encoded.charAt(offset+i);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
917 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
918
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
919 i--;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
920 buffer.append(new String(ba,0,n,charset));
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
921
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
922 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
923 else if (buffer!=null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
924 buffer.append(c);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
925 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
926
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
927 if (buffer==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
928 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
929 if (offset==0 && encoded.length()==length)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
930 return encoded;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
931 return encoded.substring(offset,offset+length);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
932 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
933
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
934 return buffer.toString();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
935 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
936 catch (UnsupportedEncodingException e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
937 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
938 throw new RuntimeException(e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
939 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
940 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
941
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
942 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
943
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
944 /* ------------------------------------------------------------ */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
945 /** Perform URL encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
946 * @param string
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
947 * @return encoded string.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
948 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
949 public static String encodeString(String string)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
950 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
951 return encodeString(string,ENCODING);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
952 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
953
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
954 /* ------------------------------------------------------------ */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
955 /** Perform URL encoding.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
956 * @param string
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
957 * @return encoded string.
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
958 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
959 public static String encodeString(String string,String charset)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
960 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
961 if (charset==null)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
962 charset=ENCODING;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
963 byte[] bytes=null;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
964 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
965 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
966 bytes=string.getBytes(charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
967 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
968 catch(UnsupportedEncodingException e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
969 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
970 // LOG.warn(LogSupport.EXCEPTION,e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
971 bytes=string.getBytes();
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
972 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
973
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
974 int len=bytes.length;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
975 byte[] encoded= new byte[bytes.length*3];
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
976 int n=0;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
977 boolean noEncode=true;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
978
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
979 for (int i=0;i<len;i++)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
980 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
981 byte b = bytes[i];
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
982
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
983 if (b==' ')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
984 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
985 noEncode=false;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
986 encoded[n++]=(byte)'+';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
987 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
988 else if (b>='a' && b<='z' ||
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
989 b>='A' && b<='Z' ||
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
990 b>='0' && b<='9')
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
991 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
992 encoded[n++]=b;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
993 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
994 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
995 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
996 noEncode=false;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
997 encoded[n++]=(byte)'%';
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
998 byte nibble= (byte) ((b&0xf0)>>4);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
999 if (nibble>=10)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1000 encoded[n++]=(byte)('A'+nibble-10);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1001 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1002 encoded[n++]=(byte)('0'+nibble);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1003 nibble= (byte) (b&0xf);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1004 if (nibble>=10)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1005 encoded[n++]=(byte)('A'+nibble-10);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1006 else
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1007 encoded[n++]=(byte)('0'+nibble);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1008 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1009 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1010
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1011 if (noEncode)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1012 return string;
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1013
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1014 try
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1015 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1016 return new String(encoded,0,n,charset);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1017 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1018 catch(UnsupportedEncodingException e)
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1019 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1020 // LOG.warn(LogSupport.EXCEPTION,e);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1021 return new String(encoded,0,n);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1022 }
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1023 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1024
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1025
1068
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1026 /* ------------------------------------------------------------ */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1027 /**
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1028 */
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1029 @Override
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1030 public Object clone()
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1031 {
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1032 return new UrlEncoded(this);
9d357b9e4bcb fix BufferUtil.newBuffer()
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
1033 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1034 }