@@ -320,7 +320,7 @@ private void consume(int numBytes) throws IOException {
320320 */
321321 private byte readByte () throws IOException {
322322 if (!ensure (1 )) {
323- throw new MessageFormatException ("insufficient data length for reading byte value" );
323+ throw new EOFException ("insufficient data length for reading byte value" );
324324 }
325325 byte b = buffer .getByte (position );
326326 consume (1 );
@@ -329,7 +329,7 @@ private byte readByte() throws IOException {
329329
330330 private short readShort () throws IOException {
331331 if (!ensure (2 )) {
332- throw new MessageFormatException ("insufficient data length for reading short value" );
332+ throw new EOFException ("insufficient data length for reading short value" );
333333 }
334334 short s = buffer .getShort (position );
335335 consume (2 );
@@ -338,7 +338,7 @@ private short readShort() throws IOException {
338338
339339 private int readInt () throws IOException {
340340 if (!ensure (4 )) {
341- throw new MessageFormatException ("insufficient data length for reading int value" );
341+ throw new EOFException ("insufficient data length for reading int value" );
342342 }
343343 int i = buffer .getInt (position );
344344 consume (4 );
@@ -347,7 +347,7 @@ private int readInt() throws IOException {
347347
348348 private float readFloat () throws IOException {
349349 if (!ensure (4 )) {
350- throw new MessageFormatException ("insufficient data length for reading float value" );
350+ throw new EOFException ("insufficient data length for reading float value" );
351351 }
352352 float f = buffer .getFloat (position );
353353 consume (4 );
@@ -356,7 +356,7 @@ private float readFloat() throws IOException {
356356
357357 private long readLong () throws IOException {
358358 if (!ensure (8 )) {
359- throw new MessageFormatException ("insufficient data length for reading long value" );
359+ throw new EOFException ("insufficient data length for reading long value" );
360360 }
361361 long l = buffer .getLong (position );
362362 consume (8 );
@@ -365,7 +365,7 @@ private long readLong() throws IOException {
365365
366366 private double readDouble () throws IOException {
367367 if (!ensure (8 )) {
368- throw new MessageFormatException ("insufficient data length for reading double value" );
368+ throw new EOFException ("insufficient data length for reading double value" );
369369 }
370370 double d = buffer .getDouble (position );
371371 consume (8 );
@@ -386,13 +386,17 @@ public void skipBytes(int numBytes) throws IOException {
386386 }
387387
388388 /**
389- * Skip the next value, then move the cursor at the end of that value
389+ * Skip the next value, then move the cursor at the end of the value
390390 *
391391 * @throws IOException
392392 */
393393 public void skipValue () throws IOException {
394394 int remainingValues = 1 ;
395- while (!reachedEOF && remainingValues > 0 ) {
395+ while (remainingValues > 0 ) {
396+ if (reachedEOF ) {
397+ throw new EOFException ();
398+ }
399+
396400 MessageFormat f = getNextFormat ();
397401 byte b = consume ();
398402 switch (f ) {
@@ -503,7 +507,7 @@ public void skipValue() throws IOException {
503507 * @throws MessageFormatException
504508 */
505509 private static MessageTypeException unexpected (String expected , byte b )
506- throws MessageFormatException {
510+ throws MessageTypeException {
507511 ValueType type = ValueType .valueOf (b );
508512 return new MessageTypeException (String .format ("Expected %s, but got %s (%02x)" , expected , type .toTypeName (), b ));
509513 }
0 commit comments