鸿蒙OS开发文档 鸿蒙OS ObjectInput

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 0

ObjectInput

public interface ObjectInput
extends DataInput, AutoCloseable

ObjectInput 扩展了 DataInput 接口以包括对象的读取。 DataInput 包括用于输入原始类型的方法,ObjectInput 扩展了该接口以包括对象、数组和字符串。

Since:

JDK1.1

方法总结

修饰符和类型方法描述
intavailable()返回可以在不阻塞的情况下读取的字节数。
voidclose()关闭输入流。
intread()读取一个字节的数据。
intread(byte[] b)读入一个字节数组。
intread(byte[] b, int off, int len)读入一个字节数组。
ObjectreadObject()读取并返回一个对象。
longskip(long n)跳过 n 个字节的输入。
从接口 java.io.DataInput 继承的方法
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes

方法详情

readObject

Object readObject() throws ClassNotFoundException, IOException

读取并返回一个对象。 实现此接口的类定义了从何处“读取”对象。

返回:

从流中读取的对象

Throws:

Throw名称Throw描述
ClassNotFoundException如果找不到序列化对象的类。
IOException如果发生任何常见的输入/输出相关异常。

read

int read() throws IOException

读取一个字节的数据。 如果没有可用的输入,此方法将阻塞。

返回:

读取的字节,如果到达流的末尾,则为 -1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

read

int read(byte[] b) throws IOException

读入一个字节数组。 此方法将阻塞,直到某些输入可用。

参数:

参数名称参数描述
b读取数据的缓冲区

返回:

实际读取的字节数,到达流末尾时返回-1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

read

int read(byte[] b, int off, int len) throws IOException

读入一个字节数组。 此方法将阻塞,直到某些输入可用。

参数:

参数名称参数描述
b读取数据的缓冲区
off数据的起始偏移量
len读取的最大字节数

返回:

实际读取的字节数,到达流末尾时返回-1。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

skip

long skip(long n) throws IOException

跳过 n 个字节的输入。

参数:

参数名称参数描述
n要跳过的字节数

返回:

跳过的实际字节数。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

available

int available() throws IOException

返回可以在不阻塞的情况下读取的字节数。

返回:

可用字节数。

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。

close

void close() throws IOException

关闭输入流。 必须调用以释放与流关联的任何资源。

指定者:

在接口 AutoCloseable 中关闭

Throws:

Throw名称Throw描述
IOException如果发生 I/O 错误。