Most visited

Recently visited

Added in API level 1

AssetFileDescriptor

public class AssetFileDescriptor
extends Object implements Parcelable, Closeable

java.lang.Object
    android.content.res.AssetFileDescriptor


AssetManager中条目的文件描述符。 这提供了您自己打开的FileDescriptor,可用于读取数据,以及文件中该条目数据的偏移量和长度。

摘要(Summary)

Nested classes

class AssetFileDescriptor.AutoCloseInputStream

您可以在ParcelFileDescriptor上创建一个InputStream,它将负责在流关闭时为您调用ParcelFileDescritor.close()

class AssetFileDescriptor.AutoCloseOutputStream

一个可以在ParcelFileDescriptor上创建的OutputStream,它可以在流关闭时为您调用ParcelFileDescritor.close()

常量(Constants)

long UNKNOWN_LENGTH

长度 AssetFileDescriptor(ParcelFileDescriptor, long, long) getDeclaredLength()时与 AssetFileDescriptor(ParcelFileDescriptor, long, long)getDeclaredLength()使用的长度。

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<AssetFileDescriptor> CREATOR

Public constructors

AssetFileDescriptor(ParcelFileDescriptor fd, long startOffset, long length)

根据给定值创建一个新的AssetFileDescriptor。

AssetFileDescriptor(ParcelFileDescriptor fd, long startOffset, long length, Bundle extras)

根据给定值创建一个新的AssetFileDescriptor。

公共方法(Public methods)

void close()

方便拨打 getParcelFileDescriptor().close()

FileInputStream createInputStream()

为此资产创建并返回新的自动关闭输入流。

FileOutputStream createOutputStream()

为此资产创建并返回新的自动关闭输出流。

int describeContents()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。

long getDeclaredLength()

返回构造AssetFileDescriptor时声明的实际字节数。

Bundle getExtras()

返回可用于解释底层文件描述符的任何其他详细信息。

FileDescriptor getFileDescriptor()

返回可用于读取文件中数据的FileDescriptor。

long getLength()

返回此资产条目数据的总字节数。

ParcelFileDescriptor getParcelFileDescriptor()

AssetFileDescriptor包含自己的ParcelFileDescriptor,除了普通的FileDescriptor对象外,还允许您在完成描述符时关闭该描述符。

long getStartOffset()

返回此资产条目数据开始处的字节偏移量。

String toString()

返回对象的字符串表示形式。

void writeToParcel(Parcel out, int flags)

将此对象平铺到一个包裹中。

继承方法(Inherited methods)

From class java.lang.Object
From interface android.os.Parcelable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

常量(Constants)

UNKNOWN_LENGTH

Added in API level 3
long UNKNOWN_LENGTH

长度AssetFileDescriptor(ParcelFileDescriptor, long, long) getDeclaredLength()时与AssetFileDescriptor(ParcelFileDescriptor, long, long)getDeclaredLength()使用的长度。 这意味着数据会延伸到文件的末尾。

常量值:-1(0xffffffffffffffff)

Fields

CREATOR

Added in API level 3
Creator<AssetFileDescriptor> CREATOR

Public constructors

AssetFileDescriptor

Added in API level 1
AssetFileDescriptor (ParcelFileDescriptor fd, 
                long startOffset, 
                long length)

根据给定值创建一个新的AssetFileDescriptor。

参数(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 (ParcelFileDescriptor fd, 
                long startOffset, 
                long length, 
                Bundle extras)

根据给定值创建一个新的AssetFileDescriptor。

参数(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
void close ()

方便拨打 getParcelFileDescriptor().close()

抛出异常(Throws)
IOException

createInputStream

Added in API level 3
FileInputStream createInputStream ()

为此资产创建并返回新的自动关闭输入流。 这将返回一个完整的资产AssetFileDescriptor.AutoCloseInputStream或一个底层的ParcelFileDescriptor.AutoCloseInputStream这取决于对象是代表一个完整的文件还是一个文件的子部分。 您应该只针对特定资产调用一次。

返回(Returns)
FileInputStream
抛出异常(Throws)
IOException

createOutputStream

Added in API level 3
FileOutputStream createOutputStream ()

为此资产创建并返回新的自动关闭输出流。 这将返回一个完整的资产AssetFileDescriptor.AutoCloseOutputStream ,或者一个底层的ParcelFileDescriptor.AutoCloseOutputStream这取决于对象是代表一个完整的文件还是一个文件的子部分。 您应该只针对特定资产调用一次。

返回(Returns)
FileOutputStream
抛出异常(Throws)
IOException

describeContents

Added in API level 3
int describeContents ()

描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。

返回(Returns)
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

getDeclaredLength

Added in API level 3
long getDeclaredLength ()

返回构造AssetFileDescriptor时声明的实际字节数。 如果长度未被声明,将为UNKNOWN_LENGTH ,这意味着数据应该读到文件的末尾。

返回(Returns)
long

也可以看看:

getExtras

Added in API level 19
Bundle getExtras ()

返回可用于解释底层文件描述符的任何其他详细信息。 可能为null。

返回(Returns)
Bundle

getFileDescriptor

Added in API level 1
FileDescriptor getFileDescriptor ()

返回可用于读取文件中数据的FileDescriptor。

返回(Returns)
FileDescriptor

getLength

Added in API level 1
long getLength ()

返回此资产条目数据的总字节数。 如果资产扩展到文件的末尾,可能是UNKNOWN_LENGTH 如果AssetFileDescriptor与构建UNKNOWN_LENGTH ,这将使用ParcelFileDescriptor.getStatSize()找到该文件的总大小,如果发现或返回这个数字UNKNOWN_LENGTH如果无法确定它。

返回(Returns)
long

也可以看看:

getParcelFileDescriptor

Added in API level 1
ParcelFileDescriptor getParcelFileDescriptor ()

AssetFileDescriptor包含自己的ParcelFileDescriptor,除了普通的FileDescriptor对象外,还允许您在完成描述符时关闭该描述符。

返回(Returns)
ParcelFileDescriptor

getStartOffset

Added in API level 1
long getStartOffset ()

返回此资产条目数据开始处的字节偏移量。

返回(Returns)
long

toString

Added in API level 1
String toString ()

返回对象的字符串表示形式。 一般来说, toString方法返回一个“文本表示”该对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。

toString方法Object返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

返回(Returns)
String a string representation of the object.

writeToParcel

Added in API level 3
void writeToParcel (Parcel out, 
                int flags)

将此对象平铺到一个包裹中。

参数(Parameters)
out Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Hooray!