Skip to content

Commit d111ee3

Browse files
author
Wojciech Strzalka
committed
Add handling of unexpected end of data stream
1 parent a2e364e commit d111ee3

File tree

5 files changed

+317
-6
lines changed

5 files changed

+317
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
- Java: Add handling of unexpected end of data stream [ISSUE#80](https://github.com/openstreetmap/OSM-binary/issues/80)
4+
35
## Release notes for 1.6.0 (2024-12-10)
46

57
- Java: Update to latest protoc and protobuf runtime versions [#84](https://github.com/openstreetmap/OSM-binary/pull/84)

resources/broken7000bytes.pbf

12.3 KB
Binary file not shown.

src.java/crosby/binary/file/BlockInputStream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ License, or (at your option) any later version.
1818
package crosby.binary.file;
1919

2020
import java.io.Closeable;
21-
import java.io.EOFException;
2221
import java.io.IOException;
2322
import java.io.InputStream;
2423

@@ -29,13 +28,14 @@ public BlockInputStream(InputStream input, BlockReaderAdapter adaptor) {
2928
this.adaptor = adaptor;
3029
}
3130

32-
public void process() throws IOException {
31+
public void process() throws Exception {
3332
try {
34-
while (true) {
33+
while (input.available() > 0) {
3534
FileBlock.process(input, adaptor);
3635
}
37-
} catch (EOFException e) {
3836
adaptor.complete();
37+
} catch (Exception e) {
38+
adaptor.failure(e);
3939
}
4040
}
4141

src.java/crosby/binary/file/BlockReaderAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ public interface BlockReaderAdapter {
3737

3838
/** Called when the file is fully read. */
3939
void complete();
40+
41+
void failure(Exception e) throws Exception;
4042
}

0 commit comments

Comments
 (0)