Java Code Examples for java.io.RandomAccessFile.writeBoolean()

The following are Jave code examples for showing how to use writeBoolean() of the java.io.RandomAccessFile class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: buildAPKsSamples   File: BackupRestoreActivity.java   Source Code and License Vote up 5 votes
/**
 * Handy helper routine to write the UI data to a file.
 */
void writeDataToFileLocked(RandomAccessFile file,
        boolean addMayo, boolean addTomato, int whichFilling)
    throws IOException {
        file.setLength(0L);
        file.writeInt(whichFilling);
        file.writeBoolean(addMayo);
        file.writeBoolean(addTomato);
        Log.v(TAG, "NEW STATE: mayo=" + addMayo
                + " tomato=" + addTomato
                + " filling=" + whichFilling);
}
 
Example 2
Project: buildAPKsSamples   File: MultiRecordExampleAgent.java   Source Code and License Vote up 4 votes
/**
 * On restore, we pull the various bits of data out of the restore stream,
 * then reconstruct the application's data file inside the shared lock.  A
 * restore data set will always be the full set of records supplied by the
 * application's backup operations.
 */
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {

    // Consume the restore data set, remembering each bit of application state
    // that we see along the way
    while (data.readNextHeader()) {
        String key = data.getKey();
        int dataSize = data.getDataSize();

        // In this implementation, we trust that we won't see any record keys
        // that we don't understand.  Since we expect to handle them all, we
        // go ahead and extract the data for each record before deciding how
        // it will be handled.
        byte[] dataBuf = new byte[dataSize];
        data.readEntityData(dataBuf, 0, dataSize);
        ByteArrayInputStream instream = new ByteArrayInputStream(dataBuf);
        DataInputStream in = new DataInputStream(instream);

        if (FILLING_KEY.equals(key)) {
            mFilling = in.readInt();
        } else if (MAYO_KEY.equals(key)) {
            mAddMayo = in.readBoolean();
        } else if (TOMATO_KEY.equals(key)) {
            mAddTomato = in.readBoolean();
        }
    }

    // Now we're ready to write out a full new dataset for the application.  Note that
    // the restore process is intended to *replace* any existing or default data, so
    // we can just go ahead and overwrite it all.
    synchronized (BackupRestoreActivity.sDataLock) {
        RandomAccessFile file = new RandomAccessFile(mDataFile, "rw");
        file.setLength(0L);
        file.writeInt(mFilling);
        file.writeBoolean(mAddMayo);
        file.writeBoolean(mAddTomato);
    }

    // Finally, write the state file that describes our data as of this restore pass.
    writeStateFile(newState);
}
 
Example 3
Project: buildAPKsSamples   File: ExampleAgent.java   Source Code and License Vote up 4 votes
/**
 * This application does not do any "live" restores of its own data,
 * so the only time a restore will happen is when the application is
 * installed.  This means that the activity itself is not going to
 * be running while we change its data out from under it.  That, in
 * turn, means that there is no need to send out any sort of notification
 * of the new data:  we only need to read the data from the stream
 * provided here, build the application's new data file, and then
 * write our new backup state blob that will be consulted at the next
 * backup operation.
 * 
 * <p>We don't bother checking the versionCode of the app who originated
 * the data because we have never revised the backup data format.  If
 * we had, the 'appVersionCode' parameter would tell us how we should
 * interpret the data we're about to read.
 */
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {
    // We should only see one entity in the data stream, but the safest
    // way to consume it is using a while() loop
    while (data.readNextHeader()) {
        String key = data.getKey();
        int dataSize = data.getDataSize();

        if (APP_DATA_KEY.equals(key)) {
            // It's our saved data, a flattened chunk of data all in
            // one buffer.  Use some handy structured I/O classes to
            // extract it.
            byte[] dataBuf = new byte[dataSize];
            data.readEntityData(dataBuf, 0, dataSize);
            ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
            DataInputStream in = new DataInputStream(baStream);

            mFilling = in.readInt();
            mAddMayo = in.readBoolean();
            mAddTomato = in.readBoolean();

            // Now we are ready to construct the app's data file based
            // on the data we are restoring from.
            synchronized (BackupRestoreActivity.sDataLock) {
                RandomAccessFile file = new RandomAccessFile(mDataFile, "rw");
                file.setLength(0L);
                file.writeInt(mFilling);
                file.writeBoolean(mAddMayo);
                file.writeBoolean(mAddTomato);
            }
        } else {
            // Curious!  This entity is data under a key we do not
            // understand how to process.  Just skip it.
            data.skipEntityData();
        }
    }

    // The last thing to do is write the state blob that describes the
    // app's data as restored from backup.
    writeStateFile(newState);
}