Wrapping the InputStream for an entry with java.nio.channel.Channels.newChannel(), allocating a ByteBuffer larger than the entry, and using a while( (read = chan.read(buffer)) != -1 ) loop corrupts the remainder and position members of the stream and results in an IndexOutOfBoundsException on the next read, instead of a -1 indicating EOF. The fix is to modify the position and remainder members by the amount read from the filesystem member, instead of the parameter passed in.
The autoclosing of the entry once it reached EOF also prevented normal termination of the loop because the first read consumes all the bytes in the entry and returns that number, and the next read trips over the ensureOpen() check with a runtime exception. The rest of this patch ensures that -1 can be returned by a read() at EOF by not autoclosing when reaching EOF on the previous read. I changed ensureOpen() to throw IOException instead of a runtime exception, similar to what Zip/JarInputStream does.
Patch for net.didion.loopy.iso9660.EntryInputStream reads