Skip to content

Commit

Permalink
available and releaseByteBuf methods added
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Feb 18, 2020
1 parent aea67d4 commit 8c7d90c
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ public int read(byte[] b, int off, int len) throws IOException {
}
buffer.get(b, off, len);
if (rem == len) {
current.release();
current = null;
buffer = null;
releaseByteBuf();
}

return len;
Expand All @@ -90,13 +88,19 @@ public int read() throws IOException {

@Override
public synchronized void close() {
if (current != null) {
current.release();
}

current = null;
buffer = null;
cleanup(true);
releaseByteBuf();

cleanup(true);
}

private void releaseByteBuf() {
if (current != null) {
current.release();
}

current = null;
buffer = null;
}

protected synchronized ByteBuffer awaitNext() {
Expand Down Expand Up @@ -137,6 +141,23 @@ protected void cleanup(boolean drain) {
}
}

@Override
public int available() throws IOException {
if (end || reading) {
return 0;
}
if (current != null) {
return current.readableBytes();
}
if (!isList.isEmpty()) {
final ByteBuf peek = isList.peek();
if (peek != null && peek.isReadable()) {
return peek.readableBytes();
}
}
return 0;
}

public synchronized void publish(ByteBuf content) {
if (end || content.nioBuffer().remaining() == 0) {
content.release();
Expand Down

0 comments on commit 8c7d90c

Please sign in to comment.