Skip to content

Commit fcb9194

Browse files
authored
Merge pull request shyiko#55 from morozov/eof-details
Add details to the EOF exceptions
2 parents 96edcd5 + bd5959d commit fcb9194

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ByteArrayInputStream extends InputStream {
2929
private Integer peek;
3030
private Integer pos, markPosition;
3131
private int blockLength = -1;
32+
private int initialBlockLength = -1;
3233

3334
public ByteArrayInputStream(InputStream inputStream) {
3435
this.inputStream = inputStream;
@@ -110,7 +111,10 @@ public void fill(byte[] bytes, int offset, int length) throws IOException {
110111
while (remaining != 0) {
111112
int read = read(bytes, offset + length - remaining, remaining);
112113
if (read == -1) {
113-
throw new EOFException();
114+
throw new EOFException(
115+
String.format("Failed to read remaining %d of %d bytes from position %d. Block length: %d. Initial block length: %d.",
116+
remaining, length, pos, blockLength, initialBlockLength)
117+
);
114118
}
115119
remaining -= read;
116120
}
@@ -206,7 +210,7 @@ public int read() throws IOException {
206210
peek = null;
207211
}
208212
if (result == -1) {
209-
throw new EOFException();
213+
throw new EOFException(String.format("Failed to read next byte from position %d", this.pos));
210214
}
211215
this.pos += 1;
212216
return result;
@@ -273,6 +277,7 @@ public void close() throws IOException {
273277

274278
public void enterBlock(int length) {
275279
this.blockLength = length < -1 ? -1 : length;
280+
this.initialBlockLength = length;
276281
}
277282

278283
public void skipToTheEndOfTheBlock() throws IOException {

0 commit comments

Comments
 (0)