private static native long nativeWriteFileDescriptor(long nativePtr, FileDescriptor val);
private static native byte[] nativeCreateByteArray(long nativePtr);
+ private static native boolean nativeReadByteArray(long nativePtr, byte[] dest, int destLen);
private static native byte[] nativeReadBlob(long nativePtr);
@FastNative
private static native int nativeReadInt(long nativePtr);
* given byte array.
*/
public final void readByteArray(byte[] val) {
- // TODO: make this a native method to avoid the extra copy.
- byte[] ba = createByteArray();
- if (ba.length == val.length) {
- System.arraycopy(ba, 0, val, 0, ba.length);
- } else {
+ boolean valid = nativeReadByteArray(mNativePtr, val, (val != null) ? val.length : 0);
+ if (!valid) {
throw new RuntimeException("bad array lengths");
}
}