本文整理汇总了Java中org.apache.avro.io.Decoder.readInt方法的典型用法代码示例。如果您正苦于以下问题:Java Decoder.readInt方法的具体用法?Java Decoder.readInt怎么用?Java Decoder.readInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.avro.io.Decoder
的用法示例。
在下文中一共展示了Decoder.readInt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readBoolArray
import org.apache.avro.io.Decoder; //导入方法依赖的package包/类
/**
* Reads a boolean[] from input
* @throws IOException
*/
public static boolean[] readBoolArray(Decoder in) throws IOException {
int length = in.readInt();
boolean[] boolArr = new boolean[length];
int byteArrLength = (int)Math.ceil(length / 8.0);
byte[] byteArr = new byte[byteArrLength];
in.readFixed(byteArr);
int arrIndex = 0;
byte b = 0;
for(int i=0; i < length; i++) {
if(i % 8 == 0) {
b = byteArr[arrIndex++];
}
boolArr[i] = (b & 0x01) > 0;
b >>= 1;
}
return boolArr;
}
示例2: readBoolArray
import org.apache.avro.io.Decoder; //导入方法依赖的package包/类
/**
* Reads a boolean[] from input.
*
* @param in decoder instance which wraps the input stream where data is read.
* @return boolean array.
* @throws IOException when failed reading the data from stream.
*/
public static boolean[] readBoolArray(Decoder in) throws IOException {
int length = in.readInt();
boolean[] boolArr = new boolean[length];
int byteArrLength = (int)Math.ceil(length / 8.0);
byte[] byteArr = new byte[byteArrLength];
in.readFixed(byteArr);
int arrIndex = 0;
byte b = 0;
for(int i=0; i < length; i++) {
if(i % 8 == 0) {
b = byteArr[arrIndex++];
}
boolArr[i] = (b & 0x01) > 0;
b >>= 1;
}
return boolArr;
}
示例3: testDecodeInt
import org.apache.avro.io.Decoder; //导入方法依赖的package包/类
@Test
public void testDecodeInt() throws Exception {
InputStream in = new ByteArrayInputStream(new byte[] { (byte) 0x80,
(byte) 0x00, (byte) 0x00, (byte) 0x01 });
Decoder decoder = new MemcmpDecoder(in);
int i = decoder.readInt();
assertEquals(1, i);
in = new ByteArrayInputStream(new byte[] { (byte) 0x7f, (byte) 0xff,
(byte) 0xff, (byte) 0xff });
decoder = new MemcmpDecoder(in);
i = decoder.readInt();
assertEquals(-1, i);
in = new ByteArrayInputStream(new byte[] { (byte) 0x80, (byte) 0x00,
(byte) 0x00, (byte) 0x00 });
decoder = new MemcmpDecoder(in);
i = decoder.readInt();
assertEquals(0, i);
}
示例4: testDecodeInt
import org.apache.avro.io.Decoder; //导入方法依赖的package包/类
@Test
public void testDecodeInt() throws Exception {
InputStream in = new ByteArrayInputStream(new byte[] { (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x01});
Decoder decoder = new ColumnDecoder(in);
int i = decoder.readInt();
assertEquals(1, i);
in = new ByteArrayInputStream(new byte[] { (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff });
decoder = new ColumnDecoder(in);
i = decoder.readInt();
assertEquals(-1, i);
in = new ByteArrayInputStream(new byte[] { (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00 });
decoder = new ColumnDecoder(in);
i = decoder.readInt();
assertEquals(0, i);
}