|
12 | 12 | */
|
13 | 13 | package org.asynchttpclient.generators;
|
14 | 14 |
|
15 |
| -import org.asynchttpclient.BodyGenerator; |
16 |
| -import org.asynchttpclient.RandomAccessBody; |
17 |
| - |
18 | 15 | import java.io.File;
|
19 | 16 | 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; |
24 | 20 |
|
25 | 21 | /**
|
26 | 22 | * Creates a request body from the contents of a file.
|
27 | 23 | */
|
28 |
| -//Not used by Netty |
29 |
| -public class FileBodyGenerator implements BodyGenerator { |
| 24 | +public final class FileBodyGenerator implements BodyGenerator { |
30 | 25 |
|
31 | 26 | private final File file;
|
32 | 27 | private final long regionSeek;
|
@@ -62,40 +57,6 @@ public long getRegionSeek() {
|
62 | 57 | */
|
63 | 58 | @Override
|
64 | 59 | 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"); |
100 | 61 | }
|
101 | 62 | }
|
0 commit comments