title: convert a LongBuffer/IntBuffer/ShortBuffer to ByteBuffer
body: <p>I know a quick way to convert a byte/short/int/long array to ByteBuffer, and then obtain a byte array. For instance, to convert a byte array to short array I can do:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>produces a short array like this: <code>[256, 0, 0, 0, 256, 0, 0, 0]</code>.</p>
  
  <p><strong>How can I do the inverse operation using <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/package-summary.html">java.nio</a> classes?</strong></p>
  
  <p>Now I am doing this:</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>And I obtain the original <code>[1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]</code> byte array. But  I want to use a method like ShortBuffer.asByteBuffer(), not a manual loop to do it.</p>
  
  <p>I have found a <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4489356">request to Sun of 2001</a>, but they did not accept it ;-(( </p>