kaitai-io / kaitai_struct_java_runtime

Kaitai Struct: runtime for Java
MIT License
42 stars 18 forks source link

What's the reason for the unneeded IOExceptions? #3

Closed ams-tschoening closed 7 years ago

ams-tschoening commented 7 years ago

I wonder why lot's of methods in the runtime say to throw an IOException, when the accessed methods of the underlying ByteBuffer actually don't?

isEof, seek, size, none of the methods of ByteBuffer called seem to throw IOException, even lots of the read methods don't. Compare readS1 to readS2be, the former doesn't even say to throw IOException, the latter does, while actually the underlying ByteBuffer doesn't throw in both cases.

In my opinion it would be easier for all users of your code to remove all unnecessary throws statements and I would like to do so and provide a pull request. But I might be missing something...

GreyCat commented 7 years ago

Actually, there were 2 implementations of Java runtime: older one that used RandomAccessFile + ByteArrayInputStream, and a newer one, which uses ByteBuffer backed by channels (now in git master).

Older one used to propagate IOExceptions thrown frequently by many read / seek / query operations. Indeed, currently all these IOExceptions are not needed, at least if you don't want to be able to swap older / newer implementations.

ams-tschoening commented 7 years ago

I got my answer and the merge, so closing this.