public byte[] toByteArray(int offset, int length) {
    ByteBuffer bb = curBuf.duplicate();
    bb.flip();

    byte[] chunk = new byte[length];

    bb.position(offset);
    bb.get(chunk, 0, length);
    return chunk;
  }
Writes an <code>int</code> to the underlying output stream as four bytes, high byte first.
@param i the <code>int</code> to write
@throws IOException if an I/O error occurs.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBufferOutputStream.java