@@ -441,11 +441,68 @@ default int readUnsignedByte() throws IOException {
441441 return readByte () & 0xff ;
442442 }
443443
444+ @ Override
445+ default short readShort () throws IOException {
446+ final int ch1 = read ();
447+ final int ch2 = read ();
448+ if ((ch1 | ch2 ) < 0 ) throw new EOFException ();
449+ return (short ) ((ch1 << 8 ) + (ch2 << 0 ));
450+ }
451+
444452 @ Override
445453 default int readUnsignedShort () throws IOException {
446454 return readShort () & 0xffff ;
447455 }
448456
457+ @ Override
458+ default char readChar () throws IOException {
459+ return (char ) readShort ();
460+ }
461+
462+ @ Override
463+ default int readInt () throws IOException {
464+ int ch1 = read ();
465+ int ch2 = read ();
466+ int ch3 = read ();
467+ int ch4 = read ();
468+ if ((ch1 | ch2 | ch3 | ch4 ) < 0 ) throw new EOFException ();
469+ return ((ch1 << 24 ) + (ch2 << 16 ) + (ch3 << 8 ) + (ch4 << 0 ));
470+ }
471+
472+ @ Override
473+ default long readLong () throws IOException {
474+ int ch1 = read ();
475+ int ch2 = read ();
476+ int ch3 = read ();
477+ int ch4 = read ();
478+ int ch5 = read ();
479+ int ch6 = read ();
480+ int ch7 = read ();
481+ int ch8 = read ();
482+ if ((ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8 ) < 0 ) {
483+ throw new EOFException ();
484+ }
485+ // TODO: Double check this inconsistent code.
486+ return ((long ) ch1 << 56 ) + //
487+ ((long ) (ch2 & 255 ) << 48 ) + //
488+ ((long ) (ch3 & 255 ) << 40 ) + //
489+ ((long ) (ch4 & 255 ) << 32 ) + //
490+ ((long ) (ch5 & 255 ) << 24 ) + //
491+ ((ch6 & 255 ) << 16 ) + //
492+ ((ch7 & 255 ) << 8 ) + //
493+ ((ch8 & 255 ) << 0 );
494+ }
495+
496+ @ Override
497+ default float readFloat () throws IOException {
498+ return Float .intBitsToFloat (readInt ());
499+ }
500+
501+ @ Override
502+ default double readDouble () throws IOException {
503+ return Double .longBitsToDouble (readLong ());
504+ }
505+
449506 @ Override
450507 default String readLine () throws IOException {
451508 // NB: Code adapted from java.io.RandomAccessFile.readLine().
@@ -510,6 +567,42 @@ default void writeByte(final int v) throws IOException {
510567 write (v );
511568 }
512569
570+ @ Override
571+ default void writeChar (final int v ) throws IOException {
572+ write ((v >>> 8 ) & 0xFF );
573+ write ((v >>> 0 ) & 0xFF );
574+ }
575+
576+ @ Override
577+ default void writeInt (final int v ) throws IOException {
578+ write ((v >>> 24 ) & 0xFF );
579+ write ((v >>> 16 ) & 0xFF );
580+ write ((v >>> 8 ) & 0xFF );
581+ write ((v >>> 0 ) & 0xFF );
582+ }
583+
584+ @ Override
585+ default void writeLong (final long v ) throws IOException {
586+ write ((byte ) (v >>> 56 ));
587+ write ((byte ) (v >>> 48 ));
588+ write ((byte ) (v >>> 40 ));
589+ write ((byte ) (v >>> 32 ));
590+ write ((byte ) (v >>> 24 ));
591+ write ((byte ) (v >>> 16 ));
592+ write ((byte ) (v >>> 8 ));
593+ write ((byte ) (v >>> 0 ));
594+ }
595+
596+ @ Override
597+ default void writeFloat (final float v ) throws IOException {
598+ writeInt (Float .floatToIntBits (v ));
599+ }
600+
601+ @ Override
602+ default void writeDouble (final double v ) throws IOException {
603+ writeLong (Double .doubleToLongBits (v ));
604+ }
605+
513606 @ Override
514607 default void writeBytes (final String s ) throws IOException {
515608 write (s .getBytes ("UTF-8" ));
0 commit comments