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

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

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

Parcel.unmarshall介绍

[英]Set the bytes in data to be the raw bytes of this Parcel.
[中]将数据中的字节设置为此包裹的原始字节。

代码示例

代码示例来源:origin: k9mail/k-9

private static Parcel unmarshall(byte[] bytes) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    return parcel;
  }
}

代码示例来源:origin: mttkay/ignition

/**
 * @see com.github.droidfu.cachefu.AbstractCache#readValueFromDisk(java.io.File)
 */
@Override
protected CachedModel readValueFromDisk(File file) throws IOException {
  FileInputStream istream = new FileInputStream(file);
  // Read file into byte array
  byte[] dataWritten = new byte[(int) file.length()];
  BufferedInputStream bistream = new BufferedInputStream(istream);
  bistream.read(dataWritten);
  bistream.close();
  // Create parcel with cached data
  Parcel parcelIn = Parcel.obtain();
  parcelIn.unmarshall(dataWritten, 0, dataWritten.length);
  parcelIn.setDataPosition(0);
  // Read class name from parcel and use the class loader to read parcel
  String className = parcelIn.readString();
  // In case this sometimes hits a null value
  if (className == null) {
    return null;
  }
  Class<?> clazz;
  try {
    clazz = Class.forName(className);
    return parcelIn.readParcelable(clazz.getClassLoader());
  } catch (ClassNotFoundException e) {
    throw new IOException(e.getMessage());
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

private static UserInfo decodeUserInfo(String base64EncodedToken) {
  byte[] data = Base64.decode(base64EncodedToken, Base64.DEFAULT);
  Parcel parcel = Parcel.obtain();
  parcel.unmarshall(data, 0, data.length);
  parcel.setDataPosition(0);
  UserInfo userInfo = (UserInfo) parcel.readValue(UserInfo.class.getClassLoader());
  parcel.recycle();
  return userInfo;
}

代码示例来源:origin: android-hacker/VirtualXposed

throw new IOException("Unable to read job config.");
p.unmarshall(bytes, 0, bytes.length);
p.setDataPosition(0);
int version = p.readInt();

代码示例来源:origin: android-hacker/VirtualXposed

throw new IOException(String.format(Locale.ENGLISH, "Expect length %d, but got %d.", bytes.length, readLength));
dest.unmarshall(bytes, 0, bytes.length);
dest.setDataPosition(0);

代码示例来源:origin: android-hacker/VirtualXposed

public static void readSignature(VPackage pkg) {
  File signatureFile = VEnvironment.getSignatureFile(pkg.packageName);
  if (!signatureFile.exists()) {
    return;
  }
  Parcel p = Parcel.obtain();
  try {
    FileInputStream fis = new FileInputStream(signatureFile);
    byte[] bytes = FileUtils.toByteArray(fis);
    fis.close();
    p.unmarshall(bytes, 0, bytes.length);
    p.setDataPosition(0);
    pkg.mSignatures = p.createTypedArray(Signature.CREATOR);
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    p.recycle();
  }
}

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

/**
 * Sets active playback configurations that will be served by {@link
 * AudioManager#getActivePlaybackConfigurations}.
 *
 * <p>Note that there is no public {@link AudioPlaybackConfiguration} constructor, so the
 * configurations returned are specified by their audio attributes only.
 */
@TargetApi(VERSION_CODES.O)
public void setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes) {
 activePlaybackConfigurations = new ArrayList<>(audioAttributes.size());
 for (AudioAttributes audioAttribute : audioAttributes) {
  Parcel p = Parcel.obtain();
  p.writeInt(0); // mPlayerIId
  p.writeInt(0); // mPlayerType
  p.writeInt(0); // mClientUid
  p.writeInt(0); // mClientPid
  p.writeInt(AudioPlaybackConfiguration.PLAYER_STATE_STARTED); // mPlayerState
  audioAttribute.writeToParcel(p, 0);
  p.writeStrongInterface(null);
  byte[] bytes = p.marshall();
  p.recycle();
  p = Parcel.obtain();
  p.unmarshall(bytes, 0, bytes.length);
  p.setDataPosition(0);
  AudioPlaybackConfiguration configuration =
    AudioPlaybackConfiguration.CREATOR.createFromParcel(p);
  p.recycle();
  activePlaybackConfigurations.add(configuration);
 }
}

代码示例来源:origin: android-hacker/VirtualXposed

public static VPackage readPackageCache(String packageName) {
  Parcel p = Parcel.obtain();
  try {
    File cacheFile = VEnvironment.getPackageCacheFile(packageName);
    FileInputStream is = new FileInputStream(cacheFile);
    byte[] bytes = FileUtils.toByteArray(is);
    is.close();
    p.unmarshall(bytes, 0, bytes.length);
    p.setDataPosition(0);
    if (p.readInt() != 4) {
      throw new IllegalStateException("Invalid version.");
    }
    VPackage pkg = new VPackage(p);
    addOwner(pkg);
    return pkg;
  } catch (Exception e) {
    e.printStackTrace();
  } finally {
    p.recycle();
  }
  return null;
}

代码示例来源:origin: commonsguy/cw-omnibus

public static <T> T toParcelable(byte[] bytes,
                  Parcelable.Creator<T> creator) {
  Parcel parcel=Parcel.obtain();

  parcel.unmarshall(bytes, 0, bytes.length);
  parcel.setDataPosition(0);

  T result=creator.createFromParcel(parcel);

  parcel.recycle();

  return(result);
 }
}

代码示例来源:origin: android-hacker/VirtualXposed

throw new IOException("Unable to read Persistence file.");
p.unmarshall(bytes, 0, bytes.length);
p.setDataPosition(0);
if (!verifyMagic(p)) {

代码示例来源:origin: konmik/nucleus

static <T> T unmarshall(byte[] array) {
  Parcel parcel = Parcel.obtain();
  parcel.unmarshall(array, 0, array.length);
  parcel.setDataPosition(0);
  Object value = parcel.readValue(CLASS_LOADER);
  parcel.recycle();
  return (T)value;
}

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

@Test
public void testUnmarshallEmpty() throws IOException {
 // Unmarshall an zero-length byte string, although, pass a non-empty array to make sure the
 // length/offset are respected.
 parcel.unmarshall(new byte[] {1, 2, 3}, 1, 0);
 assertThat(parcel.dataSize()).isEqualTo(0);
 assertThat(parcel.dataPosition()).isEqualTo(0);
 // Should not throw "Did you forget to setDataPosition(0)?" because it's still empty.
 assertThat(parcel.readInt()).isEqualTo(0);
}

代码示例来源:origin: facebook/facebook-android-sdk

public static <E extends Parcelable> E parcelAndUnparcel(final E object) {
  final Parcel writeParcel = Parcel.obtain();
  final Parcel readParcel = Parcel.obtain();
  try {
    writeParcel.writeParcelable(object, 0);
    final byte[] bytes = writeParcel.marshall();
    readParcel.unmarshall(bytes, 0, bytes.length);
    readParcel.setDataPosition(0);
    return readParcel.readParcelable(object.getClass().getClassLoader());
  } finally {
    writeParcel.recycle();
    readParcel.recycle();
  }
}

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

parcel2.unmarshall(data, 0, data.length);
assertThat(parcel2.dataPosition()).isEqualTo(parcel2.dataSize());
parcel2.setDataPosition(0);

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

parcel.unmarshall(data, 0, data.length);
assertThat(parcel.dataPosition()).isEqualTo(parcel.dataSize());
parcel.setDataPosition(0);

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

@Test
public void testMarshallAndUnmarshall() {
 parcel.writeInt(1);
 parcel.writeString("hello");
 parcel.writeDouble(25.0);
 parcel.writeFloat(1.25f);
 parcel.writeByte((byte) 0xAF);
 int oldSize = parcel.dataSize();
 parcel.setDataPosition(7);
 byte[] rawBytes = parcel.marshall();
 assertWithMessage("data position preserved").that(parcel.dataPosition()).isEqualTo(7);
 Parcel parcel2 = Parcel.obtain();
 assertInvariants(parcel2);
 parcel2.unmarshall(rawBytes, 0, rawBytes.length);
 assertThat(parcel2.dataPosition()).isEqualTo(parcel2.dataSize());
 parcel2.setDataPosition(0);
 assertThat(parcel2.dataSize()).isEqualTo(oldSize);
 assertThat(parcel2.readInt()).isEqualTo(1);
 assertThat(parcel2.readString()).isEqualTo("hello");
 assertThat(parcel2.readDouble()).isEqualTo(25.0);
 assertThat(parcel2.readFloat()).isEqualTo(1.25f);
 assertThat(parcel2.readByte()).isEqualTo((byte) 0xAF);
}

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

mostlyZeroes[302] = (byte) -32;
parcel.unmarshall(new byte[300], 2, 300);
assertThat(parcel.dataSize()).isEqualTo(300);
assertThat(parcel.dataPosition()).isEqualTo(300);

代码示例来源:origin: braintree/braintree_android

public static Parcel getParcelable(Context context, String key) {
  try {
    byte[] requestBytes = Base64.decode(getSharedPreferences(context).getString(key, ""), 0);
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(requestBytes, 0, requestBytes.length);
    parcel.setDataPosition(0);
    return parcel;
  } catch (Exception ignored) {}
  return null;
}

代码示例来源:origin: 8enet/AppOpsX

public static Parcel unmarshall(byte[] bytes) {
 if(bytes == null){
  return null;
 }
 Parcel parcel = Parcel.obtain();
 parcel.unmarshall(bytes, 0, bytes.length);
 parcel.setDataPosition(0);
 return parcel;
}

代码示例来源:origin: cn.leancloud.android/avoscloud-statistics

private static Parcel unMarshall(byte[] data) {
 Parcel parcel = Parcel.obtain();
 parcel.unmarshall(data, 0, data.length);
 parcel.setDataPosition(0); // this is extremely important!
 return parcel;
}

相关文章

Parcel类方法