org.chromium.base.StreamUtil Java Examples

The following examples show how to use org.chromium.base.StreamUtil. 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: ChromeBackupAgent.java    From delion with Apache License 2.0 6 votes vote down vote up
private boolean filterChromePrefs(File prefsFile) {
    InputStream inputStream = null;
    OutputStream outputStream = null;
    try {
        inputStream = openInputStream(prefsFile);
        int fileLength = (int) getFileLength(prefsFile);
        byte[] buffer = new byte[fileLength];
        if (inputStream.read(buffer) != fileLength) return false;
        JSONObject jsonInput = new JSONObject(new String(buffer, "UTF-8"));
        JSONObject jsonOutput = new JSONObject();
        for (String[] pref : RESTORED_CHROME_PREFS) {
            Object prefValue = readChromePref(jsonInput, pref);
            if (prefValue != null) writeChromePref(jsonOutput, pref, prefValue);
        }
        byte[] outputBytes = jsonOutput.toString().getBytes("UTF-8");
        outputStream = openOutputStream(prefsFile);
        outputStream.write(outputBytes);
        return true;
    } catch (IOException | JSONException e) {
        Log.d(TAG, "Filtering preferences failed with %s", e.getMessage());
        return false;
    } finally {
        StreamUtil.closeQuietly(inputStream);
        StreamUtil.closeQuietly(outputStream);
    }
}