Java Code Examples for android.os.Parcel.unmarshall()

The following are Jave code examples for showing how to use unmarshall() of the android.os.Parcel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VirtualHook   File: PackageParserEx.java   View Source Code Vote up 6 votes
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;
}
 
Example 2
Project: PeSanKita-android   File: MasterSecret.java   View Source Code Vote up 6 votes
public MasterSecret parcelClone() {
  Parcel thisParcel = Parcel.obtain();
  Parcel thatParcel = Parcel.obtain();
  byte[] bytes      = null;

  thisParcel.writeValue(this);
  bytes = thisParcel.marshall();

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

  MasterSecret that = (MasterSecret)thatParcel.readValue(MasterSecret.class.getClassLoader());

  thisParcel.recycle();
  thatParcel.recycle();

  return that;
}
 
Example 3
Project: VirtualHook   File: PackageParserEx.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 4
Project: TPlayer   File: PackageParserEx.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 5
Project: nifi-android-s2s   File: SerializationUtils.java   View Source Code Vote up 6 votes
/**
 * Unmarshalls a parcelable's byte array into the object
 *
 * @param bytes the byte array
 * @param clazz the class
 * @param <T>   the type
 * @return the object
 */
@SuppressWarnings("unchecked")
public static <T extends Parcelable> T unmarshallParcelable(byte[] bytes, Class<T> clazz) {
    if (bytes == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);

    try {
        Parcelable.Creator<? extends Parcelable> creator = (Parcelable.Creator<? extends Parcelable>) clazz.getField("CREATOR").get(null);
        return (T) creator.createFromParcel(parcel);
    } catch (Exception e) {
        throw new BadParcelableException(e);
    } finally {
        parcel.recycle();
    }
}
 
Example 6
Project: RLibrary   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(byte[] bytes, Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 7
Project: TPlayer   File: VJobSchedulerService.java   View Source Code Vote up 5 votes
private void readJobs() {
    File jobFile = VEnvironment.getJobConfigFile();
    if (!jobFile.exists()) {
        return;
    }
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(jobFile);
        byte[] bytes = new byte[(int) jobFile.length()];
        int len = fis.read(bytes);
        fis.close();
        if (len != bytes.length) {
            throw new IOException("Unable to read job config.");
        }
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        int version = p.readInt();
        if (version != JOB_FILE_VERSION) {
            throw new IOException("Bad version of job file: " + version);
        }
        if (!mJobStore.isEmpty()) {
            mJobStore.clear();
        }
        int count = p.readInt();
        for (int i = 0; i < count; i++) {
            JobId jobId = new JobId(p);
            JobConfig config = new JobConfig(p);
            mJobStore.put(jobId, config);
            mGlobalJobId = Math.max(mGlobalJobId, config.virtualJobId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }

}
 
Example 8
Project: GitHub   File: ParcelFn.java   View Source Code Vote up 5 votes
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;
}
 
Example 9
Project: HeadlineNews   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(final byte[] bytes, final Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 10
Project: AndroidUtilCode-master   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(byte[] bytes, Parcelable.Creator<T> creator) {
    if (bytes == null) return null;
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 11
Project: nifi-android-s2s   File: DemoAppDB.java   View Source Code Vote up 5 votes
/**
 * Retreives all pending intents that have been saved
 *
 * @return the pending intents
 */
public List<PendingIntentWrapper> getPendingIntents() {
    List<PendingIntentWrapper> pendingIntents = new ArrayList<>();
    SQLiteDatabase readableDatabase = sqLiteOpenHelper.getReadableDatabase();
    try {
        Cursor cursor = readableDatabase.query(false, PENDING_INTENT_TABLE_NAME, new String[]{ID_COLUMN, PENDING_INTENT_REQUEST_CODE, CONTENT_COLUMN}, null, null, null, null, null, null);
        try {
            int idIndex = cursor.getColumnIndexOrThrow(ID_COLUMN);
            int requestCodeIndex = cursor.getColumnIndexOrThrow(PENDING_INTENT_REQUEST_CODE);
            int contentIndex = cursor.getColumnIndexOrThrow(CONTENT_COLUMN);
            while (cursor.moveToNext()) {
                Parcel parcel = Parcel.obtain();
                byte[] bytes = cursor.getBlob(contentIndex);
                parcel.unmarshall(bytes, 0, bytes.length);
                parcel.setDataPosition(0);
                int requestCode = cursor.getInt(requestCodeIndex);
                Intent intent = Intent.CREATOR.createFromParcel(parcel);
                pendingIntents.add(new PendingIntentWrapper(cursor.getLong(idIndex), PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_NO_CREATE)));
            }
        } finally {
            cursor.close();
        }
    } finally {
        readableDatabase.close();
    }
    return pendingIntents;
}
 
Example 12
Project: Brevent   File: BreventProtocol.java   View Source Code Vote up 5 votes
private static BreventProtocol unwrap(byte[] bytes) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    parcel.readInt(); // skip version
    int action = parcel.readInt();
    parcel.setDataPosition(0);

    try {
        switch (action) {
            case STATUS_REQUEST:
                return new BreventRequest(parcel);
            case STATUS_RESPONSE:
                return new BreventResponse(parcel);
            case UPDATE_BREVENT:
                return new BreventPackages(parcel);
            case CONFIGURATION:
                return new BreventConfiguration(parcel);
            case UPDATE_PRIORITY:
                return new BreventPriority(parcel);
            case STATUS_NO_EVENT:
                return new BreventNoEvent(parcel);
            case OPS_KO:
                return BreventOpsKO.INSTANCE;
            case OPS_RESET:
                return new BreventOpsReset(parcel);
            case OPS_UPDATE:
                return new BreventOpsUpdate(parcel);
            case OPS_OK:
                return BreventOpsOK.INSTANCE;
            default:
                return null;
        }
    } finally {
        parcel.recycle();
    }
}
 
Example 13
Project: boohee_v5.6   File: RecordFood.java   View Source Code Vote up 5 votes
public RecordFood clone() {
    Parcel parcel = Parcel.obtain();
    writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    Parcel parcel2 = Parcel.obtain();
    parcel2.unmarshall(bytes, 0, bytes.length);
    parcel2.setDataPosition(0);
    return (RecordFood) CREATOR.createFromParcel(parcel2);
}
 
Example 14
Project: LJFramework   File: CacheUtils.java   View Source Code Vote up 5 votes
private static <T> T bytes2Parcelable(final byte[] bytes, final Parcelable.Creator<T> creator) {
    if (bytes == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    T result = creator.createFromParcel(parcel);
    parcel.recycle();
    return result;
}
 
Example 15
Project: container   File: VJobSchedulerService.java   View Source Code Vote up 5 votes
private void readJobs() {
    File jobFile = VEnvironment.getJobConfigFile();
    if (!jobFile.exists()) {
        return;
    }
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(jobFile);
        byte[] bytes = new byte[(int) jobFile.length()];
        int len = fis.read(bytes);
        fis.close();
        if (len != bytes.length) {
            throw new IOException("Unable to read job config.");
        }
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        int version = p.readInt();
        if (version != JOB_FILE_VERSION) {
            throw new IOException("Bad version of job file: " + version);
        }
        if (!mJobStore.isEmpty()) {
            mJobStore.clear();
        }
        int count = p.readInt();
        for (int i = 0; i < count; i++) {
            JobId jobId = new JobId(p);
            JobConfig config = new JobConfig(p);
            mJobStore.put(jobId, config);
            mGlobalJobId = Math.max(mGlobalJobId, config.virtualJobId);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }

}
 
Example 16
Project: VirtualHook   File: PersistenceLayer.java   View Source Code Vote up 5 votes
public void read() {
    File file = mPersistenceFile;
    Parcel p = Parcel.obtain();
    try {
        FileInputStream fis = new FileInputStream(file);
        byte[] bytes = new byte[(int) file.length()];
        int len = fis.read(bytes);
        fis.close();
        if (len != bytes.length) {
            throw new IOException("Unable to read Persistence file.");
        }
        p.unmarshall(bytes, 0, bytes.length);
        p.setDataPosition(0);
        if (!verifyMagic(p)) {
            onPersistenceFileDamage();
            throw new IOException("Invalid persistence file.");
        }
        int fileVersion = p.readInt();
        int currentVersion = getCurrentVersion();
        if (fileVersion != getCurrentVersion()) {
            if (!onVersionConflict(fileVersion, currentVersion)) {
                throw new IOException("Unable to process the bad version persistence file.");
            }
        }
        readPersistenceData(p);
    } catch (Exception e) {
        if (!(e instanceof FileNotFoundException)) {
            e.printStackTrace();
        }
    } finally {
        p.recycle();
    }
}
 
Example 17
Project: q-mail   File: ParcelableUtil.java   View Source Code Vote up 4 votes
private static Parcel unmarshall(byte[] bytes) {
    Parcel parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    return parcel;
}
 
Example 18
Project: Cable-Android   File: ParcelUtil.java   View Source Code Vote up 4 votes
public static Parcel deserialize(byte[] bytes) {
  Parcel parcel = Parcel.obtain();
  parcel.unmarshall(bytes, 0, bytes.length);
  parcel.setDataPosition(0);
  return parcel;
}
 
Example 19
Project: PeSanKita-android   File: ParcelUtil.java   View Source Code Vote up 4 votes
public static Parcel deserialize(byte[] bytes) {
  Parcel parcel = Parcel.obtain();
  parcel.unmarshall(bytes, 0, bytes.length);
  parcel.setDataPosition(0);
  return parcel;
}
 
Example 20
Project: container   File: VAccountManagerService.java   View Source Code Vote up 4 votes
/**
 * Read all accounts from file.
 */
private void deserializeAllAccounts() {
	File accountFile = VEnvironment.getAccountConfigFile();
	refreshAuthenticatorCache(null);
	if (accountFile.exists()) {
		accountsByUserId.clear();
           Parcel dest = Parcel.obtain();
           try {
               FileInputStream is = new FileInputStream(accountFile);
               byte[] bytes = new byte[(int) accountFile.length()];
               int readLength = is.read(bytes);
               is.close();
               if (readLength != bytes.length) {
                   throw new IOException(String.format("Expect length %d, but got %d.", bytes.length, readLength));
               }
               dest.unmarshall(bytes, 0, bytes.length);
               dest.setDataPosition(0);
               dest.readInt(); // skip the magic
               int size = dest.readInt(); // the VAccount's size we need to read
               boolean invalid = false;
               while (size-- > 0) {
                   VAccount account = new VAccount(dest);
				VLog.d(TAG, "Reading account : " + account.type);
                   AuthenticatorInfo info = cache.authenticators.get(account.type);
                   if (info != null) {
                       List<VAccount> accounts = accountsByUserId.get(account.userId);
                       if (accounts == null) {
                           accounts = new ArrayList<>();
                           accountsByUserId.put(account.userId, accounts);
                       }
                       accounts.add(account);
                   } else {
                       invalid = true;
                   }
               }
               lastAccountChangeTime = dest.readLong();
               if (invalid) {
                   serializeAllAccounts();
               }
           } catch (Exception e) {
               e.printStackTrace();
           } finally {
               dest.recycle();
           }
	}
}