当前位置: 首页>>代码示例>>Java>>正文


Java Decoder.readInt方法代码示例

本文整理汇总了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;
}
 
开发者ID:jianglibo,项目名称:gora-boot,代码行数:25,代码来源:IOUtils.java

示例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;
}
 
开发者ID:apache,项目名称:gora,代码行数:28,代码来源:IOUtils.java

示例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);
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:21,代码来源:MemcmpDecoderTest.java

示例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);
}
 
开发者ID:cloudera,项目名称:cdk,代码行数:21,代码来源:ColumnDecoderTest.java


注:本文中的org.apache.avro.io.Decoder.readInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。