Skip to content

Fix ByteArrayInputStream throw unexcepted EOFException #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ByteArrayInputStream extends InputStream {
private InputStream inputStream;
private int peek = -1;
private int pos, markPosition;
private int blockLength = -1;
private int blockLength = -1, markBlockLength = -1;
private int initialBlockLength = -1;

public ByteArrayInputStream(InputStream inputStream) {
Expand Down Expand Up @@ -294,6 +294,7 @@ public int getPosition() {
@Override
public synchronized void mark(int readlimit) {
markPosition = pos;
markBlockLength = blockLength;
inputStream.mark(readlimit);
}

Expand All @@ -305,6 +306,7 @@ public boolean markSupported() {
@Override
public synchronized void reset() throws IOException {
pos = markPosition;
blockLength = markBlockLength;
inputStream.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ public void testPeekAndReadToArray() throws Exception {
assertEquals(b[0], 5);
assertEquals(b[2], 7);
}

@Test
public void testMarkAndReset() throws Exception {
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {1, 2, 3, 4});
in.enterBlock(4);
in.mark(4);
in.readInteger(4);
in.reset();

assertEquals(1, in.read());
assertEquals(2, in.read());
assertEquals(3, in.read());
assertEquals(4, in.read());
}
}