Here you can find the source of toShorts(byte[] array, int offset, int length)
public static short[] toShorts(byte[] array, int offset, int length)
//package com.java2s; public class Main { /**/*from w ww. ja va 2 s .c o m*/ * Returns a short array built from a byte array. Each 2 bytes form * a short with the first byte as the short's MSB (big-endian order). * <p> * If offset and length are omitted, the whole array is used. */ public static short[] toShorts(byte[] array, int offset, int length) { short[] buf = new short[length / 2]; int j = 0; for (int i = offset; i < offset + length - 1; i += 2) buf[j++] = (short) (((array[i] & 0xFF) << 8) | (array[i + 1] & 0xFF)); return buf; } public static short[] toShorts(byte[] array) { return toShorts(array, 0, array.length); } }