MultipartBuilder.java
7.92 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
package com.squareup.okhttp;
import com.squareup.okhttp.internal.Util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import okio.Buffer;
import okio.BufferedSink;
import okio.ByteString;
public final class MultipartBuilder
{
public static final MediaType ALTERNATIVE;
private static final byte[] COLONSPACE = { 58, 32 };
private static final byte[] CRLF = { 13, 10 };
private static final byte[] DASHDASH = { 45, 45 };
public static final MediaType DIGEST;
public static final MediaType FORM;
public static final MediaType MIXED = MediaType.parse("multipart/mixed");
public static final MediaType PARALLEL;
private final ByteString boundary;
private final List<RequestBody> partBodies = new ArrayList();
private final List<Headers> partHeaders = new ArrayList();
private MediaType type = MIXED;
static
{
ALTERNATIVE = MediaType.parse("multipart/alternative");
DIGEST = MediaType.parse("multipart/digest");
PARALLEL = MediaType.parse("multipart/parallel");
FORM = MediaType.parse("multipart/form-data");
}
public MultipartBuilder()
{
this(UUID.randomUUID().toString());
}
public MultipartBuilder(String paramString)
{
this.boundary = ByteString.encodeUtf8(paramString);
}
private static StringBuilder appendQuotedString(StringBuilder paramStringBuilder, String paramString)
{
paramStringBuilder.append('"');
int i = 0;
int j = paramString.length();
if (i < j)
{
char c = paramString.charAt(i);
switch (c)
{
default:
paramStringBuilder.append(c);
}
for (;;)
{
i += 1;
break;
paramStringBuilder.append("%0A");
continue;
paramStringBuilder.append("%0D");
continue;
paramStringBuilder.append("%22");
}
}
paramStringBuilder.append('"');
return paramStringBuilder;
}
public final MultipartBuilder addFormDataPart(String paramString1, String paramString2)
{
return addFormDataPart(paramString1, null, RequestBody.create(null, paramString2));
}
public final MultipartBuilder addFormDataPart(String paramString1, String paramString2, RequestBody paramRequestBody)
{
if (paramString1 == null) {
throw new NullPointerException("name == null");
}
StringBuilder localStringBuilder = new StringBuilder("form-data; name=");
appendQuotedString(localStringBuilder, paramString1);
if (paramString2 != null)
{
localStringBuilder.append("; filename=");
appendQuotedString(localStringBuilder, paramString2);
}
return addPart(Headers.of(new String[] { "Content-Disposition", localStringBuilder.toString() }), paramRequestBody);
}
public final MultipartBuilder addPart(Headers paramHeaders, RequestBody paramRequestBody)
{
if (paramRequestBody == null) {
throw new NullPointerException("body == null");
}
if ((paramHeaders != null) && (paramHeaders.get("Content-Type") != null)) {
throw new IllegalArgumentException("Unexpected header: Content-Type");
}
if ((paramHeaders != null) && (paramHeaders.get("Content-Length") != null)) {
throw new IllegalArgumentException("Unexpected header: Content-Length");
}
this.partHeaders.add(paramHeaders);
this.partBodies.add(paramRequestBody);
return this;
}
public final MultipartBuilder addPart(RequestBody paramRequestBody)
{
return addPart(null, paramRequestBody);
}
public final RequestBody build()
{
if (this.partHeaders.isEmpty()) {
throw new IllegalStateException("Multipart body must have at least one part.");
}
return new MultipartRequestBody(this.type, this.boundary, this.partHeaders, this.partBodies);
}
public final MultipartBuilder type(MediaType paramMediaType)
{
if (paramMediaType == null) {
throw new NullPointerException("type == null");
}
if (!paramMediaType.type().equals("multipart")) {
throw new IllegalArgumentException("multipart != " + paramMediaType);
}
this.type = paramMediaType;
return this;
}
static final class MultipartRequestBody
extends RequestBody
{
private final ByteString boundary;
private long contentLength = -1L;
private final MediaType contentType;
private final List<RequestBody> partBodies;
private final List<Headers> partHeaders;
public MultipartRequestBody(MediaType paramMediaType, ByteString paramByteString, List<Headers> paramList, List<RequestBody> paramList1)
{
if (paramMediaType == null) {
throw new NullPointerException("type == null");
}
this.boundary = paramByteString;
this.contentType = MediaType.parse(paramMediaType + "; boundary=" + paramByteString.utf8());
this.partHeaders = Util.immutableList(paramList);
this.partBodies = Util.immutableList(paramList1);
}
private long writeOrCountBytes(BufferedSink paramBufferedSink, boolean paramBoolean)
throws IOException
{
long l1 = 0L;
if (paramBoolean) {
paramBufferedSink = new Buffer();
}
for (BufferedSink localBufferedSink = paramBufferedSink;; localBufferedSink = null)
{
int k = this.partHeaders.size();
int i = 0;
if (i < k)
{
Object localObject = (Headers)this.partHeaders.get(i);
RequestBody localRequestBody = (RequestBody)this.partBodies.get(i);
paramBufferedSink.write(MultipartBuilder.DASHDASH);
paramBufferedSink.write(this.boundary);
paramBufferedSink.write(MultipartBuilder.CRLF);
if (localObject != null)
{
int j = 0;
int m = ((Headers)localObject).size();
while (j < m)
{
paramBufferedSink.writeUtf8(((Headers)localObject).name(j)).write(MultipartBuilder.COLONSPACE).writeUtf8(((Headers)localObject).value(j)).write(MultipartBuilder.CRLF);
j += 1;
}
}
localObject = localRequestBody.contentType();
if (localObject != null) {
paramBufferedSink.writeUtf8("Content-Type: ").writeUtf8(((MediaType)localObject).toString()).write(MultipartBuilder.CRLF);
}
l2 = localRequestBody.contentLength();
if (l2 != -1L) {
paramBufferedSink.writeUtf8("Content-Length: ").writeDecimalLong(l2).write(MultipartBuilder.CRLF);
}
while (!paramBoolean)
{
paramBufferedSink.write(MultipartBuilder.CRLF);
if (!paramBoolean) {
break label305;
}
l1 = l2 + l1;
paramBufferedSink.write(MultipartBuilder.CRLF);
i += 1;
break;
}
localBufferedSink.clear();
l2 = -1L;
}
label305:
do
{
return l2;
((RequestBody)this.partBodies.get(i)).writeTo(paramBufferedSink);
break;
paramBufferedSink.write(MultipartBuilder.DASHDASH);
paramBufferedSink.write(this.boundary);
paramBufferedSink.write(MultipartBuilder.DASHDASH);
paramBufferedSink.write(MultipartBuilder.CRLF);
l2 = l1;
} while (!paramBoolean);
long l2 = localBufferedSink.size();
localBufferedSink.clear();
return l1 + l2;
}
}
public final long contentLength()
throws IOException
{
long l = this.contentLength;
if (l != -1L) {
return l;
}
l = writeOrCountBytes(null, true);
this.contentLength = l;
return l;
}
public final MediaType contentType()
{
return this.contentType;
}
public final void writeTo(BufferedSink paramBufferedSink)
throws IOException
{
writeOrCountBytes(paramBufferedSink, false);
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/MultipartBuilder.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/