Commit be15f0cd authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Make sure that the decoder always returns an EOF at the end of the stream.

Due to a logic bug, the Simulink Decoder would throw RuntimeExceptions instead
of EOFExceptions after the first EOF.  Fix this by handling the state after
the first EOF explicitly.
parent 8fd1d16c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ public class SimulinkDecoder extends InputStream
                    ret = (leftover << 6) | next;
                    break;
                }
                case -1: { // We need to explicitly deal with the -1 case, as -1 % 4 in Java is -1.
                    throw new EOFException("No more bytes!");
                }
                default:
                    throw new RuntimeException("Case " + (pos % 4));
            }
+9 −0
Original line number Diff line number Diff line
@@ -94,6 +94,15 @@ public class SimulinkMatTest
        }
        assertThat(atEnd, is(true));

        // Double check that EOF will be re-thrown on each extra call to read.
        atEnd = false;
        try {
            decoder.read();
        } catch (EOFException ex) {
            atEnd = true;
        }
        assertThat(atEnd, is(true));

        byte[] expectedBuf = new byte[20144];
        SimulinkMatTest.class.getResourceAsStream("/simulink_tet_out.mat").read(expectedBuf);