Added in API level 1

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 android.

open

An OutputStream you can create on a ParcelFileDescriptor, which will take care of calling android.

Constants
static Long

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

Inherited constants
Public constructors
AssetFileDescriptor(fd: ParcelFileDescriptor!, startOffset: Long, length: Long)

Create a new AssetFileDescriptor from the given values.

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

Create a new AssetFileDescriptor from the given values.

Public methods
open Unit

Convenience for calling getParcelFileDescriptor().close().

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 Int

open Long

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

open Bundle!

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

open FileDescriptor!

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

open Long

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

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 byte offset where this asset entry's data starts.

open String

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

Properties
static Parcelable.Creator<AssetFileDescriptor!>

Constants

UNKNOWN_LENGTH

Added in API level 3
static val UNKNOWN_LENGTH: Long

Length used with AssetFileDescriptor(android.os.ParcelFileDescriptor,long,long) and getDeclaredLength when a length has not been declared. This means the data extends to the end of the file.

Value: -1L

Public constructors

AssetFileDescriptor

Added in API level 1
AssetFileDescriptor(
    fd: ParcelFileDescriptor!,
    startOffset: Long,
    length: Long)

Create a new AssetFileDescriptor from the given values.

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

AssetFileDescriptor

Added in API level 19
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 Long: The location within the file that the asset starts. This must be 0 if length is UNKNOWN_LENGTH.
length Long: The number of bytes of the asset, or UNKNOWN_LENGTH if it extends to the end of the file.
extras Bundle!: additional details that can be used to interpret the underlying file descriptor. May be null.

Public methods

close

Added in API level 1
open fun close(): Unit

Convenience for calling getParcelFileDescriptor().close().

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

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.

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.

describeContents

Added in API level 3
open fun describeContents(): Int
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

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.

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.

getFileDescriptor

Added in API level 1
open fun getFileDescriptor(): FileDescriptor!

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

getLength

Added in API level 1
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.

getParcelFileDescriptor

Added in API level 1
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.

getStartOffset

Added in API level 1
open fun getStartOffset(): Long

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

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 3
open fun writeToParcel(
    out: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: 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

Properties

CREATOR

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