Here you can find the source of toShort(ByteBuffer buffer)
public static short toShort(ByteBuffer buffer)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static short toShort(byte[] bytes) { return toShort(ByteBuffer.wrap(bytes)); }/*from w w w . j a v a 2s . co m*/ public static short toShort(ByteBuffer buffer) { return toByteBuffer(buffer, Short.BYTES).getShort(); } protected static ByteBuffer toByteBuffer(ByteBuffer buffer, int length) { if (length > buffer.remaining()) { return (ByteBuffer) ((ByteBuffer) ByteBuffer.allocate(length).position(length - buffer.remaining())) .put(buffer.array()).rewind(); } else { return buffer; } } }