Skip to content

Commit 7ce989b

Browse files
committed
Make FileBodyGenerator final and remove unused stuff, see AsyncHttpClient#896
1 parent a278107 commit 7ce989b

File tree

1 file changed

+5
-44
lines changed

1 file changed

+5
-44
lines changed

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

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@
1212
*/
1313
package org.asynchttpclient.generators;
1414

15-
import org.asynchttpclient.BodyGenerator;
16-
import org.asynchttpclient.RandomAccessBody;
17-
1815
import java.io.File;
1916
import java.io.IOException;
20-
import java.io.RandomAccessFile;
21-
import java.nio.ByteBuffer;
22-
import java.nio.channels.FileChannel;
23-
import java.nio.channels.WritableByteChannel;
17+
18+
import org.asynchttpclient.BodyGenerator;
19+
import org.asynchttpclient.RandomAccessBody;
2420

2521
/**
2622
* Creates a request body from the contents of a file.
2723
*/
28-
//Not used by Netty
29-
public class FileBodyGenerator implements BodyGenerator {
24+
public final class FileBodyGenerator implements BodyGenerator {
3025

3126
private final File file;
3227
private final long regionSeek;
@@ -62,40 +57,6 @@ public long getRegionSeek() {
6257
*/
6358
@Override
6459
public RandomAccessBody createBody() throws IOException {
65-
return new FileBody(file, regionSeek, regionLength);
66-
}
67-
68-
private static class FileBody implements RandomAccessBody {
69-
70-
private final RandomAccessFile raf;
71-
72-
private final FileChannel channel;
73-
74-
private final long length;
75-
76-
private FileBody(File file, long regionSeek, long regionLength) throws IOException {
77-
raf = new RandomAccessFile(file, "r");
78-
channel = raf.getChannel();
79-
length = regionLength;
80-
if (regionSeek > 0) {
81-
raf.seek(regionSeek);
82-
}
83-
}
84-
85-
public long getContentLength() {
86-
return length;
87-
}
88-
89-
public long read(ByteBuffer buffer) throws IOException {
90-
return channel.read(buffer);
91-
}
92-
93-
public long transferTo(long position, WritableByteChannel target) throws IOException {
94-
return channel.transferTo(position, length, target);
95-
}
96-
97-
public void close() throws IOException {
98-
raf.close();
99-
}
60+
throw new UnsupportedOperationException("FileBodyGenerator.createBody isn't used, Netty direclt sends the file");
10061
}
10162
}

0 commit comments

Comments
 (0)