2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.calculator2;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.io.IOException;
22 import java.io.FileNotFoundException;
23 import java.io.BufferedInputStream;
24 import java.io.BufferedOutputStream;
25 import java.io.DataInputStream;
26 import java.io.DataOutputStream;
28 import android.content.Context;
31 private static final int LAST_VERSION = 1;
32 private static final String FILE_NAME = "calculator.data";
33 private Context mContext;
35 History history = new History();
37 Persist(Context context) {
38 this.mContext = context;
44 InputStream is = new BufferedInputStream(mContext.openFileInput(FILE_NAME), 8192);
45 DataInputStream in = new DataInputStream(is);
46 int version = in.readInt();
47 if (version > LAST_VERSION) {
48 throw new IOException("data version " + version + "; expected " + LAST_VERSION);
50 history = new History(version, in);
52 } catch (FileNotFoundException e) {
53 Calculator.log("" + e);
54 } catch (IOException e) {
55 Calculator.log("" + e);
61 OutputStream os = new BufferedOutputStream(mContext.openFileOutput(FILE_NAME, 0), 8192);
62 DataOutputStream out = new DataOutputStream(os);
63 out.writeInt(LAST_VERSION);
66 } catch (IOException e) {
67 Calculator.log("" + e);