blob: 474cedaa05528d4f3c7fa74b93a397f030054b55 [file] [log] [blame]
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001/*
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
17package android.util;
18
19import java.io.DataInputStream;
20import java.io.DataOutputStream;
21import java.io.IOException;
22
23/**
24 * Utility methods for Backup/Restore
25 * @hide
26 */
27public 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
42 public static String readString(DataInputStream in) throws IOException {
43 return (in.readByte() == NOT_NULL) ? in.readUTF() : null;
44 }
45
46 public static void writeString(DataOutputStream out, String val) throws IOException {
47 if (val != null) {
48 out.writeByte(NOT_NULL);
49 out.writeUTF(val);
50 } else {
51 out.writeByte(NULL);
52 }
53 }
54}