本文整理了Java中android.os.Parcel.createByteArray()
方法的一些代码示例,展示了Parcel.createByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parcel.createByteArray()
方法的具体详情如下:
包路径:android.os.Parcel
类名称:Parcel
方法名:createByteArray
[英]Read and return a byte[] object from the parcel.
[中]从包裹中读取并返回字节[]对象。
代码示例来源:origin: johncarl81/parceler
@Override
public byte[] nullSafeFromParcel(Parcel parcel) {
return parcel.createByteArray();
}
代码示例来源:origin: google/ExoPlayer
/* package */ SchemeData(Parcel in) {
uuid = new UUID(in.readLong(), in.readLong());
licenseServerUrl = in.readString();
mimeType = in.readString();
data = in.createByteArray();
requiresSecureDecryption = in.readByte() != 0;
}
代码示例来源:origin: google/ExoPlayer
@SuppressWarnings("ResourceType")
/* package */ ColorInfo(Parcel in) {
colorSpace = in.readInt();
colorRange = in.readInt();
colorTransfer = in.readInt();
boolean hasHdrStaticInfo = Util.readBoolean(in);
hdrStaticInfo = hasHdrStaticInfo ? in.createByteArray() : null;
}
代码示例来源:origin: square/wire
@Override public M createFromParcel(Parcel in) {
try {
return adapter.decode(in.createByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: google/ExoPlayer
/* package */ EventMessage(Parcel in) {
schemeIdUri = castNonNull(in.readString());
value = castNonNull(in.readString());
presentationTimeUs = in.readLong();
durationMs = in.readLong();
id = in.readLong();
messageData = castNonNull(in.createByteArray());
}
代码示例来源:origin: google/ExoPlayer
/* package */ PrivFrame(Parcel in) {
super(ID);
owner = castNonNull(in.readString());
privateData = castNonNull(in.createByteArray());
}
代码示例来源:origin: google/ExoPlayer
/* package */ BinaryFrame(Parcel in) {
super(castNonNull(in.readString()));
data = castNonNull(in.createByteArray());
}
代码示例来源:origin: k9mail/k-9
public OpenPgpDecryptionResult createFromParcel(final Parcel source) {
int version = source.readInt(); // parcelableVersion
int parcelableSize = source.readInt();
int startPosition = source.dataPosition();
int result = source.readInt();
byte[] sessionKey = version > 1 ? source.createByteArray() : null;
byte[] decryptedSessionKey = version > 1 ? source.createByteArray() : null;
OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult(result, sessionKey, decryptedSessionKey);
// skip over all fields added in future versions of this parcel
source.setDataPosition(startPosition + parcelableSize);
return vr;
}
代码示例来源:origin: google/ExoPlayer
/* package */ ApicFrame(Parcel in) {
super(ID);
mimeType = castNonNull(in.readString());
description = castNonNull(in.readString());
pictureType = in.readInt();
pictureData = castNonNull(in.createByteArray());
}
代码示例来源:origin: google/ExoPlayer
/* package */ GeobFrame(Parcel in) {
super(ID);
mimeType = castNonNull(in.readString());
filename = castNonNull(in.readString());
description = castNonNull(in.readString());
data = castNonNull(in.createByteArray());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndReadByteArray_empty() {
parcel.writeInt(0);
parcel.setDataPosition(0);
assertThat(parcel.createByteArray()).isEqualTo(new byte[0]);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndReadByteArray_justLengthButNoContents() {
parcel.writeInt(3);
parcel.setDataPosition(0);
try {
parcel.createByteArray();
fail("expected exception");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Byte array's length prefix is 3 but real length is 0");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testByteArrayToleratesZeroes() {
parcel.writeInt(19); // Length
parcel.writeInt(0); // These are zero
parcel.writeLong(0); // This is zero
parcel.writeFloat(0.0f); // This is zero
parcel.writeByteArray(new byte[0]); // This is also zero
assertThat(parcel.dataSize()).isEqualTo(24);
parcel.setDataPosition(0);
assertThat(parcel.createByteArray()).isEqualTo(new byte[19]);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testByteArrayOfZeroesCastedToZeroes() {
parcel.writeByteArray(new byte[17]);
assertThat(parcel.dataSize()).named("total size").isEqualTo(24);
parcel.setDataPosition(0);
assertThat(parcel.readInt()).isEqualTo(17);
assertThat(parcel.readInt()).isEqualTo(0);
assertThat(parcel.readFloat()).isEqualTo(0.0f);
assertThat(parcel.createByteArray()).isEqualTo(new byte[0]);
assertThat(parcel.readString()).isEqualTo("");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testZeroCanBeCasted_8ByteTypesCanBeReadAs4Bytes() {
parcel.writeLong(0);
parcel.writeDouble(0.0);
parcel.writeLong(0);
assertThat(parcel.dataSize()).named("total size").isEqualTo(24);
parcel.setDataPosition(0);
assertThat(parcel.readInt()).isEqualTo(0);
assertThat(parcel.readFloat()).isEqualTo(0.0f);
assertThat(parcel.createByteArray()).isEqualTo(new byte[0]);
assertThat(parcel.dataPosition()).isEqualTo(12);
assertThat(parcel.readInt()).isEqualTo(0);
assertThat(parcel.readFloat()).isEqualTo(0.0f);
assertThat(parcel.createByteArray()).isEqualTo(new byte[0]);
assertThat(parcel.dataPosition()).isEqualTo(24);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateNullByteArray() throws Exception {
parcel.writeByteArray(null);
assertThat(parcel.dataSize()).isEqualTo(4);
parcel.setDataPosition(0);
assertThat(parcel.createByteArray()).isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateByteArray_lengthZero() {
byte[] bytes = new byte[] {};
parcel.writeByteArray(bytes);
assertThat(parcel.dataSize()).isEqualTo(4);
parcel.setDataPosition(0);
byte[] actualBytes = parcel.createByteArray();
assertTrue(Arrays.equals(bytes, actualBytes));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndReadByteArray_overwrittenLength() {
byte[] bytes = new byte[] {-1, 2, 3, 127};
parcel.writeByteArray(bytes);
assertThat(parcel.dataSize()).isEqualTo(8);
parcel.setDataPosition(0);
parcel.writeInt(3);
parcel.setDataPosition(0);
try {
parcel.createByteArray();
fail("expected exception");
} catch (UnreliableBehaviorError e) {
assertThat(e).hasMessage("Byte array's length prefix is 3 but real length is 4");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateByteArray_oddLength() {
byte[] bytes = new byte[] {-1, 2, 3, 127, -128};
parcel.writeByteArray(bytes);
assertWithMessage("4B length + 5B data + 3B padding").that(parcel.dataSize()).isEqualTo(12);
parcel.setDataPosition(0);
assertThat(parcel.createByteArray()).isEqualTo(bytes);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateByteArray_multipleOf4() {
byte[] bytes = new byte[] {-1, 2, 3, 127};
parcel.writeByteArray(bytes);
// Make sure that the parcel is not storing the original array.
bytes[0] = 55;
bytes[1] = 55;
bytes[2] = 55;
bytes[3] = 55;
assertWithMessage("4B length + 4B data").that(parcel.dataSize()).isEqualTo(8);
parcel.setDataPosition(0);
byte[] actualBytes = parcel.createByteArray();
assertThat(actualBytes).isEqualTo(new byte[] {-1, 2, 3, 127});
}
内容来源于网络,如有侵权,请联系作者删除!