Java Convert via ByteBuffer toShortArray(final byte[] byteArray)

Here you can find the source of toShortArray(final byte[] byteArray)

Description

to Short Array

License

Open Source License

Declaration

public static short[] toShortArray(final byte[] byteArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Main {
    public static short[] toShortArray(final byte[] byteArray) {
        short[] shortArray = new short[byteArray.length];
        for (int i = 0; i < byteArray.length; i++) {
            shortArray[i] = toShort(byteArray[i]);
        }// w  ww. ja  va 2  s. co  m
        return shortArray;
    }

    public static short toShort(final byte byteValue) {
        return toShort(byteValue, ByteOrder.LITTLE_ENDIAN);
    }

    public static short toShort(final byte byteValue,
            final ByteOrder byteOrder) {
        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(2);
        byteBuffer.order(byteOrder);
        byteBuffer.put(byteValue);
        byteBuffer.put((byte) 0x00);
        byteBuffer.flip();
        return byteBuffer.getShort();
    }
}

Related

  1. toMsftBinary(UUID uuid)
  2. toShort(byte firstByte, byte secondByte)
  3. toShort(byte[] bytes, int index)
  4. toShort(final byte byteValue, final ByteOrder byteOrder)
  5. toShortArray(byte[] arr)
  6. toSimpleList(List attrValues)
  7. toString(byte[] buf, int arrayOffset, int origLimit, StringBuilder sb)
  8. toString(byte[] value, int offset, int length, String encoding)
  9. toString(final String filename)