Skip to content

Commit 4996b44

Browse files
author
Stephane Landelle
committed
RandomAccessBody.transferTo count is actually unused (Long.MAX_VALUE)
1 parent 6807f5b commit 4996b44

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

api/src/main/java/org/asynchttpclient/Body.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface Body extends Closeable {
3636
* @return The non-negative number of bytes actually read or {@code -1} if the body has been read completely.
3737
* @throws IOException If the chunk could not be read.
3838
*/
39+
// FIXME introduce a visitor pattern so that Netty can pass a pooled buffer
3940
long read(ByteBuffer buffer) throws IOException;
4041

4142
/**

api/src/main/java/org/asynchttpclient/RandomAccessBody.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ public interface RandomAccessBody extends Body {
2626
*
2727
* @param position
2828
* The zero-based byte index from which to start the transfer, must not be negative.
29-
* @param count
30-
* The maximum number of bytes to transfer, must not be negative.
3129
* @param target
3230
* The destination channel to transfer the body chunk to, must not be {@code null}.
3331
* @return The non-negative number of bytes actually transferred.
3432
* @throws IOException
3533
* If the body chunk could not be transferred.
3634
*/
37-
long transferTo(long position, long count, WritableByteChannel target) throws IOException;
35+
long transferTo(long position, WritableByteChannel target) throws IOException;
3836
}

api/src/main/java/org/asynchttpclient/generators/FileBodyGenerator.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/**
2626
* Creates a request body from the contents of a file.
2727
*/
28+
//Not used by Netty
2829
public class FileBodyGenerator implements BodyGenerator {
2930

3031
private final File file;
@@ -89,11 +90,8 @@ public long read(ByteBuffer buffer) throws IOException {
8990
return channel.read(buffer);
9091
}
9192

92-
public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
93-
if (count > length) {
94-
count = length;
95-
}
96-
return channel.transferTo(position, count, target);
93+
public long transferTo(long position, WritableByteChannel target) throws IOException {
94+
return channel.transferTo(position, length, target);
9795
}
9896

9997
public void close() throws IOException {

api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public String getContentType() {
6969
}
7070

7171
// RandomAccessBody API, suited for HTTP but not for HTTPS
72-
public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
72+
public long transferTo(long position, WritableByteChannel target) throws IOException {
7373

7474
long overallLength = 0;
7575

0 commit comments

Comments
 (0)