[AMQ-6831, AMQ-6771] trigger eofexception on read -1 - AMQ6522Test

(cherry picked from commit e793260573)
This commit is contained in:
gtully 2017-10-11 00:20:26 +01:00 committed by Christopher L. Shannon (cshannon)
parent b19ed4815b
commit d66e96e8bc
2 changed files with 12 additions and 2 deletions

View File

@ -75,7 +75,11 @@ public class ByteSequence {
public void reset() {
length = remaining();
System.arraycopy(data, offset, data, 0, length);
if (length > 0) {
System.arraycopy(data, offset, data, 0, length);
} else {
length = 0;
}
offset = 0;
}

View File

@ -627,7 +627,13 @@ public class Journal {
private void ensureAvailable(ByteSequence bs, RandomAccessFile reader, int required) throws IOException {
if (bs.remaining() < required) {
bs.reset();
bs.setLength(bs.length + reader.read(bs.data, bs.length, bs.data.length - bs.length));
int read = reader.read(bs.data, bs.length, bs.data.length - bs.length);
if (read < 0) {
if (bs.remaining() == 0) {
throw new EOFException("request for " + required + " bytes reached EOF");
}
}
bs.setLength(bs.length + read);
}
}