# AssetFileDescriptor.AutoCloseInputStream

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

# AutoCloseInputStream

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/content/res/AssetFileDescriptor.AutoCloseInputStream "View this page in Java")  

```
open class AutoCloseInputStream : ParcelFileDescriptor.AutoCloseInputStream
```

|---|---|---|---|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                                        |||||
| ↳ | [java.io.InputStream](https://developer.android.com/reference/kotlin/java/io/InputStream.html#)                                                                                       ||||
|   | ↳ | [java.io.FileInputStream](https://developer.android.com/reference/kotlin/java/io/FileInputStream.html#)                                                                            |||
|   |   | ↳ | [android.os.ParcelFileDescriptor.AutoCloseInputStream](https://developer.android.com/reference/kotlin/android/os/ParcelFileDescriptor.AutoCloseInputStream.html#)               ||
|   |   |   | ↳ | [android.content.res.AssetFileDescriptor.AutoCloseInputStream](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#) |

An InputStream you can create on a ParcelFileDescriptor, which will take care of calling android.os.ParcelFileDescriptor#close for you when the stream is closed. It has a ParcelFileDescriptor.AutoCloseInputStream member to make delegate calls and during definition it will create seekable or non seekable child object AssetFileDescriptor.AutoCloseInputStream depends on the type of file descriptor to provide different solution.

## Summary

|                                                                                                                                                          Public constructors                                                                                                                                                          ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [AutoCloseInputStream](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#AutoCloseInputStream(android.content.res.AssetFileDescriptor))`(`fd:` `[AssetFileDescriptor](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor)!`)` <br /> |

|                                                                                                                                                                                                                                                                                Public methods                                                                                                                                                                                                                                                                                ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                         | [available](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#available())`()` <br />                                                                                                                                                                                                                                                                                                                      |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                       | [close](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#close())`()` <br />                                                                                                                                                                                                                                                                                                                              |
| open[FileChannel](https://developer.android.com/reference/kotlin/java/nio/channels/FileChannel.html#)! | [getChannel](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#getChannel())`()` <br />                                                                                                                                                                                                                                                                                                                    |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                       | [mark](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#mark(kotlin.Int))`(`readlimit:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` <br />                                                                                                                                                                                                                             |
| open[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                 | [markSupported](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#markSupported())`()` <br />                                                                                                                                                                                                                                                                                                              |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                         | [read](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#read())`()` <br />                                                                                                                                                                                                                                                                                                                                |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                         | [read](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#read(kotlin.ByteArray))`(`buffer:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`)` <br />                                                                                                                                                                                                            |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                         | [read](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#read(kotlin.ByteArray,%20kotlin.Int,%20kotlin.Int))`(`buffer:` `[ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!`, `offset:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `count:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` <br /> |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)                       | [reset](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#reset())`()` <br />                                                                                                                                                                                                                                                                                                                              |
| open[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)                       | [skip](https://developer.android.com/reference/kotlin/android/content/res/AssetFileDescriptor.AutoCloseInputStream#skip(kotlin.Long))`(`count:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` <br />                                                                                                                                                                                                                              |

## Public constructors

### AutoCloseInputStream

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

```
AutoCloseInputStream(fd: AssetFileDescriptor!)
```

## Public methods

### available

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

```
open fun available(): Int
```

|                                                                                                Return                                                                                                ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking. |

|                                                Exceptions                                                 ||
|-----------------------|------------------------------------------------------------------------------------|
| `java.io.IOException` | if this file input stream has been closed by calling`close`or an I/O error occurs. |

### close

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

```
open fun close(): Unit
```

|                        Exceptions                        ||
|-----------------------|-----------------------------------|
| `java.lang.Exception` | if this resource cannot be closed |
| `java.io.IOException` | if an I/O error occurs.           |

### getChannel

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

```
open fun getChannel(): FileChannel!
```

|                                                                           Return                                                                            ||
|----------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| [FileChannel](https://developer.android.com/reference/kotlin/java/nio/channels/FileChannel.html#)! | the file channel associated with this file input stream |

### mark

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

```
open fun mark(readlimit: Int): Unit
```

|                                                                                  Parameters                                                                                   ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `readlimit` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the maximum limit of bytes that can be read before the mark position becomes invalid. |

### markSupported

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

```
open fun markSupported(): Boolean
```

|                                                                                 Return                                                                                  ||
|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if this stream instance supports the mark and reset methods;`false`otherwise. |

### read

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

```
open fun read(): Int
```

|                                                                   Return                                                                    ||
|----------------------------------------------------------------------------|-----------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the next byte of data, or`-1`if the end of the file is reached. |

|                   Exceptions                   ||
|-----------------------|-------------------------|
| `java.io.IOException` | if an I/O error occurs. |

### read

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

```
open fun read(buffer: ByteArray!): Int
```

|                  Parameters                  ||
|-----|-----------------------------------------|
| `b` | the buffer into which the data is read. |

|                                                                                                  Return                                                                                                  ||
|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the total number of bytes read into the buffer, or`-1`if there is no more data because the end of the file has been reached. |

|                        Exceptions                         ||
|----------------------------------|-------------------------|
| `java.io.IOException`            | if an I/O error occurs. |
| `java.lang.NullPointerException` | if`b`is`null`.          |

### read

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

```
open fun read(
    buffer: ByteArray!, 
    offset: Int, 
    count: Int
): Int
```

|                     Parameters                      ||
|-------|----------------------------------------------|
| `b`   | the buffer into which the data is read.      |
| `off` | the start offset in the destination array`b` |
| `len` | the maximum number of bytes read.            |

|                                                                                                  Return                                                                                                  ||
|----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the total number of bytes read into the buffer, or`-1`if there is no more data because the end of the file has been reached. |

|                                                     Exceptions                                                     ||
|---------------------------------------|-----------------------------------------------------------------------------|
| `java.io.IOException`                 | if an I/O error occurs.                                                     |
| `java.lang.NullPointerException`      | If`b`is`null`.                                                              |
| `java.lang.IndexOutOfBoundsException` | If`off`is negative,`len`is negative, or`len`is greater than`b.length - off` |

### reset

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

```
open fun reset(): Unit
```

|                                           Exceptions                                           ||
|-----------------------|-------------------------------------------------------------------------|
| `java.io.IOException` | if this stream has not been marked or if the mark has been invalidated. |

### skip

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

```
open fun skip(count: Long): Long
```

|               Parameters                ||
|-----|------------------------------------|
| `n` | the number of bytes to be skipped. |

|                                                      Return                                                       ||
|------------------------------------------------------------------------------|-------------------------------------|
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | the actual number of bytes skipped. |

|                                                Exceptions                                                ||
|-----------------------|-----------------------------------------------------------------------------------|
| `java.io.IOException` | if n is negative, if the stream does not support seek, or if an I/O error occurs. |