Skip to content
Snippets Groups Projects
Unverified Commit 4d8a84a4 authored by akwizgran's avatar akwizgran
Browse files

Don't throw IllegalStateException if BDF input is incomplete.

parent 2650f311
No related branches found
No related tags found
Loading
......@@ -4,6 +4,8 @@ import java.io.IOException;
public interface BdfReader {
int DEFAULT_NESTED_LIMIT = 5;
boolean eof() throws IOException;
void close() throws IOException;
......
......
......@@ -5,4 +5,6 @@ import java.io.InputStream;
public interface BdfReaderFactory {
BdfReader createReader(InputStream in);
BdfReader createReader(InputStream in, int nestedLimit);
}
......@@ -5,9 +5,17 @@ import org.briarproject.api.data.BdfReaderFactory;
import java.io.InputStream;
import static org.briarproject.api.data.BdfReader.DEFAULT_NESTED_LIMIT;
class BdfReaderFactoryImpl implements BdfReaderFactory {
@Override
public BdfReader createReader(InputStream in) {
return new BdfReaderImpl(in);
return new BdfReaderImpl(in, DEFAULT_NESTED_LIMIT);
}
@Override
public BdfReader createReader(InputStream in, int nestedLimit) {
return new BdfReaderImpl(in, nestedLimit);
}
}
......@@ -32,21 +32,14 @@ import static org.briarproject.data.Types.TRUE;
@NotThreadSafe
class BdfReaderImpl implements BdfReader {
final static int DEFAULT_NESTED_LIMIT = 5;
private static final byte[] EMPTY_BUFFER = new byte[] {};
private static final byte[] EMPTY_BUFFER = new byte[0];
private final InputStream in;
private final int nestedLimit;
private boolean hasLookahead = false, eof = false;
private byte next;
private byte[] buf = new byte[8];
private final int nestedLimit;
BdfReaderImpl(InputStream in) {
this.in = in;
this.nestedLimit = DEFAULT_NESTED_LIMIT;
}
BdfReaderImpl(InputStream in, int nestedLimit) {
this.in = in;
......@@ -54,7 +47,7 @@ class BdfReaderImpl implements BdfReader {
}
private void readLookahead() throws IOException {
if (eof) throw new IllegalStateException();
if (eof) return;
if (hasLookahead) throw new IllegalStateException();
// Read a lookahead byte
int i = in.read();
......
......
File changed. Contains only whitespace changes. Show whitespace changes.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment