code: public static void writeBuffer(DataOutput out, ByteBuffer buffer) throws IOException {
          if (buffer.hasArray()) {
              out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
              buffer.position(buffer.limit());
          } else {
              final byte[] array = new byte[buffer.remaining()];
              buffer.get(array);
              assert buffer.remaining() == 0 && buffer.position() == buffer.limit();
              out.write(array);
          }
      }
docs: Writes the given {@link ByteBuffer} into the given {@link DataOutput}.
  
  @param out The {@link DataOutput} into which the buffer will be written.
  @param buffer The buffer to write into the {@link DataOutput}.
  @throws IOException