public static class AssetFileDescriptor.AutoCloseInputStream
extends ParcelFileDescriptor.AutoCloseInputStream
java.lang.Object | ||||
↳ | java.io.InputStream | |||
↳ | java.io.FileInputStream | |||
↳ | android.os.ParcelFileDescriptor.AutoCloseInputStream | |||
↳ | android.content.res.AssetFileDescriptor.AutoCloseInputStream |
您可以在ParcelFileDescriptor上创建一个InputStream,该流将关闭时为您调用 ParcelFileDescritor.close()
。
Public constructors |
|
---|---|
AssetFileDescriptor.AutoCloseInputStream(AssetFileDescriptor fd) |
Public methods |
|
---|---|
int |
available() 返回可从此输入流中读取(或跳过)的剩余字节数的估计值,而不会因为此输入流的下一次方法调用而被阻塞。 |
void |
mark(int readlimit) 标记此输入流中的当前位置。 |
boolean |
markSupported() 测试此输入流是否支持 |
int |
read() 从此输入流中读取一个字节的数据。 |
int |
read(byte[] buffer, int offset, int count) 从该输入流中最多读取 |
int |
read(byte[] buffer) 从这个输入流中读取多达 |
void |
reset() 将此流重新定位到上次在此输入流上调用 |
long |
skip(long count) 跳过并丢弃来自输入流的 |
Inherited methods |
|
---|---|
From class android.os.ParcelFileDescriptor.AutoCloseInputStream
|
|
From class java.io.FileInputStream
|
|
From class java.io.InputStream
|
|
From class java.lang.Object
|
|
From interface java.io.Closeable
|
|
From interface java.lang.AutoCloseable
|
AssetFileDescriptor.AutoCloseInputStream (AssetFileDescriptor fd)
Parameters | |
---|---|
fd |
AssetFileDescriptor
|
Throws | |
---|---|
IOException |
int available ()
返回可从此输入流中读取(或跳过)的剩余字节数的估计值,而不会因为此输入流的下一次方法调用而被阻塞。 下一次调用可能是同一个线程或另一个线程。 单个读取或跳过这么多字节不会被阻塞,但可以读取或跳过更少的字节。
在某些情况下,非阻塞式读取(或跳过)在缓慢时可能会被阻止,例如,通过慢速网络读取大型文件时。
Returns | |
---|---|
int |
an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking. |
Throws | |
---|---|
IOException |
void mark (int readlimit)
标记此输入流中的当前位置。 随后调用reset
方法将此流重新定位到最后标记的位置,以便后续读取重新读取相同的字节。
参数 readlimit
告诉这个输入流允许在标记位置失效之前读取很多字节。
mark
的总体合同是,如果方法markSupported
返回true
,则流以某种方式记住了在调用mark
之后读取的所有字节,并准备在调用方法reset
时再次提供那些相同的字节。 但是,如果在reset
之前从流中读取了超过readlimit
个字节,则根本不需要记录任何数据。
标记封闭的流不应该对流有任何影响。
该 mark
的方法 InputStream
什么都不做。
Parameters | |
---|---|
readlimit |
int : the maximum limit of bytes that can be read before the mark position becomes invalid. |
boolean markSupported ()
测试此输入流是否支持mark
和reset
方法。 是否支持mark
和reset
是特定输入流实例的不变特性。 该markSupported
方法InputStream
回报false
。
Returns | |
---|---|
boolean |
true if this stream instance supports the mark and reset methods; false otherwise. |
int read ()
从此输入流中读取一个字节的数据。 如果没有输入可用,此方法会阻止。
Returns | |
---|---|
int |
the next byte of data, or -1 if the end of the file is reached. |
Throws | |
---|---|
IOException |
int read (byte[] buffer, int offset, int count)
从这个输入流中读取多达len
个字节的数据到一个字节数组中。 如果len
不为零,则该方法阻塞,直到某些输入可用; 否则,不读取字节并返回0
。
Parameters | |
---|---|
buffer |
byte : the buffer into which the data is read. |
offset |
int : the start offset in the destination array b |
count |
int : the maximum number of bytes read. |
Returns | |
---|---|
int |
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. |
Throws | |
---|---|
IOException |
int read (byte[] buffer)
从这个输入流中最多读取b.length
个字节的数据到一个字节数组中。 此方法阻塞,直到有些输入可用。
Parameters | |
---|---|
buffer |
byte : the buffer into which the data is read. |
Returns | |
---|---|
int |
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. |
Throws | |
---|---|
IOException |
void reset ()
将此流重新定位到上次在此输入流上调用方法 mark
时的位置。
reset
的总合同是:
markSupported
returns true
, then:
mark
has not been called since the stream was created, or the number of bytes read from the stream since mark
was last called is larger than the argument to mark
at that last call, then an IOException
might be thrown. IOException
is not thrown, then the stream is reset to a state such that all the bytes read since the most recent call to mark
(or since the start of the file, if mark
has not been called) will be resupplied to subsequent callers of the read
method, followed by any bytes that otherwise would have been the next input data as of the time of the call to reset
. markSupported
returns false
, then:
reset
may throw an IOException
. IOException
is not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of the read
method depend on the particular type of the input stream. 类 InputStream
的方法 reset
除了抛出 IOException
之外什么也不 IOException
。
Throws | |
---|---|
IOException |
long skip (long count)
跳过并丢弃来自输入流的 n
字节的数据。
由于各种原因, skip
方法可能会跳过一些较小数量的字节,可能是0
。 如果n
为负数,则抛出IOException
,即使InputStream
超类的skip
方法在这种情况下不起作用。 返回跳过的实际字节数。
此方法可能会跳过比备份文件中剩余的更多的字节。 这不会产生异常,并且跳过的字节数可能包含超出备份文件EOF的一些字节数。 在跳过结尾后试图从流中读取将导致-1指示文件的结尾。
Parameters | |
---|---|
count |
long : the number of bytes to be skipped. |
Returns | |
---|---|
long |
the actual number of bytes skipped. |
Throws | |
---|---|
IOException |