# BackupDataInputStream

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Methods](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#inhmethods)  

# BackupDataInputStream

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/backup/BackupDataInputStream "View this page in Kotlin")\|Java

`
public


class
BackupDataInputStream
`  
`


``

extends `[InputStream](https://developer.android.com/reference/java/io/InputStream)`


``


`

|---|---|------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [java.io.InputStream](https://developer.android.com/reference/java/io/InputStream) ||
|   | ↳ | android.app.backup.BackupDataInputStream |

<br />

*** ** * ** ***

Provides an[InputStream](https://developer.android.com/reference/java/io/InputStream)-like interface for accessing an entity's data during a restore operation. Used by[BackupHelper](https://developer.android.com/reference/android/app/backup/BackupHelper)classes within the[BackupAgentHelper](https://developer.android.com/reference/android/app/backup/BackupAgentHelper)mechanism.

When[BackupHelper.restoreEntity()](https://developer.android.com/reference/android/app/backup/BackupHelper#restoreEntity(android.app.backup.BackupDataInputStream))is called, the current entity's header has already been read from the underlying[BackupDataInput](https://developer.android.com/reference/android/app/backup/BackupDataInput). The entity's key string and total data size are available through this class's[getKey()](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#getKey())and[size()](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#size())methods, respectively.

**Note:** The caller should take care not to seek or close the underlying data source, nor read more than[size()](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#size())bytes from the stream.

<br />

**See also:**

- [BackupAgentHelper](https://developer.android.com/reference/android/app/backup/BackupAgentHelper)
- [BackupHelper](https://developer.android.com/reference/android/app/backup/BackupHelper)

## Summary

|                                                                                                                                                        ### Public methods                                                                                                                                                        ||
|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[String](https://developer.android.com/reference/java/lang/String) | ` `[getKey](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#getKey())`() ` Report the key string associated with this entity within the backup data set.                                                                 |
| ` int`                                                                | ` `[read](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#read())`() ` Read one byte of entity data from the stream, returning it as an integer value.                                                                   |
| ` int`                                                                | ` `[read](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#read(byte[],%20int,%20int))`(byte[] b, int offset, int size) ` Read up to`size`bytes of data into a byte array, beginning at position`offset`within the array. |
| ` int`                                                                | ` `[read](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#read(byte[]))`(byte[] b) ` Read enough entity data into a byte array to fill the array.                                                                        |
| ` int`                                                                | ` `[size](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#size())`() ` Report the total number of bytes of data available for the current entity.                                                                        |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.io.InputStream](https://developer.android.com/reference/java/io/InputStream)` ` |--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` int`                                                                               | ` `[available](https://developer.android.com/reference/java/io/InputStream#available())`() ` Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.                                                     | | ` void`                                                                              | ` `[close](https://developer.android.com/reference/java/io/InputStream#close())`() ` Closes this input stream and releases any system resources associated with the stream.                                                                                                                                                  | | ` void`                                                                              | ` `[mark](https://developer.android.com/reference/java/io/InputStream#mark(int))`(int readlimit) ` Marks the current position in this input stream.                                                                                                                                                                          | | ` boolean`                                                                           | ` `[markSupported](https://developer.android.com/reference/java/io/InputStream#markSupported())`() ` Tests if this input stream supports the`mark`and`reset`methods.                                                                                                                                                         | | ` static `[InputStream](https://developer.android.com/reference/java/io/InputStream) | ` `[nullInputStream](https://developer.android.com/reference/java/io/InputStream#nullInputStream())`() ` Returns a new`InputStream`that reads no bytes.                                                                                                                                                                      | | ` int`                                                                               | ` `[read](https://developer.android.com/reference/java/io/InputStream#read(byte[]))`(byte[] b) ` Reads some number of bytes from the input stream and stores them into the buffer array`b`.                                                                                                                                  | | ` abstract int`                                                                      | ` `[read](https://developer.android.com/reference/java/io/InputStream#read())`() ` Reads the next byte of data from the input stream.                                                                                                                                                                                        | | ` int`                                                                               | ` `[read](https://developer.android.com/reference/java/io/InputStream#read(byte[],%20int,%20int))`(byte[] b, int off, int len) ` Reads up to`len`bytes of data from the input stream into an array of bytes.                                                                                                                 | | ` byte[]`                                                                            | ` `[readAllBytes](https://developer.android.com/reference/java/io/InputStream#readAllBytes())`() ` Reads all remaining bytes from the input stream.                                                                                                                                                                          | | ` int`                                                                               | ` `[readNBytes](https://developer.android.com/reference/java/io/InputStream#readNBytes(byte[],%20int,%20int))`(byte[] b, int off, int len) ` Reads the requested number of bytes from the input stream into the given byte array.                                                                                            | | ` byte[]`                                                                            | ` `[readNBytes](https://developer.android.com/reference/java/io/InputStream#readNBytes(int))`(int len) ` Reads up to a specified number of bytes from the input stream.                                                                                                                                                      | | ` void`                                                                              | ` `[reset](https://developer.android.com/reference/java/io/InputStream#reset())`() ` Repositions this stream to the position at the time the`mark`method was last called on this input stream.                                                                                                                               | | ` long`                                                                              | ` `[skip](https://developer.android.com/reference/java/io/InputStream#skip(long))`(long n) ` Skips over and discards`n`bytes of data from this input stream.                                                                                                                                                                 | | ` void`                                                                              | ` `[skipNBytes](https://developer.android.com/reference/java/io/InputStream#skipNBytes(long))`(long n) ` Skips over and discards exactly`n`bytes of data from this input stream.                                                                                                                                             | | ` long`                                                                              | ` `[transferTo](https://developer.android.com/reference/java/io/InputStream#transferTo(java.io.OutputStream))`(`[OutputStream](https://developer.android.com/reference/java/io/OutputStream)` out) ` Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||
| From interface` `[java.io.Closeable](https://developer.android.com/reference/java/io/Closeable)` ` |------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/io/Closeable#close())`() ` Closes this stream and releases any system resources associated with it. | ||
| From interface` `[java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable)` ` |------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[close](https://developer.android.com/reference/java/lang/AutoCloseable#close())`() ` Closes this resource, relinquishing any underlying resources. | ||

## Public methods

### getKey

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getKey ()
```

Report the key string associated with this entity within the backup data set.

<br />

|                                                                                                                                                                            Returns                                                                                                                                                                             ||
|--------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | The key string for this entity, equivalent to calling[BackupDataInput.getKey()](https://developer.android.com/reference/android/app/backup/BackupDataInput#getKey())on the underlying[BackupDataInput](https://developer.android.com/reference/android/app/backup/BackupDataInput). <br /> |

### read

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int read ()
```

Read one byte of entity data from the stream, returning it as an integer value. If more than[size()](https://developer.android.com/reference/android/app/backup/BackupDataInputStream#size())bytes of data are read from the stream, the output of this method is undefined.

<br />

|                                       Returns                                        ||
|-------|-------------------------------------------------------------------------------|
| `int` | The byte read, or undefined if the end of the stream has been reached. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### read

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int read (byte[] b, 
                int offset, 
                int size)
```

Read up to`size`bytes of data into a byte array, beginning at position`offset`within the array.

<br />

|                                                                                          Parameters                                                                                           ||
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `b`      | `byte`: Byte array into which the data will be read <br />                                                                                                                          |
| `offset` | `int`: The data will be stored in`b`beginning at this index within the array. <br />                                                                                                |
| `size`   | `int`: 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. <br /> |

|                                                  Returns                                                   ||
|-------|-----------------------------------------------------------------------------------------------------|
| `int` | The number of bytes of data read, or zero if all of the entity's data has already been read. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### read

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int read (byte[] b)
```

Read enough entity data into a byte array to fill the array.

<br />

|                                                                                             Parameters                                                                                              ||
|-----|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `b` | `byte`: 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. <br /> |

|                                                  Returns                                                   ||
|-------|-----------------------------------------------------------------------------------------------------|
| `int` | The number of bytes of data read, or zero if all of the entity's data has already been read. <br /> |

|                                    Throws                                     ||
|----------------------------------------------------------------------------|---|
| [IOException](https://developer.android.com/reference/java/io/IOException) |   |

### size

Added in[API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int size ()
```

Report the total number of bytes of data available for the current entity.

<br />

|                                                                                                                                                     Returns                                                                                                                                                     ||
|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | The number of data bytes available, equivalent to calling[BackupDataInput.getDataSize()](https://developer.android.com/reference/android/app/backup/BackupDataInput#getDataSize())on the underlying[BackupDataInput](https://developer.android.com/reference/android/app/backup/BackupDataInput). <br /> |