Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.30 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         public static short readShort(InputStream in) throws IOException {
  2.                 byte a = (byte) in.read();
  3.                 byte b = (byte) in.read();
  4.                
  5.                 ByteBuffer bb = ByteBuffer.allocate(2);
  6.                 bb.order(ByteOrder.BIG_ENDIAN);
  7.                
  8.                 bb.put(a);
  9.                 bb.put(b);
  10.                
  11.                 short result = bb.getShort(0);
  12.                 return result;         
  13.         }