本文整理了Java中android.os.Parcel.setDataPosition()
方法的一些代码示例,展示了Parcel.setDataPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parcel.setDataPosition()
方法的具体详情如下:
包路径:android.os.Parcel
类名称:Parcel
方法名:setDataPosition
[英]Move the current read/write position in the parcel.
[中]移动地块中的当前读/写位置。
代码示例来源:origin: robolectric/robolectric
private static PackageInfo newPackageInfo(PackageInfo orig) {
Parcel parcel = Parcel.obtain();
orig.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return PackageInfo.CREATOR.createFromParcel(parcel);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testReadWriteSingleInt() {
int val = 5;
parcel.writeInt(val);
parcel.setDataPosition(0);
assertThat(parcel.readInt()).isEqualTo(val);
}
代码示例来源:origin: robolectric/robolectric
/** Returns a copy of {@code automaticZenRule}. */
private AutomaticZenRule copyAutomaticZenRule(AutomaticZenRule automaticZenRule) {
Parcel parcel = Parcel.obtain();
try {
automaticZenRule.writeToParcel(parcel, /* flags= */ 0);
parcel.setDataPosition(0);
return new AutomaticZenRule(parcel);
} finally {
parcel.recycle();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testReadWriteMultipleInts() {
for (int i = 0; i < 10; ++i) {
parcel.writeInt(i);
}
parcel.setDataPosition(0);
for (int i = 0; i < 10; ++i) {
assertThat(parcel.readInt()).isEqualTo(i);
}
// now try to read past the number of items written and see what happens
assertThat(parcel.readInt()).isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
private static UserHandle newUserHandle(int uid) {
Parcel userParcel = Parcel.obtain();
userParcel.writeInt(uid);
userParcel.setDataPosition(0);
return new UserHandle(userParcel);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testParcelableWithBase() throws Exception {
TestParcelableImpl normal = new TestParcelableImpl(23);
parcel.writeParcelable(normal, 0);
parcel.setDataPosition(0);
TestParcelableImpl rehydrated = parcel.readParcelable(TestParcelableImpl.class.getClassLoader());
assertEquals(normal.contents, rehydrated.contents);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testParcelableWithPublicClass() throws Exception {
TestParcelable normal = new TestParcelable(23);
parcel.writeParcelable(normal, 0);
parcel.setDataPosition(0);
TestParcelable rehydrated = parcel.readParcelable(TestParcelable.class.getClassLoader());
assertEquals(normal.contents, rehydrated.contents);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testReadWriteMap() throws Exception {
HashMap<String, String> original = new HashMap<>();
original.put("key", "value");
parcel.writeMap(original);
parcel.setDataPosition(0);
HashMap<String, String> rehydrated = parcel.readHashMap(null);
assertEquals("value", rehydrated.get("key"));
}
代码示例来源: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 testReadWriteSingleStringEvenLength() {
String val = "test";
parcel.writeString(val);
parcel.setDataPosition(0);
assertThat(parcel.readString()).isEqualTo(val);
assertWithMessage("4B length + 4*2B data + 2B null char + 2B padding")
.that(parcel.dataSize())
.isEqualTo(16);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateNullIntArray() throws Exception {
parcel.writeIntArray(null);
parcel.setDataPosition(0);
assertThat(parcel.createIntArray()).isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testWriteAndCreateNullStringArray() throws Exception {
parcel.writeStringArray(null);
parcel.setDataPosition(0);
assertThat(parcel.createStringArray()).isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testCreateStringArray() {
String[] strs = { "a1", "b2" };
parcel.writeStringArray(strs);
parcel.setDataPosition(0);
String[] newStrs = parcel.createStringArray();
assertTrue(Arrays.equals(strs, newStrs));
}
代码示例来源:origin: robolectric/robolectric
@Test(expected = RuntimeException.class)
public void testWriteAndReadByteArray_nullNotAllowed() {
parcel.writeByteArray(null);
assertThat(parcel.dataSize()).isEqualTo(4);
parcel.setDataPosition(0);
byte[] actualBytes = new byte[1];
parcel.readByteArray(actualBytes);
}
代码示例来源:origin: google/ExoPlayer
@Test
public void testEventMessageParcelable() {
EventMessage eventMessage = new EventMessage("urn:test", "123", 3000, 1000403,
new byte[] {0, 1, 2, 3, 4}, 1000);
// Write to parcel.
Parcel parcel = Parcel.obtain();
eventMessage.writeToParcel(parcel, 0);
// Create from parcel.
parcel.setDataPosition(0);
EventMessage fromParcelEventMessage = EventMessage.CREATOR.createFromParcel(parcel);
// Assert equals.
assertThat(fromParcelEventMessage).isEqualTo(eventMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldHaveParcelConstructor() throws Exception {
Account expected = new Account("name", "type");
Parcel p = Parcel.obtain();
expected.writeToParcel(p, 0);
p.setDataPosition(0);
Account actual = new Account(p);
assertThat(actual).isEqualTo(expected);
}
代码示例来源:origin: google/ExoPlayer
@Test
public void testParcelable() {
DrmInitData drmInitDataToParcel = new DrmInitData(DATA_1, DATA_2);
Parcel parcel = Parcel.obtain();
drmInitDataToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
DrmInitData drmInitDataFromParcel = DrmInitData.CREATOR.createFromParcel(parcel);
assertThat(drmInitDataFromParcel).isEqualTo(drmInitDataToParcel);
parcel.recycle();
}
代码示例来源:origin: google/ExoPlayer
@Test
public void testParcelable() {
MdtaMetadataEntry mdtaMetadataEntryToParcel =
new MdtaMetadataEntry("test", new byte[] {1, 2}, 3, 4);
Parcel parcel = Parcel.obtain();
mdtaMetadataEntryToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
MdtaMetadataEntry mdtaMetadataEntryFromParcel =
MdtaMetadataEntry.CREATOR.createFromParcel(parcel);
assertThat(mdtaMetadataEntryFromParcel).isEqualTo(mdtaMetadataEntryToParcel);
parcel.recycle();
}
}
代码示例来源: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: google/ExoPlayer
@Test
public void testParcelable() {
Format format1 = Format.createSampleFormat("1", MimeTypes.VIDEO_H264, 0);
Format format2 = Format.createSampleFormat("2", MimeTypes.AUDIO_AAC, 0);
TrackGroup trackGroupToParcel = new TrackGroup(format1, format2);
Parcel parcel = Parcel.obtain();
trackGroupToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
TrackGroup trackGroupFromParcel = TrackGroup.CREATOR.createFromParcel(parcel);
assertThat(trackGroupFromParcel).isEqualTo(trackGroupToParcel);
parcel.recycle();
}
}
内容来源于网络,如有侵权,请联系作者删除!