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

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

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

Parcel.dataAvail介绍

[英]Returns the amount of data remaining to be read from the parcel. That is, #dataSize- #dataPosition.
[中]返回要从地块读取的剩余数据量。也就是说,#数据大小-#数据位置。

代码示例

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

@Test
public void testDataAvail() {
 parcel.writeInt(1);
 parcel.writeFloat(5);
 parcel.writeDouble(6);
 parcel.setDataPosition(4);
 assertThat(parcel.dataAvail()).isEqualTo(12);
}

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

@Test
public void testAppendFrom() {
 // Write a mixture of things, and overwrite something.
 parcel.writeInt(1);
 parcel.writeInt(2);
 parcel.writeInt(3);
 parcel.writeInt(4);
 // Create a parcel2 that sandwiches parcel1 with happy birthday.
 Parcel parcel2 = Parcel.obtain();
 parcel2.writeString("happy");
 parcel2.appendFrom(parcel, 4, 8);
 assertInvariants(parcel);
 assertInvariants(parcel2);
 parcel2.writeString("birthday");
 assertInvariants(parcel);
 parcel2.setDataPosition(0);
 assertThat(parcel2.readString()).isEqualTo("happy");
 assertThat(parcel2.readInt()).isEqualTo(2);
 assertThat(parcel2.readInt()).isEqualTo(3);
 assertThat(parcel2.readString()).isEqualTo("birthday");
 assertThat(parcel2.dataAvail()).isEqualTo(0);
}

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

private void assertInvariants(Parcel p) {
  assertWithMessage("capacity >= size").that(p.dataCapacity()).isAtLeast(p.dataSize());
  assertWithMessage("position <= size").that(p.dataPosition()).isAtMost(p.dataSize());
  assertWithMessage("available = size - position")
    .that(p.dataAvail())
    .isEqualTo(p.dataSize() - p.dataPosition());
  assertWithMessage("size % 4 == 0").that(p.dataSize() % 4).isEqualTo(0);
  assertWithMessage("capacity % 4 == 0").that(p.dataSize() % 4).isEqualTo(0);
 }
}

代码示例来源:origin: codezjx/AndLinker

@Override
public short[] createFromParcel(Parcel in) {
  int N = in.readInt();
  if (N >= 0 && N <= (in.dataAvail() >> 2)) {
    short[] val = new short[N];
    for (int i = 0; i < N; i++) {
      val[i] = (short) in.readInt();
    }
    return val;
  } else {
    return null;
  }
}

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

public void readFromParcel(Parcel in){
  int count = in.dataAvail();
  for(int i = 0; i < count; i++){
    x = in.readInt();
    i++;
    y = in.readInt();
  }
}

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

MyObject(Parcel in) {

  this.contract_id = in.readInt();
  this.id = in.readString();
  this.title = in.readString();
  this.body = in.readString(); // till here both constructors have same data

  if (in.dataAvail() > 0) { // check for the extra data

    this.time = in.readString();
    this.nickName = in.readString();

  }
}

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

public Student(){}
public Student(String name, String dpt)
{ 
 this.studentName = name;
 this.studentDept = dpt;}
public Student(int id, String name, String dpt)
{ this.studentdID = id;
 this.studentName = name;
 this.studentDept = dpt; 
}
public Student(Parcel in) {
  name = in.readString();
  dpt = in.readString();
  if(in.dataAvail() > 0) // is there data left to read?
    id = in.readInt();
}

代码示例来源:origin: smartdevicelink/sdl_android

public SdlPacket(Parcel p) {
  this.version = p.readInt();
  this.encryption = (p.readInt() == 0) ? false : true;
  this.frameType = p.readInt();
  this.serviceType = p.readInt();
  this.frameInfo = p.readInt();
  this.sessionId = p.readInt();
  this.dataSize = p.readInt();
  this.messageId = p.readInt();
  if(p.readInt() == 1){ //We should have a payload attached
    payload = new byte[dataSize];
    p.readByteArray(payload);
  }
  this.priorityCoefficient = p.readInt();
  if(p.dataAvail() > EXTRA_PARCEL_DATA_LENGTH) {	//See note on constant for why not 0
    try {
      messagingVersion = p.readInt();
      if (messagingVersion >= 2) {
        if (p.readInt() == 1) { //We should have a transport type attached
          this.transportRecord = p.readParcelable(TransportRecord.class.getClassLoader());
        }
      }
    }catch (ParcelFormatException e){
    }
  }
}

相关文章

Parcel类方法