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

Commitd124b53

Browse files
author
Stephane Landelle
committed
Make explicit that writeToTarget uses byte[]
1 parent475c599 commitd124b53

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,11 @@ public long transferTo(long position, long count, WritableByteChannel target)
329329

330330
tempPart++;
331331
}
332-
ByteArrayOutputStreamendWriter =
333-
newByteArrayOutputStream();
332+
ByteArrayOutputStreamendWriter =newByteArrayOutputStream();
334333

335334
Part.sendMessageEnd(endWriter,boundary);
336335

337-
overallLength +=writeToTarget(target,endWriter);
336+
overallLength +=writeToTarget(target,endWriter.toByteArray());
338337

339338
startPart =tempPart;
340339

@@ -391,15 +390,15 @@ private long handleByteArrayPart(WritableByteChannel target,
391390

392391
finalByteArrayOutputStreamoutput =newByteArrayOutputStream();
393392
Part.sendPart(output,filePart,boundary);
394-
returnwriteToTarget(target,output);
393+
returnwriteToTarget(target,output.toByteArray());
395394
}
396395

397396
privatelonghandleFileEnd(WritableByteChanneltarget,FilePartfilePart)
398397
throwsIOException {
399398

400399
ByteArrayOutputStreamendOverhead =generateFileEnd(filePart);
401400

402-
returnthis.writeToTarget(target,endOverhead);
401+
returnthis.writeToTarget(target,endOverhead.toByteArray());
403402
}
404403

405404
privateByteArrayOutputStreamgenerateFileEnd(FilePartfilePart)
@@ -415,7 +414,7 @@ private long handleFileHeaders(WritableByteChannel target, FilePart filePart) th
415414

416415
ByteArrayOutputStreamoverhead =generateFileStart(filePart);
417416

418-
returnwriteToTarget(target,overhead);
417+
returnwriteToTarget(target,overhead.toByteArray());
419418
}
420419

421420
privateByteArrayOutputStreamgenerateFileStart(FilePartfilePart)
@@ -525,7 +524,7 @@ private long handlePartSource(WritableByteChannel target, FilePart filePart) thr
525524
if (nRead >0) {
526525
ByteArrayOutputStreambos =newByteArrayOutputStream(nRead);
527526
bos.write(bytes,0,nRead);
528-
writeToTarget(target,bos);
527+
writeToTarget(target,bos.toByteArray());
529528
}
530529
}
531530
}finally {
@@ -544,7 +543,7 @@ private long handleStringPart(WritableByteChannel target, StringPart currentPart
544543

545544
Part.sendPart(outputStream,currentPart,boundary);
546545

547-
returnwriteToTarget(target,outputStream);
546+
returnwriteToTarget(target,outputStream.toByteArray());
548547
}
549548

550549
privatelonghandleMultiPart(WritableByteChanneltarget,PartcurrentPart)throwsIOException {
@@ -561,21 +560,21 @@ private long handleMultiPart(WritableByteChannel target, Part currentPart) throw
561560
return0;
562561
}
563562

564-
privatelongwriteToTarget(WritableByteChanneltarget,ByteArrayOutputStreambyteWriter)
563+
privatelongwriteToTarget(WritableByteChanneltarget,byte[]bytes)
565564
throwsIOException {
566565

567566
intwritten =0;
568567
intmaxSpin =0;
569-
synchronized (byteWriter) {
570-
ByteBuffermessage =ByteBuffer.wrap(byteWriter.toByteArray());
568+
synchronized (bytes) {
569+
ByteBuffermessage =ByteBuffer.wrap(bytes);
571570

572571
if (targetinstanceofSocketChannel) {
573572
finalSelectorselector =Selector.open();
574573
try {
575574
finalSocketChannelchannel = (SocketChannel)target;
576575
channel.register(selector,SelectionKey.OP_WRITE);
577576

578-
while (written <byteWriter.size()) {
577+
while (written <bytes.length) {
579578
selector.select(1000);
580579
maxSpin++;
581580
finalSet<SelectionKey>selectedKeys =selector.selectedKeys();
@@ -595,13 +594,13 @@ private long writeToTarget(WritableByteChannel target, ByteArrayOutputStream byt
595594
selector.close();
596595
}
597596
}else {
598-
while ((target.isOpen()) && (written <byteWriter.size())) {
597+
while ((target.isOpen()) && (written <bytes.length)) {
599598
longnWrite =target.write(message);
600599
written +=nWrite;
601600
if (nWrite ==0 &&maxSpin++ <10) {
602601
logger.info("Waiting for writing...");
603602
try {
604-
byteWriter.wait(1000);
603+
bytes.wait(1000);
605604
}catch (InterruptedExceptione) {
606605
logger.trace(e.getMessage(),e);
607606
}
@@ -616,5 +615,4 @@ private long writeToTarget(WritableByteChannel target, ByteArrayOutputStream byt
616615
}
617616
returnwritten;
618617
}
619-
620618
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp