| 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.base; |
| 6 | |
| 7 | /** |
| 8 | * This class provides an interface to the native class for writing |
| 9 | * important data files without risking data loss. |
| 10 | */ |
| 11 | @JNINamespace("base::android") |
| 12 | public class ImportantFileWriterAndroid { |
| 13 | |
| 14 | /** |
| 15 | * Write a binary file atomically. |
| 16 | * |
| 17 | * This either writes all the data or leaves the file unchanged. |
| 18 | * |
| 19 | * @param fileName The complete path of the file to be written |
| 20 | * @param data The data to be written to the file |
| 21 | * @return true if the data was written to the file, false if not. |
| 22 | */ |
| 23 | public static boolean writeFileAtomically(String fileName, byte[] data) { |
| 24 | return nativeWriteFileAtomically(fileName, data); |
| 25 | } |
| 26 | |
| 27 | private static native boolean nativeWriteFileAtomically( |
| 28 | String fileName, byte[] data); |
| 29 | } |