Debian Codegraph @

core/java/android/util/BackupUtils.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package android.util;
18
19 import java.io.DataInputStream;
20 import java.io.DataOutputStream;
21 import java.io.IOException;
22
23 /**
24 * Utility methods for Backup/Restore
25 * @hide
26 */
27 public class BackupUtils {
28
29 public static final int NULL = 0;
30 public static final int NOT_NULL = 1;
31
32 /**
33 * Thrown when there is a backup version mismatch
34 * between the data received and what the system can handle
35 */
36 public static class BadVersionException extends Exception {
37 public BadVersionException(String message) {
38 super(message);
39 }
40
41 public BadVersionException(String message, Throwable throwable) {
42 super(message, throwable);
43 }
44 }
45
46 public static String readString(DataInputStream in) throws IOException {
47 return (in.readByte() == NOT_NULL) ? in.readUTF() : null;
48 }
49
50 public static void writeString(DataOutputStream out, String val) throws IOException {
51 if (val != null) {
52 out.writeByte(NOT_NULL);
53 out.writeUTF(val);
54 } else {
55 out.writeByte(NULL);
56 }
57 }
58 }