android.os.Parcel.setDataCapacity()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中android.os.Parcel.setDataCapacity()方法的一些代码示例,展示了Parcel.setDataCapacity()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parcel.setDataCapacity()方法的具体详情如下:
包路径:android.os.Parcel
类名称:Parcel
方法名:setDataCapacity

Parcel.setDataCapacity介绍

[英]Change the capacity (current available space) of the parcel.
[中]更改地块的容量(当前可用空间)。

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
public void testSetDataCapacity() {
 parcel.writeInt(-1);
 assertWithMessage("size is 1 int").that(parcel.dataSize()).isEqualTo(4);
 assertInvariants();
 parcel.setDataPosition(parcel.dataPosition());
 parcel.readInt();
 assertWithMessage("reading within capacity but over size does not increase size")
   .that(parcel.dataSize())
   .isEqualTo(4);
 parcel.setDataCapacity(100);
 assertInvariants();
 assertWithMessage("capacity equals requested").that(parcel.dataCapacity()).isEqualTo(100);
 assertWithMessage("size does not increase with capacity").that(parcel.dataSize()).isEqualTo(4);
 parcel.setDataCapacity(404);
 for (int i = 0; i < 100; i++) {
  parcel.writeInt(i);
 }
 assertInvariants();
 assertWithMessage("capacity exactly holds 404 ints").that(parcel.dataCapacity()).isEqualTo(404);
 assertWithMessage("101 ints in size").that(parcel.dataSize()).isEqualTo(404);
 assertWithMessage("advanced 101 ints").that(parcel.dataPosition()).isEqualTo(404);
 parcel.setDataCapacity(12);
 assertWithMessage("capacity never shrinks").that(parcel.dataCapacity()).isEqualTo(404);
 parcel.setDataSize(12);
 assertWithMessage("size does shrink").that(parcel.dataSize()).isEqualTo(12);
 parcel.setDataCapacity(12);
 assertWithMessage("capacity never shrinks").that(parcel.dataCapacity()).isEqualTo(404);
}

代码示例来源:origin: robolectric/robolectric

parcel.setDataCapacity(500); // Make sure it doesn't affect size.
assertInvariants();
assertWithMessage("truncated size").that(parcel.dataSize()).isEqualTo(8);

代码示例来源:origin: stackoverflow.com

auth.writeString("middle"); // middle
auth.writeString("lastname"); // lastname
auth.setDataCapacity(3);
auth.setDataPosition(0);
Author a = Author.CREATOR.createFromParcel(auth);

相关文章

Parcel类方法