public byte[] toByteArray() {
    byte[] result = new byte[cursor];
    System.arraycopy(data, 0, result, 0, cursor);
    return result;
  }
Constructs and returns a new {@code byte[]} that contains the written contents exactly (that
is, with no extra unwritten bytes at the end).

@return {@code non-null;} an appropriately-constructed array
@see #getArray
android/android_framework/dex-maker/src/main/java/com/android/dx/util/ByteArrayAnnotatedOutput.java