ByteBuffer byteBuffer = new ByteBuffer(); if (isAllZeroes(array, offset, length)) { byteBuffer.setDataSize(length); byteBuffer.writeItem(new FakeEncodedItem(length, new byte[length])); return byteBuffer; byteBuffer.writeItem(new FakeEncodedItem(sizeOf, value));
@Implementation(minSdk = LOLLIPOP) @SuppressWarnings("robolectric.ShadowReturnTypeMismatch") protected static void nativeAppendFrom( long thisNativePtr, long otherNativePtr, int offset, int length) { ByteBuffer thisByteBuffer = NATIVE_PTR_TO_PARCEL.get(thisNativePtr); ByteBuffer otherByteBuffer = NATIVE_PTR_TO_PARCEL.get(otherNativePtr); thisByteBuffer.appendFrom(otherByteBuffer, offset, length); }
@Implementation(minSdk = LOLLIPOP) @SuppressWarnings("robolectric.ShadowReturnTypeMismatch") protected static void nativeFreeBuffer(long nativePtr) { NATIVE_PTR_TO_PARCEL.get(nativePtr).clear(); }
/** * Creates a Byte buffer from a raw byte array. * * @param array byte array to read from * @param offset starting position in bytes to start reading array at * @param length number of bytes to read from array */ public static ByteBuffer fromByteArray(byte[] array, int offset, int length) { ByteBuffer byteBuffer = new ByteBuffer(); try { ByteArrayInputStream bis = new ByteArrayInputStream(array, offset, length); ObjectInputStream ois = new ObjectInputStream(bis); int numElements = ois.readInt(); for (int i = 0; i < numElements; i++) { int sizeOf = ois.readInt(); Object value = ois.readObject(); byteBuffer.buffer.add(Pair.create(sizeOf, value)); } return byteBuffer; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates a Byte buffer from a raw byte array. * * @param array byte array to read from * @param offset starting position in bytes to start reading array at * @param length number of bytes to read from array */ public static ByteBuffer fromByteArray(byte[] array, int offset, int length) { ByteBuffer byteBuffer = new ByteBuffer(); try { ByteArrayInputStream bis = new ByteArrayInputStream(array, offset, length); ObjectInputStream ois = new ObjectInputStream(bis); int numElements = ois.readInt(); for (int i = 0; i < numElements; i++) { int sizeOf = ois.readInt(); Object value = ois.readObject(); byteBuffer.buffer.add(Pair.create(sizeOf, value)); } return byteBuffer; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates a Byte buffer from a raw byte array. * * @param array byte array to read from * @param offset starting position in bytes to start reading array at * @param length number of bytes to read from array */ public static ByteBuffer fromByteArray(byte[] array, int offset, int length) { ByteBuffer byteBuffer = new ByteBuffer(); try { ByteArrayInputStream bis = new ByteArrayInputStream(array, offset, length); ObjectInputStream ois = new ObjectInputStream(bis); int numElements = ois.readInt(); for (int i = 0; i < numElements; i++) { int sizeOf = ois.readInt(); Object value = ois.readObject(); byteBuffer.buffer.add(Pair.create(sizeOf, value)); } return byteBuffer; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Creates a Byte buffer from a raw byte array. * * @param array byte array to read from * @param offset starting position in bytes to start reading array at * @param length number of bytes to read from array */ public static ByteBuffer fromByteArray(byte[] array, int offset, int length) { ByteBuffer byteBuffer = new ByteBuffer(); try { ByteArrayInputStream bis = new ByteArrayInputStream(array, offset, length); ObjectInputStream ois = new ObjectInputStream(bis); int numElements = ois.readInt(); for (int i = 0; i < numElements; i++) { int sizeOf = ois.readInt(); Object value = ois.readObject(); byteBuffer.buffer.add(Pair.create(sizeOf, value)); } return byteBuffer; } catch (Exception e) { throw new RuntimeException(e); } }
@Implementation(minSdk = LOLLIPOP) protected static int nativeDataPosition(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataPosition(); }
@Implementation(minSdk = LOLLIPOP) public static int nativeDataSize(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataSize(); }
/** * Reads a byte array from the byte buffer based on the current data position */ public boolean readByteArray(byte[] dest, int destLen) { int length = readInt(); if (length >= 0 && length <= dataAvailable() && length == destLen) { for (int i = 0; i < length; i++) { dest[i] = readByte(); } return true; } return false; }
@Implementation(minSdk = LOLLIPOP) public static int nativeDataAvail(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataAvailable(); }
@Implementation @HiddenApi public static int nativeDataPosition(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataPosition(); }
@Implementation(minSdk = LOLLIPOP) public static double nativeReadDouble(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).readDouble(); }
@Implementation(minSdk = LOLLIPOP) public static void nativeFreeBuffer(long nativePtr) { NATIVE_PTR_TO_PARCEL.get(nativePtr).clear(); }
@Implementation(minSdk = O_MR1) protected static boolean nativeReadByteArray(long nativePtr, byte[] dest, int destLen) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).readByteArray(dest, destLen); }
@Implementation(minSdk = LOLLIPOP) public static byte[] nativeCreateByteArray(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).readByteArray(); }
@Implementation(minSdk = LOLLIPOP) protected static int nativeDataAvail(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataAvailable(); }
@Implementation(minSdk = LOLLIPOP) public static int nativeDataPosition(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataPosition(); }
@Implementation(minSdk = LOLLIPOP) public static byte[] nativeCreateByteArray(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).readByteArray(); }
@Implementation(minSdk = LOLLIPOP) public static int nativeDataAvail(long nativePtr) { return NATIVE_PTR_TO_PARCEL.get(nativePtr).dataAvailable(); }