当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.writeBoolean方法代码示例

本文整理汇总了Java中java.io.RandomAccessFile.writeBoolean方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.writeBoolean方法的具体用法?Java RandomAccessFile.writeBoolean怎么用?Java RandomAccessFile.writeBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.writeBoolean方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeDataToFileLocked

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:15,代码来源:BackupRestoreActivity.java

示例2: onRestore

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:49,代码来源:MultiRecordExampleAgent.java

示例3: onRestore

import java.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:59,代码来源:ExampleAgent.java


注:本文中的java.io.RandomAccessFile.writeBoolean方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。