Skip to content

Commit 0392917

Browse files
committed
minor clean up
1 parent 97c8ec5 commit 0392917

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/main/java/com/ning/http/client/providers/netty/request/body/FeedableBodyGenerator.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.nio.ByteBuffer;
2323
import java.util.Queue;
2424
import java.util.concurrent.ConcurrentLinkedQueue;
25-
import java.util.concurrent.atomic.AtomicInteger;
2625

2726
/**
2827
* {@link BodyGenerator} which may return just part of the payload at the time handler is requesting it.
@@ -32,7 +31,6 @@ public class FeedableBodyGenerator implements BodyGenerator {
3231
private final static byte[] END_PADDING = "\r\n".getBytes(US_ASCII);
3332
private final static byte[] ZERO = "0".getBytes(US_ASCII);
3433
private final Queue<BodyPart> queue = new ConcurrentLinkedQueue<>();
35-
private final AtomicInteger queueSize = new AtomicInteger();
3634
private FeedListener listener;
3735

3836
@Override
@@ -42,7 +40,6 @@ public Body createBody() throws IOException {
4240

4341
public void feed(final ByteBuffer buffer, final boolean isLast) throws IOException {
4442
queue.offer(new BodyPart(buffer, isLast));
45-
queueSize.incrementAndGet();
4643
if (listener != null) {
4744
listener.onContentAdded();
4845
}
@@ -56,12 +53,13 @@ public void setListener(FeedListener listener) {
5653
this.listener = listener;
5754
}
5855

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

64-
private int finishState = 0;
62+
private PushBodyState state = PushBodyState.ONGOING;
6563

6664
@Override
6765
public long getContentLength() {
@@ -73,14 +71,14 @@ public long read(final ByteBuffer buffer) throws IOException {
7371
BodyPart nextPart = queue.peek();
7472
if (nextPart == null) {
7573
// Nothing in the queue
76-
switch (finishState) {
74+
switch (state) {
7775
case ONGOING:
7876
return 0;
7977
case CLOSING:
8078
buffer.put(ZERO);
8179
buffer.put(END_PADDING);
8280
buffer.put(END_PADDING);
83-
finishState = FINISHED;
81+
state = PushBodyState.FINISHED;
8482
return buffer.position();
8583
case FINISHED:
8684
return -1;
@@ -98,7 +96,7 @@ public long read(final ByteBuffer buffer) throws IOException {
9896
}
9997
if (!nextPart.buffer.hasRemaining()) {
10098
if (nextPart.isLast) {
101-
finishState = CLOSING;
99+
state = PushBodyState.CLOSING;
102100
}
103101
queue.remove();
104102
}

0 commit comments

Comments
 (0)