Java Code Examples for android.support.v4.util.AtomicFile#failWrite()

The following examples show how to use android.support.v4.util.AtomicFile#failWrite() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TabPersistentStore.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Atomically writes the given serialized data out to disk.
 * @param stateDirectory Directory to save TabModel data into.
 * @param selectorIndex  Index of the TabModelSelector to write out.
 * @param listData       TabModel data in the form of a serialized byte array.
 */
public static void saveListToFile(File stateDirectory, int selectorIndex, byte[] listData) {
    synchronized (SAVE_LIST_LOCK) {
        // Save the index file containing the list of tabs to restore.
        File metadataFile = new File(stateDirectory, getStateFileName(selectorIndex));

        AtomicFile file = new AtomicFile(metadataFile);
        FileOutputStream stream = null;
        try {
            stream = file.startWrite();
            stream.write(listData, 0, listData.length);
            file.finishWrite(stream);
        } catch (IOException e) {
            if (stream != null) file.failWrite(stream);
            Log.e(TAG, "Failed to write file: " + metadataFile.getAbsolutePath());
        }
    }
}
 
Example 2
Source File: TabPersistentStore.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Atomically writes the given serialized data out to disk.
 * @param stateDirectory Directory to save TabModel data into.
 * @param stateFileName  File name to save TabModel data into.
 * @param listData       TabModel data in the form of a serialized byte array.
 */
public static void saveListToFile(File stateDirectory, String stateFileName, byte[] listData) {
    synchronized (SAVE_LIST_LOCK) {
        // Save the index file containing the list of tabs to restore.
        File metadataFile = new File(stateDirectory, stateFileName);

        AtomicFile file = new AtomicFile(metadataFile);
        FileOutputStream stream = null;
        try {
            stream = file.startWrite();
            stream.write(listData, 0, listData.length);
            file.finishWrite(stream);
        } catch (IOException e) {
            if (stream != null) file.failWrite(stream);
            Log.e(TAG, "Failed to write file: " + metadataFile.getAbsolutePath());
        }
    }
}
 
Example 3
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Atomically writes the given serialized data out to disk.
 * @param stateDirectory Directory to save TabModel data into.
 * @param stateFileName  File name to save TabModel data into.
 * @param listData       TabModel data in the form of a serialized byte array.
 */
public static void saveListToFile(File stateDirectory, String stateFileName, byte[] listData) {
    synchronized (SAVE_LIST_LOCK) {
        // Save the index file containing the list of tabs to restore.
        File metadataFile = new File(stateDirectory, stateFileName);

        AtomicFile file = new AtomicFile(metadataFile);
        FileOutputStream stream = null;
        try {
            stream = file.startWrite();
            stream.write(listData, 0, listData.length);
            file.finishWrite(stream);
        } catch (IOException e) {
            if (stream != null) file.failWrite(stream);
            Log.e(TAG, "Failed to write file: " + metadataFile.getAbsolutePath());
        }
    }
}