1 /* 2 * Copyright (C) 2009 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.backup; 18 19 import android.util.Log; 20 21 import java.io.InputStream; 22 import java.io.IOException; 23 24 /** @hide */ 25 public class BackupDataInputStream extends InputStream { 26 27 String key; 28 int dataSize; 29 30 BackupDataInput mData; 31 byte[] mOneByte; 32 BackupDataInputStream(BackupDataInput data)33 BackupDataInputStream(BackupDataInput data) { 34 mData = data; 35 } 36 read()37 public int read() throws IOException { 38 byte[] one = mOneByte; 39 if (mOneByte == null) { 40 one = mOneByte = new byte[1]; 41 } 42 mData.readEntityData(one, 0, 1); 43 return one[0]; 44 } 45 read(byte[] b, int offset, int size)46 public int read(byte[] b, int offset, int size) throws IOException { 47 return mData.readEntityData(b, offset, size); 48 } 49 read(byte[] b)50 public int read(byte[] b) throws IOException { 51 return mData.readEntityData(b, 0, b.length); 52 } 53 getKey()54 public String getKey() { 55 return this.key; 56 } 57 size()58 public int size() { 59 return this.dataSize; 60 } 61 } 62 63 64