Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions src/main/java/org/msgpack/io/LinkedBufferInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.EOFException;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.nio.ByteBuffer;

public class LinkedBufferInput extends AbstractInput {
Expand Down Expand Up @@ -50,7 +51,7 @@ public int read(byte[] b, int off, int len) throws EOFException {
}
int olen = len;
while (true) {
ByteBuffer bb = link.peekFirst();
ByteBuffer bb = link.getFirst();
if (len < bb.remaining()) {
bb.get(b, off, len);
incrReadByteCount(len);
Expand All @@ -69,7 +70,10 @@ public int read(byte[] b, int off, int len) throws EOFException {
}

public boolean tryRefer(BufferReferer ref, int len) throws IOException {
ByteBuffer bb = link.peekFirst();
ByteBuffer bb = null;
try {
bb = link.getFirst();
} catch(NoSuchElementException e) {}
if (bb == null) {
throw new EndOfBufferException();
} else if (bb.remaining() < len) {
Expand Down Expand Up @@ -98,7 +102,10 @@ public boolean tryRefer(BufferReferer ref, int len) throws IOException {
}

public byte readByte() throws EOFException {
ByteBuffer bb = link.peekFirst();
ByteBuffer bb = null;
try {
bb = link.getFirst();
} catch(NoSuchElementException e) {}
if (bb == null || bb.remaining() == 0) {
throw new EndOfBufferException();
}
Expand All @@ -117,7 +124,7 @@ public void advance() {
int len = nextAdvance;
ByteBuffer bb;
while (true) {
bb = link.peekFirst();
bb = link.getFirst();
if (len < bb.remaining()) {
bb.position(bb.position() + len);
break;
Expand Down Expand Up @@ -169,7 +176,10 @@ private void requireMore(int n) throws EOFException {
}

private ByteBuffer require(int n) throws EOFException {
ByteBuffer bb = link.peekFirst();
ByteBuffer bb = null;
try {
bb = link.getFirst();
} catch(NoSuchElementException e) {}
if (bb == null) {
throw new EndOfBufferException();
}
Expand Down Expand Up @@ -227,7 +237,7 @@ public void feed(byte[] b, int off, int len) {

public void feed(byte[] b, int off, int len, boolean reference) {
if (reference) {
if (writable > 0 && link.peekLast().remaining() == 0) {
if (writable > 0 && link.getLast().remaining() == 0) {
link.add(link.size()-1, ByteBuffer.wrap(b, off, len));
return;
}
Expand All @@ -236,7 +246,10 @@ public void feed(byte[] b, int off, int len, boolean reference) {
return;
}

ByteBuffer bb = link.peekLast();
ByteBuffer bb = null;
try {
bb = link.getLast();
} catch(NoSuchElementException e) {}
if (len <= writable) {
int pos = bb.position();
bb.position(bb.limit());
Expand Down Expand Up @@ -273,7 +286,7 @@ public void feed(ByteBuffer b) {

public void feed(ByteBuffer buf, boolean reference) {
if (reference) {
if (writable > 0 && link.peekLast().remaining() == 0) {
if (writable > 0 && link.getLast().remaining() == 0) {
link.add(link.size()-1, buf);
return;
}
Expand All @@ -284,7 +297,10 @@ public void feed(ByteBuffer buf, boolean reference) {

int rem = buf.remaining();

ByteBuffer bb = link.peekLast();
ByteBuffer bb = null;
try {
bb = link.getLast();
} catch(NoSuchElementException e) {}
if (rem <= writable) {
int pos = bb.position();
bb.position(bb.limit());
Expand Down