Headers.java
9.08 KB
1
2
3
4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package com.squareup.okhttp;
import com.squareup.okhttp.internal.http.HttpDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
public final class Headers
{
private final String[] namesAndValues;
private Headers(Builder paramBuilder)
{
this.namesAndValues = ((String[])paramBuilder.namesAndValues.toArray(new String[paramBuilder.namesAndValues.size()]));
}
private Headers(String[] paramArrayOfString)
{
this.namesAndValues = paramArrayOfString;
}
private static String get(String[] paramArrayOfString, String paramString)
{
int i = paramArrayOfString.length - 2;
while (i >= 0)
{
if (paramString.equalsIgnoreCase(paramArrayOfString[i])) {
return paramArrayOfString[(i + 1)];
}
i -= 2;
}
return null;
}
public static Headers of(Map<String, String> paramMap)
{
if (paramMap == null) {
throw new IllegalArgumentException("Expected map with header names and values");
}
String[] arrayOfString = new String[paramMap.size() * 2];
paramMap = paramMap.entrySet().iterator();
int i = 0;
while (paramMap.hasNext())
{
Object localObject = (Map.Entry)paramMap.next();
if ((((Map.Entry)localObject).getKey() == null) || (((Map.Entry)localObject).getValue() == null)) {
throw new IllegalArgumentException("Headers cannot be null");
}
String str = ((String)((Map.Entry)localObject).getKey()).trim();
localObject = ((String)((Map.Entry)localObject).getValue()).trim();
if ((str.length() == 0) || (str.indexOf(0) != -1) || (((String)localObject).indexOf(0) != -1)) {
throw new IllegalArgumentException("Unexpected header: " + str + ": " + (String)localObject);
}
arrayOfString[i] = str;
arrayOfString[(i + 1)] = localObject;
i += 2;
}
return new Headers(arrayOfString);
}
public static Headers of(String... paramVarArgs)
{
if ((paramVarArgs == null) || (paramVarArgs.length % 2 != 0)) {
throw new IllegalArgumentException("Expected alternating header names and values");
}
paramVarArgs = (String[])paramVarArgs.clone();
int i = 0;
while (i < paramVarArgs.length)
{
if (paramVarArgs[i] == null) {
throw new IllegalArgumentException("Headers cannot be null");
}
paramVarArgs[i] = paramVarArgs[i].trim();
i += 1;
}
i = 0;
while (i < paramVarArgs.length)
{
String str1 = paramVarArgs[i];
String str2 = paramVarArgs[(i + 1)];
if ((str1.length() == 0) || (str1.indexOf(0) != -1) || (str2.indexOf(0) != -1)) {
throw new IllegalArgumentException("Unexpected header: " + str1 + ": " + str2);
}
i += 2;
}
return new Headers(paramVarArgs);
}
public final String get(String paramString)
{
return get(this.namesAndValues, paramString);
}
public final Date getDate(String paramString)
{
paramString = get(paramString);
if (paramString != null) {
return HttpDate.parse(paramString);
}
return null;
}
public final String name(int paramInt)
{
paramInt *= 2;
if ((paramInt < 0) || (paramInt >= this.namesAndValues.length)) {
return null;
}
return this.namesAndValues[paramInt];
}
public final Set<String> names()
{
TreeSet localTreeSet = new TreeSet(String.CASE_INSENSITIVE_ORDER);
int i = 0;
int j = size();
while (i < j)
{
localTreeSet.add(name(i));
i += 1;
}
return Collections.unmodifiableSet(localTreeSet);
}
public final Builder newBuilder()
{
Builder localBuilder = new Builder();
Collections.addAll(localBuilder.namesAndValues, this.namesAndValues);
return localBuilder;
}
public final int size()
{
return this.namesAndValues.length / 2;
}
public final Map<String, List<String>> toMultimap()
{
LinkedHashMap localLinkedHashMap = new LinkedHashMap();
int j = size();
int i = 0;
while (i < j)
{
String str = name(i);
List localList = (List)localLinkedHashMap.get(str);
Object localObject = localList;
if (localList == null)
{
localObject = new ArrayList(2);
localLinkedHashMap.put(str, localObject);
}
((List)localObject).add(value(i));
i += 1;
}
return localLinkedHashMap;
}
public final String toString()
{
StringBuilder localStringBuilder = new StringBuilder();
int i = 0;
int j = size();
while (i < j)
{
localStringBuilder.append(name(i)).append(": ").append(value(i)).append("\n");
i += 1;
}
return localStringBuilder.toString();
}
public final String value(int paramInt)
{
paramInt = paramInt * 2 + 1;
if ((paramInt < 0) || (paramInt >= this.namesAndValues.length)) {
return null;
}
return this.namesAndValues[paramInt];
}
public final List<String> values(String paramString)
{
int j = size();
Object localObject1 = null;
int i = 0;
while (i < j)
{
Object localObject2 = localObject1;
if (paramString.equalsIgnoreCase(name(i)))
{
localObject2 = localObject1;
if (localObject1 == null) {
localObject2 = new ArrayList(2);
}
((List)localObject2).add(value(i));
}
i += 1;
localObject1 = localObject2;
}
if (localObject1 != null) {
return Collections.unmodifiableList((List)localObject1);
}
return Collections.emptyList();
}
public static final class Builder
{
private final List<String> namesAndValues = new ArrayList(20);
private void checkNameAndValue(String paramString1, String paramString2)
{
if (paramString1 == null) {
throw new IllegalArgumentException("name == null");
}
if (paramString1.isEmpty()) {
throw new IllegalArgumentException("name is empty");
}
int j = paramString1.length();
int i = 0;
int k;
while (i < j)
{
k = paramString1.charAt(i);
if ((k <= 31) || (k >= 127)) {
throw new IllegalArgumentException(String.format("Unexpected char %#04x at %d in header name: %s", new Object[] { Integer.valueOf(k), Integer.valueOf(i), paramString1 }));
}
i += 1;
}
if (paramString2 == null) {
throw new IllegalArgumentException("value == null");
}
j = paramString2.length();
i = 0;
while (i < j)
{
k = paramString2.charAt(i);
if ((k <= 31) || (k >= 127)) {
throw new IllegalArgumentException(String.format("Unexpected char %#04x at %d in header value: %s", new Object[] { Integer.valueOf(k), Integer.valueOf(i), paramString2 }));
}
i += 1;
}
}
public final Builder add(String paramString)
{
int i = paramString.indexOf(":");
if (i == -1) {
throw new IllegalArgumentException("Unexpected header: " + paramString);
}
return add(paramString.substring(0, i).trim(), paramString.substring(i + 1));
}
public final Builder add(String paramString1, String paramString2)
{
checkNameAndValue(paramString1, paramString2);
return addLenient(paramString1, paramString2);
}
final Builder addLenient(String paramString)
{
int i = paramString.indexOf(":", 1);
if (i != -1) {
return addLenient(paramString.substring(0, i), paramString.substring(i + 1));
}
if (paramString.startsWith(":")) {
return addLenient("", paramString.substring(1));
}
return addLenient("", paramString);
}
final Builder addLenient(String paramString1, String paramString2)
{
this.namesAndValues.add(paramString1);
this.namesAndValues.add(paramString2.trim());
return this;
}
public final Headers build()
{
return new Headers(this, null);
}
public final String get(String paramString)
{
int i = this.namesAndValues.size() - 2;
while (i >= 0)
{
if (paramString.equalsIgnoreCase((String)this.namesAndValues.get(i))) {
return (String)this.namesAndValues.get(i + 1);
}
i -= 2;
}
return null;
}
public final Builder removeAll(String paramString)
{
int j;
for (int i = 0; i < this.namesAndValues.size(); i = j + 2)
{
j = i;
if (paramString.equalsIgnoreCase((String)this.namesAndValues.get(i)))
{
this.namesAndValues.remove(i);
this.namesAndValues.remove(i);
j = i - 2;
}
}
return this;
}
public final Builder set(String paramString1, String paramString2)
{
checkNameAndValue(paramString1, paramString2);
removeAll(paramString1);
addLenient(paramString1, paramString2);
return this;
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/Headers.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/