public class DataInputBuffer extends DataInputStream
DataInput 实现.
DataInputBuffer 继承自 DataInputStream ,提供了 DataInput
的实现,可以方便的将内存数据作为输入,并提供 reset 系列方法支持对象复用。
代码示例:
DataInputBuffer buffer = new DataInputBuffer();
while (... loop condition ...) {
byte[] data = ... get data ...;
int dataLength = ... get data length ...;
buffer.reset(data, dataLength); //重用 buffer,无需再new 对象
... read buffer using DataInput methods ...
}
Writable.readFields(DataInput),
DataOutputBuffer| Constructor and Description |
|---|
DataInputBuffer()
构建一个空 DataInputBuffer
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getData()
获取当前数据内容的字节数组
|
int |
getLength()
获取数据输入的内容长度
|
int |
getPosition()
获取数据输入流的当前位置
|
void |
reset(byte[] input,
int length)
重置内存数据输入.
|
void |
reset(byte[] input,
int start,
int length)
重置内存数据输入.
|
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytesavailable, close, mark, markSupported, read, reset, skippublic void reset(byte[] input,
int length)
将 input[0,...,length-1] 作为数据输入
input - 字节数组length - 数据内容长度public void reset(byte[] input,
int start,
int length)
将 input[start,...,start+length-1] 作为数据输入
input - 字节数组start - 数据起始位置length - 数据内容长度public byte[] getData()
public int getPosition()
public int getLength()
Copyright © 2021 Alibaba Cloud Computing. All rights reserved.