Example usage for android.os Parcel marshall

List of usage examples for android.os Parcel marshall

Introduction

In this page you can find the example usage for android.os Parcel marshall.

Prototype

public final byte[] marshall() 

Source Link

Document

Returns the raw bytes of the parcel.

Usage

From source file:org.sufficientlysecure.keychain.ui.MultiUserIdsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

    MatrixCursor matrix = new MatrixCursor(new String[] { "_id", "user_data", "grouped" }) {
        @Override/*www . ja  va 2  s .  c o m*/
        public byte[] getBlob(int column) {
            return super.getBlob(column);
        }
    };
    data.moveToFirst();

    long lastMasterKeyId = 0;
    String lastName = "";
    ArrayList<String> uids = new ArrayList<>();

    boolean header = true;

    // Iterate over all rows
    while (!data.isAfterLast()) {
        long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
        String userId = data.getString(INDEX_USER_ID);
        OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId);

        // Two cases:

        boolean grouped = masterKeyId == lastMasterKeyId;
        boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name);
        // Remember for next loop
        lastName = pieces.name;

        Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));

        if (!subGrouped) {
            // 1. This name should NOT be grouped with the previous, so we flush the buffer

            Parcel p = Parcel.obtain();
            p.writeStringList(uids);
            byte[] d = p.marshall();
            p.recycle();

            matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 });
            // indicate that we have a header for this masterKeyId
            header = false;

            // Now clear the buffer, and add the new user id, for the next round
            uids.clear();

        }

        // 2. This name should be grouped with the previous, just add to buffer
        uids.add(userId);
        lastMasterKeyId = masterKeyId;

        // If this one wasn't grouped, the next one's gotta be a header
        if (!grouped) {
            header = true;
        }

        // Regardless of the outcome, move to next entry
        data.moveToNext();

    }

    // If there is anything left in the buffer, flush it one last time
    if (!uids.isEmpty()) {

        Parcel p = Parcel.obtain();
        p.writeStringList(uids);
        byte[] d = p.marshall();
        p.recycle();

        matrix.addRow(new Object[] { lastMasterKeyId, d, header ? 1 : 0 });

    }

    mUserIdsAdapter.swapCursor(matrix);
}

From source file:ca.farrelltonsolar.classic.PVOutputService.java

private byte[] serializeBundle(final Bundle bundle) {
    byte[] rval = null;
    final Parcel parcel = Parcel.obtain();
    try {/* w w  w.  j a  v a 2  s. c  o  m*/
        parcel.writeBundle(bundle);
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(bos));
        zos.write(parcel.marshall());
        zos.close();
        rval = bos.toByteArray();
    } catch (IOException ex) {
        Log.w(getClass().getName(), String.format("serializeBundle failed ex: %s", ex));

    } finally {
        parcel.recycle();
    }
    return rval;
}

From source file:app.com.example.android.sunshine.ItemChoiceManager.java

public void onSaveInstanceState(Bundle outState) {
    Parcel outParcel = Parcel.obtain();
    outParcel.writeSparseBooleanArray(mCheckStates);
    final int numStates = mCheckedIdStates.size();
    outParcel.writeInt(numStates);//from w ww.  ja  v a2 s. c  o  m
    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();
}

From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java

protected final void updateData(Parcel data) // TODO: a placer plutot cot serveur
{
    if (UPDATE_PARCEL) {
        int v = VERSION.SDK_INT;
        data.setDataPosition(0);/*from w w  w .  j av  a  2  s .  c o  m*/
        if (v >= 10) // Gingerbread_MR1+
        {
            data.readInt();
        }
        String enforceInterfaceName = data.readString(); // Read the interface name (see Parcel.cpp)
        assert (enforceInterfaceName != null);
        byte[] bufDatas = data.marshall(); // Return all the buffer (with the specific enforceInterface
        int startDatas = data.dataPosition(); // Position after the first string

        // Create a new one with interface name + buffers
        Parcel p = Parcel.obtain();
        p.setDataPosition(0);
        p.writeString(enforceInterfaceName);
        int sizeInterface = p.dataPosition();
        byte[] bufInterface = p.marshall(); // Part of buffer only for the string
        p.recycle();

        // Extract the rest of the buffer
        byte[] result = new byte[sizeInterface + bufDatas.length - startDatas];
        System.arraycopy(bufInterface, 0, result, 0, sizeInterface);
        System.arraycopy(bufDatas, startDatas, result, sizeInterface, bufDatas.length - startDatas);
        data.unmarshall(result, 0, result.length);
    }
}