public short unpackShort ( ) throws IOException { byte b = readByte ( ) ; if ( Code . isFixInt ( b ) ) { return ( short ) b ; } switch ( b ) { case Code . UINT8 : // unsigned int 8 byte u8 = readByte ( ) ; return ( short ) ( u8 & 0xff ) ; case Code . UINT16 : // unsigned int 16 short u16 = readShort ( ) ; if ( u16 < ( short ) 0 ) { throw overflowU16 ( u16 ) ; } return u16 ; case Code . UINT32 : // unsigned int 32 int u32 = readInt ( ) ; if ( u32 < 0 || u32 > Short . MAX_VALUE ) { throw overflowU32 ( u32 ) ; } return ( short ) u32 ; case Code . UINT64 : // unsigned int 64 long u64 = readLong ( ) ; if ( u64 < 0L || u64 > Short . MAX_VALUE ) { throw overflowU64 ( u64 ) ; } return ( short ) u64 ; case Code . INT8 : // signed int 8 byte i8 = readByte ( ) ; return ( short ) i8 ; case Code . INT16 : // signed int 16 short i16 = readShort ( ) ; return i16 ; case Code . INT32 : // signed int 32 int i32 = readInt ( ) ; if ( i32 < Short . MIN_VALUE || i32 > Short . MAX_VALUE ) { throw overflowI32 ( i32 ) ; } return ( short ) i32 ; case Code . INT64 : // signed int 64 long i64 = readLong ( ) ; if ( i64 < Short . MIN_VALUE || i64 > Short . MAX_VALUE ) { throw overflowI64 ( i64 ) ; } return ( short ) i64 ; } throw unexpected ( "Integer" , b ) ; }
Reads a short .