-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueryString.java
More file actions
35 lines (27 loc) · 793 Bytes
/
QueryString.java
File metadata and controls
35 lines (27 loc) · 793 Bytes
1
2
3
4
5
6
7<
5A8C
/div>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class QueryString {
private StringBuilder query = new StringBuilder();
public QueryString() {
}
public synchronized void add(String name, String value) {
query.append('&');
encode(name, value);
}
private synchronized void encode(String name, String value) {
try {
query.append(URLEncoder.encode(name, "UTF-8"));
query.append('=');
query.append(URLEncoder.encode(value, "UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("Broken VM does not support UTF-8");
}
}
public synchronized String getQuery() {
return query.toString();
}
@Override
public String toString() {
return getQuery();
}
}