Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb86b39

Browse files
author
Stephane Landelle
committed
initializeBuffer takes byte[], make immutable members final
1 parentd124b53 commitfb86b39

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

‎src/main/java/com/ning/http/multipart/MultipartBody.java‎

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,28 @@
3232

3333
publicclassMultipartBodyimplementsRandomAccessBody {
3434

35-
privatebyte[]boundary;
36-
privatelongcontentLength;
37-
privateList<com.ning.http.client.Part>parts;
38-
privateList<RandomAccessFile>files;
39-
privateintstartPart;
4035
privatefinalstaticLoggerlogger =LoggerFactory.getLogger(MultipartBody.class);
41-
ByteArrayInputStreamcurrentStream;
42-
intcurrentStreamPosition;
43-
booleanendWritten;
44-
booleandoneWritingParts;
45-
FileLocationfileLocation;
46-
FilePartcurrentFilePart;
47-
FileChannelcurrentFileChannel;
36+
37+
privatefinalbyte[]boundary;
38+
privatefinallongcontentLength;
39+
privatefinalList<com.ning.http.client.Part>parts;
40+
privatefinalList<RandomAccessFile>files =newArrayList<RandomAccessFile>();
41+
42+
privateintstartPart =0;
43+
privateByteArrayInputStreamcurrentStream;
44+
privateintcurrentStreamPosition = -1;
45+
privatebooleanendWritten =false;
46+
privatebooleandoneWritingParts =false;
47+
privateFileLocationfileLocation =FileLocation.NONE;
48+
privateFilePartcurrentFilePart;
49+
privateFileChannelcurrentFileChannel;
4850

4951
enumFileLocation {NONE,START,MIDDLE,END}
5052

5153
publicMultipartBody(List<com.ning.http.client.Part>parts,StringcontentType,longcontentLength) {
5254
this.boundary =MultipartEncodingUtil.getAsciiBytes(contentType.substring(contentType.indexOf("boundary=") +"boundary=".length()));
5355
this.parts =parts;
5456
this.contentLength =contentLength;
55-
56-
files =newArrayList<RandomAccessFile>();
57-
58-
startPart =0;
59-
currentStreamPosition = -1;
60-
endWritten =false;
61-
doneWritingParts =false;
62-
fileLocation =FileLocation.NONE;
63-
currentFilePart =null;
6457
}
6558

6659
publicvoidclose()throwsIOException {
@@ -180,7 +173,7 @@ public long read(ByteBuffer buffer) throws IOException {
180173

181174
Part.sendMessageEnd(endWriter,boundary);
182175

183-
initializeBuffer(endWriter);
176+
initializeBuffer(endWriter.toByteArray());
184177
}
185178

186179
if (currentStreamPosition > -1) {
@@ -207,7 +200,7 @@ private void initializeByteArrayBody(FilePart filePart)
207200
ByteArrayOutputStreamoutput =newByteArrayOutputStream();
208201
filePart.sendData(output);
209202

210-
initializeBuffer(output);
203+
initializeBuffer(output.toByteArray());
211204

212205
fileLocation =FileLocation.MIDDLE;
213206
}
@@ -217,7 +210,7 @@ private void initializeFileEnd(FilePart currentPart)
217210

218211
ByteArrayOutputStreamoutput =generateFileEnd(currentPart);
219212

220-
initializeBuffer(output);
213+
initializeBuffer(output.toByteArray());
221214

222215
fileLocation =FileLocation.END;
223216

@@ -238,6 +231,7 @@ private void initializeFileBody(FilePart currentPart)
238231
currentFileChannel =raf.getChannel();
239232

240233
}else {
234+
// ByteArrayPartSource
241235
PartSourcepartSource =currentPart.getSource();
242236

243237
InputStreamstream =partSource.createInputStream();
@@ -261,7 +255,7 @@ private void initializeFilePart(FilePart filePart)
261255

262256
ByteArrayOutputStreamoutput =generateFileStart(filePart);
263257

264-
initializeBuffer(output);
258+
initializeBuffer(output.toByteArray());
265259

266260
fileLocation =FileLocation.START;
267261
}
@@ -274,7 +268,7 @@ private void initializeStringPart(StringPart currentPart)
274268

275269
Part.sendPart(outputStream,currentPart,boundary);
276270

277-
initializeBuffer(outputStream);
271+
initializeBuffer(outputStream.toByteArray());
278272
}
279273

280274
privateintwriteToBuffer(ByteBufferbuffer,intlength)
@@ -300,10 +294,10 @@ private int writeToBuffer(ByteBuffer buffer, int length)
300294
returnwriteLength;
301295
}
302296

303-
privatevoidinitializeBuffer(ByteArrayOutputStreamoutputStream)
297+
privatevoidinitializeBuffer(byte[]bytes)
304298
throwsIOException {
305299

306-
currentStream =newByteArrayInputStream(outputStream.toByteArray());
300+
currentStream =newByteArrayInputStream(bytes);
307301

308302
currentStreamPosition =0;
309303

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp