5
5
import java .io .File ;
6
6
import java .io .FileInputStream ;
7
7
import java .io .IOException ;
8
+ import java .util .concurrent .atomic .AtomicInteger ;
8
9
9
10
import org .asynchttpclient .FluentCaseInsensitiveStringsMap ;
10
11
import org .asynchttpclient .listener .TransferCompletionHandler ;
@@ -13,7 +14,7 @@ class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter {
13
14
14
15
private final ByteBuf content ;
15
16
private final FileInputStream file ;
16
- private int byteRead = 0 ;
17
+ private AtomicInteger byteRead = new AtomicInteger ( 0 ) ;
17
18
18
19
public NettyTransferAdapter (FluentCaseInsensitiveStringsMap headers , ByteBuf content , File file ) throws IOException {
19
20
super (headers );
@@ -28,11 +29,10 @@ public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf con
28
29
@ Override
29
30
public void getBytes (byte [] bytes ) {
30
31
if (content .writableBytes () != 0 ) {
31
- content .getBytes (byteRead , bytes );
32
- byteRead += bytes .length ;
32
+ content .getBytes (byteRead .getAndAdd (bytes .length ), bytes );
33
33
} else if (file != null ) {
34
34
try {
35
- byteRead += file .read (bytes );
35
+ byteRead . getAndAdd ( file .read (bytes ) );
36
36
} catch (IOException e ) {
37
37
NettyAsyncHttpProvider .LOGGER .error (e .getMessage (), e );
38
38
}
0 commit comments