@Test(dependsOnMethods="testSafeRead") public void testReadShort() throws IOException { ByteBuffer buffer = ByteBuffer.allocate(1024); buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putShort((short)0).putShort((short)1).putShort((short)2).putShort((short)-1).putShort((short)-2); InputStream in = new ByteArrayInputStream(buffer.array(), 0, buffer.position()); Assert.assertEquals(IoUtils.readShort(in), 0); Assert.assertEquals(IoUtils.readShort(in), 1); Assert.assertEquals(IoUtils.readShort(in), 2); Assert.assertEquals(IoUtils.readShort(in), -1); Assert.assertEquals(IoUtils.readShort(in), -2); }
public static int readShort(InputStream in) throws IOException { int b0 = safeRead(in); int b1 = safeRead(in); int i = b1 << 8 | b0; if ((b1 & 0x80) == 0x80) { i |= 0xffff0000; } return i; }
IoUtils { public static int readShort(InputStream in) throws IOException { int b0 = safeRead(in); int b1 = safeRead(in); int i = b1 << 8 | b0; if ((b1 & 0x80) == 0x80) { i |= 0xffff0000; } return i; } }
IoUtils { public static int readShort(InputStream in) throws IOException { int b0 = safeRead(in); int b1 = safeRead(in); int i = b1 << 8 | b0; if ((b1 & 0x80) == 0x80) { i |= 0xffff0000; } return i; } private  IoUtils(); }
IoUtils { public static int readShort(InputStream in) throws IOException { int b0 = safeRead(in); int b1 = safeRead(in); int i = b1 << 8 | b0; if ((b1 & 0x80) == 0x80) { i |= 0xffff0000; } return i; } private  IoUtils(); static int safeRead(InputStream in); static int readShort(InputStream in); static int readUnsignedShort(InputStream in); static void writeShort(OutputStream out, int i); static void writeInt(OutputStream out, int i); static int readUnsignedMediumInt(InputStream in); static int readMediumInt(InputStream in); static int readInt(InputStream in); static long readUnsignedInt(InputStream in); static long readLong(InputStream in); static long readBinaryLengthEncoding(InputStream in); static long readBinaryLengthEncoding(InputStream in, int firstByte); static String readLengthCodedString(InputStream in, String charset); static String readLengthCodedString(InputStream in, int firstByte, String charset); static String readString(InputStream in, String charset); static String readFixedLengthString(InputStream in, int length, String charset); static Set<FieldFlag> readEnumSet(InputStream in, Class<FieldFlag> enumClass); static EnumSet<E> readEnumSetShort(InputStream in, Class<E> enumClass); static E readEnum(InputStream in, Class<E> enumClass); static void writeEnumSetShort(OutputStream out, Set<E> set); }
IoUtils { public static int readShort(InputStream in) throws IOException { int b0 = safeRead(in); int b1 = safeRead(in); int i = b1 << 8 | b0; if ((b1 & 0x80) == 0x80) { i |= 0xffff0000; } return i; } private  IoUtils(); static int safeRead(InputStream in); static int readShort(InputStream in); static int readUnsignedShort(InputStream in); static void writeShort(OutputStream out, int i); static void writeInt(OutputStream out, int i); static int readUnsignedMediumInt(InputStream in); static int readMediumInt(InputStream in); static int readInt(InputStream in); static long readUnsignedInt(InputStream in); static long readLong(InputStream in); static long readBinaryLengthEncoding(InputStream in); static long readBinaryLengthEncoding(InputStream in, int firstByte); static String readLengthCodedString(InputStream in, String charset); static String readLengthCodedString(InputStream in, int firstByte, String charset); static String readString(InputStream in, String charset); static String readFixedLengthString(InputStream in, int length, String charset); static Set<FieldFlag> readEnumSet(InputStream in, Class<FieldFlag> enumClass); static EnumSet<E> readEnumSetShort(InputStream in, Class<E> enumClass); static E readEnum(InputStream in, Class<E> enumClass); static void writeEnumSetShort(OutputStream out, Set<E> set); static final int NULL_VALUE; }