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

The following are Jave code examples for showing how to use marshall() 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: JobSchedulerCompat   File: PersistableBundleTest.java   View Source Code Vote up 6 votes
@Test
public void testParcelling() {
    PersistableBundle bundle = new PersistableBundle();
    bundle.putString("string", "string");
    bundle.putInt("int", 0);
    bundle.putLong("long", 0);
    bundle.putBoolean("boolean", true);
    // Can't use double or any array, as the instances would be different and equals() would fail.
    Parcel parcel = Parcel.obtain();
    parcel.writeValue(bundle);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    parcel = Parcel.obtain();
    parcel.unmarshall(bytes, 0, bytes.length);
    parcel.setDataPosition(0);
    PersistableBundle parcelledBundle =
            (PersistableBundle) parcel.readValue(PersistableBundle.class.getClassLoader());

    assertEquals(bundle.toMap(1), parcelledBundle.toMap(1));
}
 
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: BadIntent   File: RestAPI.java   View Source Code Vote up 6 votes
@NonNull
private Map<String, Object> createResponseMap(Parcel reply) {
    Map<String, Object> data = new HashMap<>();
    data.put("message", "reply");
    if (reply != null) {
        try {
            byte[] marshalled = reply.marshall();
            data.put("data", marshalled);
            if (marshalled != null) {
                String base64 = BaseEncoding.base64().encode(marshalled).replace("/", "");
                data.put("data_base64", base64);
            }
        } catch (RuntimeException e) {
            data.put("info", "activeObject");
        }
    }
    return data;
}
 
Example 4
Project: nifi-android-s2s   File: DemoAppDB.java   View Source Code Vote up 6 votes
/**
 * Saves the repeatable intent (useful for later cancelling an alarm after the application has restarted)
 *
 * @param siteToSiteRepeatableIntent the repeatable intent
 */
public void save(SiteToSiteRepeatableIntent siteToSiteRepeatableIntent) {
    Parcel parcel = Parcel.obtain();
    siteToSiteRepeatableIntent.getIntent().writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    byte[] bytes = parcel.marshall();
    SQLiteDatabase writableDatabase = sqLiteOpenHelper.getWritableDatabase();
    try {
        ContentValues contentValues = new ContentValues();
        contentValues.put(PENDING_INTENT_REQUEST_CODE, siteToSiteRepeatableIntent.getRequestCode());
        contentValues.put(CONTENT_COLUMN, bytes);
        writableDatabase.insertOrThrow(PENDING_INTENT_TABLE_NAME, null, contentValues);
    } finally {
        writableDatabase.close();
    }
}
 
Example 5
Project: Cable-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 6
Project: q-mail   File: ParcelableUtil.java   View Source Code Vote up 5 votes
public static byte[] marshall(Parcelable parceable) {
    Parcel parcel = Parcel.obtain();
    parceable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
Example 7
Project: HeadlineNews   File: CacheUtils.java   View Source Code Vote up 5 votes
private static byte[] parcelable2Bytes(final Parcelable parcelable) {
    if (parcelable == null) return null;
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
Example 8
Project: Cable-Android   File: ParcelUtil.java   View Source Code Vote up 5 votes
public static byte[] serialize(Parcelable parceable) {
  Parcel parcel = Parcel.obtain();
  parceable.writeToParcel(parcel, 0);
  byte[] bytes = parcel.marshall();
  parcel.recycle();
  return bytes;
}
 
Example 9
Project: GitHub   File: ParcelFn.java   View Source Code Vote up 5 votes
static byte[] marshall(Object o) {
    Parcel parcel = Parcel.obtain();
    parcel.writeValue(o);
    byte[] result = parcel.marshall();
    parcel.recycle();
    return result;
}
 
Example 10
Project: JobSchedulerCompat   File: JobStore.java   View Source Code Vote up 5 votes
private <T extends Parcelable> byte[] parcelableToByteArray(T parcelable) {
    Parcel parcel = Parcel.obtain();
    parcel.writeParcelable(parcelable, 0);
    byte[] data = parcel.marshall();
    parcel.recycle();
    return data;
}
 
Example 11
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 12
Project: AIMSICDL   File: SamsungMulticlientRilExecutor.java   View Source Code Vote up 5 votes
private byte[] marshallRequest(int token, byte data[]) {
    Parcel p = Parcel.obtain();
    p.writeInt(RIL_REQUEST_OEM_RAW);
    p.writeInt(token);
    p.writeByteArray(data);
    byte[] res = p.marshall();
    p.recycle();
    return res;
}
 
Example 13
Project: AIMSICDL   File: SamsungMulticlientRilExecutor.java   View Source Code Vote up 5 votes
private byte[] marshallRequest(int token, String strings[]) {
    Parcel p = Parcel.obtain();
    p.writeInt(RIL_REQUEST_OEM_STRINGS);
    p.writeInt(token);
    p.writeStringArray(strings);
    byte[] res = p.marshall();
    p.recycle();
    return res;
}
 
Example 14
Project: AndroidUtilCode-master   File: CacheUtils.java   View Source Code Vote up 5 votes
private static byte[] parcelable2Bytes(Parcelable parcelable) {
    if (parcelable == null) return null;
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();
    return bytes;
}
 
Example 15
Project: nifi-android-s2s   File: SerializationUtils.java   View Source Code Vote up 5 votes
/**
 * Marshalls a parcelable into a byte array
 *
 * @param parcelable the parcelable
 * @param <T>        the type
 * @return the byte array
 */
public static <T extends Parcelable> byte[] marshallParcelable(T parcelable) {
    if (parcelable == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcelable.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    try {
        return parcel.marshall();
    } finally {
        parcel.recycle();
    }
}
 
Example 16
Project: nifi-android-s2s   File: SerializationUtils.java   View Source Code Vote up 5 votes
/**
 * Marshalls a serializable into a byte array
 *
 * @param serializable the serializable
 * @param <T>          the type
 * @return the byte array
 */
public static <T extends Serializable> byte[] marshallSerializable(T serializable) {
    if (serializable == null) {
        return null;
    }
    Parcel parcel = Parcel.obtain();
    parcel.writeSerializable(serializable);
    parcel.setDataPosition(0);
    try {
        return parcel.marshall();
    } finally {
        parcel.recycle();
    }
}
 
Example 17
Project: Udacity_Sunshine   File: ItemChoiceManager.java   View Source Code Vote up 5 votes
public void onSaveInstanceState(Bundle outState) {
    Parcel outParcel = Parcel.obtain();
    outParcel.writeSparseBooleanArray(mCheckStates);
    final int numStates = mCheckedIdStates.size();
    outParcel.writeInt(numStates);
    for (int i=0; i<numStates; i++) {
        outParcel.writeLong(mCheckedIdStates.keyAt(i));
        outParcel.writeInt(mCheckedIdStates.valueAt(i));
    }
    byte[] states = outParcel.marshall();
    outState.putByteArray(SELECTED_ITEMS_KEY, states);
    outParcel.recycle();
}
 
Example 18
Project: Brevent   File: BreventProtocol.java   View Source Code Vote up 5 votes
public static void writeTo(BreventProtocol protocol, DataOutputStream os) throws IOException {
    Parcel parcel = Parcel.obtain();
    protocol.writeToParcel(parcel, 0);
    byte[] bytes = parcel.marshall();
    parcel.recycle();

    bytes = compress(bytes);
    int size = bytes.length;
    if (size > 0xffff) {
        throw new IOTooLargeException(size);
    }
    os.writeShort(size);
    os.write(bytes);
}
 
Example 19
Project: OpenYOLO-Android   File: IntentUtilTest.java   View Source Code Vote up 5 votes
private static byte[] toBytesUnchecked(Intent intent) {
    Parcel parcel = Parcel.obtain();
    parcel.writeParcelable(intent,0);
    byte[] intentBytes = parcel.marshall();
    parcel.recycle();

    return intentBytes;
}
 
Example 20
Project: nifi-android-s2s   File: SiteToSiteDB.java   View Source Code Vote up 4 votes
/**
 * Saves the peer status for a given url set and proxy
 *
 * @param siteToSiteClientConfig the configuration to save the peer status for
 */
public void savePeerStatus(SiteToSiteClientConfig siteToSiteClientConfig) throws SQLiteIOException {
    SQLiteDatabase writableDatabase = sqLiteOpenHelper.getWritableDatabase();
    writableDatabase.beginTransaction();
    try {
        writableDatabase.execSQL("DELETE FROM " + PEER_STATUSES_TABLE_NAME + " WHERE " + EXPIRATION_MILLIS_COLUMN + " <= ?", new Object[]{new Date().getTime()});
        for (SiteToSiteRemoteCluster siteToSiteRemoteCluster : siteToSiteClientConfig.getRemoteClusters()) {
            PeerStatus peerStatus = siteToSiteRemoteCluster.getPeerStatus();
            if (peerStatus == null) {
                continue;
            }

            Parcel parcel = Parcel.obtain();
            peerStatus.writeToParcel(parcel, 0);
            parcel.setDataPosition(0);
            byte[] bytes = parcel.marshall();

            String urlsString = getPeerUrlsString(siteToSiteRemoteCluster.getUrls());
            String proxyHost = siteToSiteRemoteCluster.getProxyHost();
            int proxyPort = siteToSiteRemoteCluster.getProxyPort();

            writableDatabase.delete(PEER_STATUSES_TABLE_NAME, PEER_STATUS_WHERE_CLAUSE, new String[]{urlsString, proxyHost, Integer.toString(proxyPort)});
            ContentValues values = new ContentValues();
            values.put(PEER_STATUS_URLS_COLUMN, urlsString);
            if (proxyHost == null || proxyHost.isEmpty()) {
                values.putNull(PEER_STATUS_PROXY_HOST_COLUMN);
                values.putNull(PEER_STATUS_PROXY_PORT_COLUMN);
            } else {
                values.put(PEER_STATUS_PROXY_HOST_COLUMN, proxyHost);
                values.put(PEER_STATUS_PROXY_PORT_COLUMN, proxyPort);
            }
            values.put(CONTENT_COLUMN, bytes);
            values.put(EXPIRATION_MILLIS_COLUMN, new Date().getTime() + siteToSiteClientConfig.getPeerUpdateInterval(TimeUnit.MILLISECONDS));
            writableDatabase.insertOrThrow(PEER_STATUSES_TABLE_NAME, null, values);
        }
        writableDatabase.setTransactionSuccessful();
    } catch (SQLiteException e) {
        throw new SQLiteIOException("Unable to store peer status in database.", e);
    } finally {
        writableDatabase.endTransaction();
        writableDatabase.close();
    }
}