FileDocCategorySizeDatePackage
BackupDataInputStream.javaAPI DocAndroid 5.1 API4264Thu Mar 12 22:22:10 GMT 2015android.app.backup

BackupDataInputStream

public class BackupDataInputStream extends InputStream
Provides an {@link java.io.InputStream}-like interface for accessing an entity's data during a restore operation. Used by {@link BackupHelper} classes within the {@link BackupAgentHelper} mechanism.

When {@link BackupHelper#restoreEntity(BackupDataInputStream) BackupHelper.restoreEntity()} is called, the current entity's header has already been read from the underlying {@link BackupDataInput}. The entity's key string and total data size are available through this class's {@link #getKey()} and {@link #size()} methods, respectively.

Note: The caller should take care not to seek or close the underlying data source, nor read more than {@link #size()} bytes from the stream.

see
BackupAgentHelper
see
BackupHelper

Fields Summary
String
key
int
dataSize
BackupDataInput
mData
byte[]
mOneByte
Constructors Summary
BackupDataInputStream(BackupDataInput data)

hide

        mData = data;
    
Methods Summary
public java.lang.StringgetKey()
Report the key string associated with this entity within the backup data set.

return
The key string for this entity, equivalent to calling {@link BackupDataInput#getKey()} on the underlying {@link BackupDataInput}.

        return this.key;
    
public intread()
Read one byte of entity data from the stream, returning it as an integer value. If more than {@link #size()} bytes of data are read from the stream, the output of this method is undefined.

return
The byte read, or undefined if the end of the stream has been reached.

        byte[] one = mOneByte;
        if (mOneByte == null) {
            one = mOneByte = new byte[1];
        }
        mData.readEntityData(one, 0, 1);
        return one[0];
    
public intread(byte[] b, int offset, int size)
Read up to {@code size} bytes of data into a byte array, beginning at position {@code offset} within the array.

param
b Byte array into which the data will be read
param
offset The data will be stored in {@code b} beginning at this index within the array.
param
size The number of bytes to read in this operation. If insufficient data exists within the entity to fulfill this request, only as much data will be read as is available.
return
The number of bytes of data read, or zero if all of the entity's data has already been read.

        return mData.readEntityData(b, offset, size);
    
public intread(byte[] b)
Read enough entity data into a byte array to fill the array.

param
b Byte array to fill with data from the stream. If the stream does not have sufficient data to fill the array, then the contents of the remainder of the array will be undefined.
return
The number of bytes of data read, or zero if all of the entity's data has already been read.

        return mData.readEntityData(b, 0, b.length);
    
public intsize()
Report the total number of bytes of data available for the current entity.

return
The number of data bytes available, equivalent to calling {@link BackupDataInput#getDataSize()} on the underlying {@link BackupDataInput}.

        return this.dataSize;