converter um LongBuffer / IntBuffer / ShortBuffer para ByteBuffer

Eu sei uma maneira rápida de converter um byte / short / int / long array para ByteBuffer e, em seguida, obter uma matriz de bytes. Por exemplo, para converter uma matriz de bytes em uma matriz curta, posso fazer:

byte[] bArray = { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 };

ByteBuffer bb = ByteBuffer.wrap(byteArray);
ShortBuffer sb = bb.asShortBuffer();
short[] shortArray = new short[byteArray.length / 2];
sb.get(shortArray);

produz uma matriz curta como esta:[256, 0, 0, 0, 256, 0, 0, 0].

Como posso fazer a operação inversa usandojava.nio classes?

Agora estou fazendo isso:

shortArray[] = {256, 0, 0, 0, 256, 0, 0, 0};
ByteBuffer bb = ByteBuffer.allocate(shortArray.length * 2);
for (short s : shortArray) {
    bb.putShort(s);
}
return bb.array();

E eu obtenho o original[1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0] matriz de bytes. Mas eu quero usar um método como ShortBuffer.asByteBuffer (), não um loop manual para fazê-lo.

Eu encontrei umpedido para Sun de 2001, mas eles não o aceitaram; - ((

questionAnswers(3)

yourAnswerToTheQuestion