AssetFileDescriptor

open class AssetFileDescriptor : Parcelable, Closeable
kotlin.Any
   ↳ android.content.res.AssetFileDescriptor

File descriptor of an entry in the AssetManager. This provides your own opened FileDescriptor that can be used to read the data, as well as the offset and length of that entry's data in the file.

Summary

Nested classes
open

An InputStream you can create on a ParcelFileDescriptor, which will take care of calling ParcelFileDescriptor.close() for you when the stream is closed.

open

An OutputStream you can create on a ParcelFileDescriptor, which will take care of calling ParcelFileDescriptor.close() for you when the stream is closed.

Constants
static Long

Length used with #AssetFileDescriptor(ParcelFileDescriptor, long, long) and #getDeclaredLength when a length has not been declared.

Inherited constants
Public constructors
<init>(fd: ParcelFileDescriptor!, startOffset: Long, length: Long)

Create a new AssetFileDescriptor from the given values.

<init>(fd: ParcelFileDescriptor!, startOffset: Long, length: Long, extras: Bundle!)

Create a new AssetFileDescriptor from the given values.

Public methods
open ParcelFileDescriptor!

The AssetFileDescriptor contains its own ParcelFileDescriptor, which in addition to the normal FileDescriptor object also allows you to close the descriptor when you are done with it.

open Long

Returns the total number of bytes of this asset entry's data.

open Long

Returns the byte offset where this asset entry's data starts.

open String

open Bundle!

Returns any additional details that can be used to interpret the underlying file descriptor.

open FileInputStream!

Create and return a new auto-close input stream for this asset.

open FileOutputStream!

Create and return a new auto-close output stream for this asset.

open Unit
writeToParcel(out: Parcel!, flags: Int)

Flatten this object in to a Parcel.

open Long

Return the actual number of bytes that were declared when the AssetFileDescriptor was constructed.

open Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

open Unit

Convenience for calling getParcelFileDescriptor().close().

open FileDescriptor!

Returns the FileDescriptor that can be used to read the data in the file.

Properties
static Parcelable.Creator<AssetFileDescriptor!>!

Requires API level 3 (Android 1.5, Cupcake)

Constants

UNKNOWN_LENGTH

added in API level 3
static val UNKNOWN_LENGTH: Long

Length used with #AssetFileDescriptor(ParcelFileDescriptor, long, long) and #getDeclaredLength when a length has not been declared. This means the data extends to the end of the file.
Requires API level 3 (Android 1.5, Cupcake)

Value: -1L

Public constructors

<init>

AssetFileDescriptor(fd: ParcelFileDescriptor!, startOffset: Long, length: Long)

Create a new AssetFileDescriptor from the given values.

Parameters
fd ParcelFileDescriptor!: The underlying file descriptor.
startOffset ParcelFileDescriptor!: The location within the file that the asset starts. This must be 0 if length is UNKNOWN_LENGTH.
length ParcelFileDescriptor!: The number of bytes of the asset, or #UNKNOWN_LENGTH if it extends to the end of the file.

<init>

AssetFileDescriptor(fd: ParcelFileDescriptor!, startOffset: Long, length: Long, extras: Bundle!)

Create a new AssetFileDescriptor from the given values.

Parameters
fd ParcelFileDescriptor!: The underlying file descriptor.
startOffset ParcelFileDescriptor!: The location within the file that the asset starts. This must be 0 if length is UNKNOWN_LENGTH.
length ParcelFileDescriptor!: The number of bytes of the asset, or #UNKNOWN_LENGTH if it extends to the end of the file.
extras ParcelFileDescriptor!: additional details that can be used to interpret the underlying file descriptor. May be null.

Public methods

getParcelFileDescriptor

open fun getParcelFileDescriptor(): ParcelFileDescriptor!

The AssetFileDescriptor contains its own ParcelFileDescriptor, which in addition to the normal FileDescriptor object also allows you to close the descriptor when you are done with it.

getLength

open fun getLength(): Long

Returns the total number of bytes of this asset entry's data. May be #UNKNOWN_LENGTH if the asset extends to the end of the file. If the AssetFileDescriptor was constructed with #UNKNOWN_LENGTH, this will use ParcelFileDescriptor.getStatSize() to find the total size of the file, returning that number if found or #UNKNOWN_LENGTH if it could not be determined.

getStartOffset

open fun getStartOffset(): Long

Returns the byte offset where this asset entry's data starts.

toString

open fun toString(): String

getExtras

added in API level 19
open fun getExtras(): Bundle!

Returns any additional details that can be used to interpret the underlying file descriptor. May be null.
Requires API level 19 (Android 4.4, KitKat)

createInputStream

added in API level 3
open fun createInputStream(): FileInputStream!

Create and return a new auto-close input stream for this asset. This will either return a full asset AutoCloseInputStream, or an underlying ParcelFileDescriptor.AutoCloseInputStream depending on whether the the object represents a complete file or sub-section of a file. You should only call this once for a particular asset.
Requires API level 3 (Android 1.5, Cupcake)

createOutputStream

added in API level 3
open fun createOutputStream(): FileOutputStream!

Create and return a new auto-close output stream for this asset. This will either return a full asset AutoCloseOutputStream, or an underlying ParcelFileDescriptor.AutoCloseOutputStream depending on whether the the object represents a complete file or sub-section of a file. You should only call this once for a particular asset.
Requires API level 3 (Android 1.5, Cupcake)

writeToParcel

added in API level 3
open fun writeToParcel(out: Parcel!, flags: Int): Unit

Flatten this object in to a Parcel. Requires API level 3 (Android 1.5, Cupcake)

Parameters
dest Parcel!: The Parcel in which the object should be written.
flags Parcel!: Additional flags about how the object should be written. May be 0 or #PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

getDeclaredLength

added in API level 3
open fun getDeclaredLength(): Long

Return the actual number of bytes that were declared when the AssetFileDescriptor was constructed. Will be #UNKNOWN_LENGTH if the length was not declared, meaning data should be read to the end of the file.
Requires API level 3 (Android 1.5, Cupcake)

describeContents

added in API level 3
open fun describeContents(): Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of #writeToParcel(Parcel, int), the return value of this method must include the #CONTENTS_FILE_DESCRIPTOR bit. Requires API level 3 (Android 1.5, Cupcake)

Return
Int: a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

close

open fun close(): Unit

Convenience for calling getParcelFileDescriptor().close().

Exceptions
Exception if this resource cannot be closed
IOException if an I/O error occurs

getFileDescriptor

open fun getFileDescriptor(): FileDescriptor!

Returns the FileDescriptor that can be used to read the data in the file.

Properties

CREATOR

added in API level 3
static val CREATOR: Parcelable.Creator<AssetFileDescriptor!>!

Requires API level 3 (Android 1.5, Cupcake)