Skip to content

Commit 1bd2a25

Browse files
committed
minor clean up
1 parent 7345850 commit 1bd2a25

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

api/src/main/java/org/asynchttpclient/request/body/generator/FeedableBodyGenerator.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.nio.ByteBuffer;
2020
import java.util.Queue;
2121
import java.util.concurrent.ConcurrentLinkedQueue;
22-
import java.util.concurrent.atomic.AtomicInteger;
2322

2423
import org.asynchttpclient.request.body.Body;
2524

@@ -31,7 +30,6 @@ public final class FeedableBodyGenerator implements BodyGenerator {
3130
private final static byte[] END_PADDING = "\r\n".getBytes(US_ASCII);
3231
private final static byte[] ZERO = "0".getBytes(US_ASCII);
3332
private final Queue<BodyPart> queue = new ConcurrentLinkedQueue<>();
34-
private final AtomicInteger queueSize = new AtomicInteger();
3533
private FeedListener listener;
3634

3735
@Override
@@ -41,7 +39,6 @@ public Body createBody() {
4139

4240
public void feed(final ByteBuffer buffer, final boolean isLast) throws IOException {
4341
queue.offer(new BodyPart(buffer, isLast));
44-
queueSize.incrementAndGet();
4542
if (listener != null) {
4643
listener.onContentAdded();
4744
}
@@ -55,12 +52,13 @@ public void setListener(FeedListener listener) {
5552
this.listener = listener;
5653
}
5754

55+
private static enum PushBodyState {
56+
ONGOING, CLOSING, FINISHED;
57+
}
58+
5859
private final class PushBody implements Body {
59-
private final int ONGOING = 0;
60-
private final int CLOSING = 1;
61-
private final int FINISHED = 2;
6260

63-
private int finishState = 0;
61+
private PushBodyState state = PushBodyState.ONGOING;
6462

6563
@Override
6664
public long getContentLength() {
@@ -72,14 +70,14 @@ public long read(final ByteBuffer buffer) throws IOException {
7270
BodyPart nextPart = queue.peek();
7371
if (nextPart == null) {
7472
// Nothing in the queue
75-
switch (finishState) {
73+
switch (state) {
7674
case ONGOING:
7775
return 0;
7876
case CLOSING:
7977
buffer.put(ZERO);
8078
buffer.put(END_PADDING);
8179
buffer.put(END_PADDING);
82-
finishState = FINISHED;
80+
state = PushBodyState.FINISHED;
8381
return buffer.position();
8482
case FINISHED:
8583
return -1;
@@ -97,7 +95,7 @@ public long read(final ByteBuffer buffer) throws IOException {
9795
}
9896
if (!nextPart.buffer.hasRemaining()) {
9997
if (nextPart.isLast) {
100-
finishState = CLOSING;
98+
state = PushBodyState.CLOSING;
10199
}
102100
queue.remove();
103101
}

0 commit comments

Comments
 (0)