本文整理匯總了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);
}