當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。