當前位置: 首頁>>代碼示例>>Java>>正文


Java DataInput類代碼示例

本文整理匯總了Java中java.io.DataInput的典型用法代碼示例。如果您正苦於以下問題:Java DataInput類的具體用法?Java DataInput怎麽用?Java DataInput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataInput類屬於java.io包,在下文中一共展示了DataInput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testStringArrayObject

import java.io.DataInput; //導入依賴的package包/類
/**
 * Tests data serializing a <code>String</code> array using {@link DataSerializer#writeObject}.
 */
@Test
public void testStringArrayObject() throws Exception {
  Random random = getRandom();

  String[] array = new String[] {String.valueOf(random.nextLong()),
      String.valueOf(random.nextLong()), String.valueOf(random.nextLong())};

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObject(array, out);
  out.flush();

  DataInput in = getDataInput();
  String[] array2 = (String[]) DataSerializer.readObject(in);

  assertEquals(array.length, array2.length);
  for (int i = 0; i < array.length; i++) {
    assertEquals(array[i], array2[i]);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:DataSerializableJUnitTest.java

示例2: fromDataInputV2

import java.io.DataInput; //導入依賴的package包/類
@Deprecated
static TransactionEventRecord fromDataInputV2(DataInput in)
    throws IOException {
  int header = in.readInt();
  if (header != MAGIC_HEADER) {
    throw new IOException("Header " + Integer.toHexString(header) +
        " is not the required value: " + Integer.toHexString(MAGIC_HEADER));
  }
  short type = in.readShort();
  long transactionID = in.readLong();
  long writeOrderID = in.readLong();
  TransactionEventRecord entry = newRecordForType(type, transactionID,
      writeOrderID);
  entry.readFields(in);
  return entry;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:17,代碼來源:TransactionEventRecord.java

示例3: readOplogMagicSeqRecord

import java.io.DataInput; //導入依賴的package包/類
private void readOplogMagicSeqRecord(DataInput dis, OPLOG_TYPE type) throws IOException {
  byte[] seq = new byte[OPLOG_TYPE.getLen()];
  dis.readFully(seq);
  for (int i = 0; i < OPLOG_TYPE.getLen(); i++) {
    if (seq[i] != type.getBytes()[i]) {
      if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
        logger.trace(LogMarker.PERSIST_RECOVERY,
            "oplog magic code mismatched at byte:{}, value:{}", (i + 1), seq[i]);
      }
      throw new DiskAccessException("Invalid oplog (" + type.name() + ") file provided.",
          interpreter.getNameForError());
    }
  }
  if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < OPLOG_TYPE.getLen(); i++) {
      sb.append(" " + seq[i]);
    }
    logger.trace(LogMarker.PERSIST_RECOVERY, "oplog magic code: {}", sb);
  }
  readEndOfRecord(dis);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:DiskInitFileParser.java

示例4: readIdentityHashMap

import java.io.DataInput; //導入依賴的package包/類
/**
 * Reads a <code>IdentityHashMap</code> from a <code>DataInput</code>. Note that key identity is
 * not preserved unless the keys belong to a class whose serialization preserves identity.
 *
 * @throws IOException A problem occurs while reading from <code>in</code>
 * @throws ClassNotFoundException The class of one of the <Code>IdentityHashMap</code>'s elements
 *         cannot be found.
 *
 * @see #writeIdentityHashMap
 */
public static <K, V> IdentityHashMap<K, V> readIdentityHashMap(DataInput in)
    throws IOException, ClassNotFoundException {

  InternalDataSerializer.checkIn(in);

  int size = InternalDataSerializer.readArrayLength(in);
  if (size == -1) {
    return null;
  } else {
    IdentityHashMap<K, V> map = new IdentityHashMap<K, V>(size);
    for (int i = 0; i < size; i++) {
      K key = DataSerializer.<K>readObject(in);
      V value = DataSerializer.<V>readObject(in);
      map.put(key, value);
    }

    if (logger.isTraceEnabled(LogMarker.SERIALIZER)) {
      logger.trace(LogMarker.SERIALIZER, "Read IdentityHashMap with {} elements: {}", size, map);
    }

    return map;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:34,代碼來源:DataSerializer.java

示例5: unpackUnsignedLong

import java.io.DataInput; //導入依賴的package包/類
public static long unpackUnsignedLong(DataInput buffer) throws IOException
{
	int shift = 0;
	long result = 0;
	while (shift < 64)
	{
		final byte b = buffer.readByte();
		result |= (long)(b & 0x7F) << shift;
		if ((b & 0x80) == 0)
		{
			return result;
		}
		shift += 7;
	}
	throw new IllegalArgumentException("Variable length quantity is too long");
}
 
開發者ID:quqiangsheng,項目名稱:abhot,代碼行數:17,代碼來源:Util.java

示例6: readRootIndex

import java.io.DataInput; //導入依賴的package包/類
/**
 * Read in the root-level index from the given input stream. Must match
 * what was written into the root level by
 * {@link BlockIndexWriter#writeIndexBlocks(FSDataOutputStream)} at the
 * offset that function returned.
 *
 * @param in the buffered input stream or wrapped byte input stream
 * @param numEntries the number of root-level index entries
 * @throws IOException
 */
public void readRootIndex(DataInput in, final int numEntries)
    throws IOException {
  blockOffsets = new long[numEntries];
  blockKeys = new byte[numEntries][];
  blockDataSizes = new int[numEntries];

  // If index size is zero, no index was written.
  if (numEntries > 0) {
    for (int i = 0; i < numEntries; ++i) {
      long offset = in.readLong();
      int dataSize = in.readInt();
      byte[] key = Bytes.readByteArray(in);
      add(key, offset, dataSize);
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:27,代碼來源:HFileBlockIndex.java

示例7: loadSnapshotList

import java.io.DataInput; //導入依賴的package包/類
/**
 * Load snapshots and snapshotQuota for a Snapshottable directory.
 *
 * @param snapshottableParent
 *          The snapshottable directory for loading.
 * @param numSnapshots
 *          The number of snapshots that the directory has.
 * @param loader
 *          The loader
 */
public static void loadSnapshotList(INodeDirectory snapshottableParent,
    int numSnapshots, DataInput in, FSImageFormat.Loader loader)
    throws IOException {
  DirectorySnapshottableFeature sf = snapshottableParent
      .getDirectorySnapshottableFeature();
  Preconditions.checkArgument(sf != null);
  for (int i = 0; i < numSnapshots; i++) {
    // read snapshots
    final Snapshot s = loader.getSnapshot(in);
    s.getRoot().setParent(snapshottableParent);
    sf.addSnapshot(s);
  }
  int snapshotQuota = in.readInt();
  snapshottableParent.setSnapshotQuota(snapshotQuota);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:SnapshotFSImageFormat.java

示例8: readFields

import java.io.DataInput; //導入依賴的package包/類
@Override
public void readFields(DataInput in) throws IOException {
  
  // Get the number of "unknown" classes
  
  newClasses = in.readByte();
  
  // Then read in the class names and add them to our tables
  
  for (int i = 0; i < newClasses; i++) {
    byte id = in.readByte();
    String className = in.readUTF();
    try {
      addToMap(Class.forName(className), id);
      
    } catch (ClassNotFoundException e) {
      throw new IOException("can't find class: " + className + " because "+
          e.getMessage());
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:AbstractMapWritable.java

示例9: fromData

import java.io.DataInput; //導入依賴的package包/類
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  this.className = DataSerializer.readString(in);
  swizzleGemFireClassNames();
  {
    byte bits = in.readByte();
    this.noDomainClass = (bits & NO_DOMAIN_CLASS_BIT) != 0;
    this.hasDeletedField = (bits & HAS_DELETED_FIELD_BIT) != 0;
  }

  this.typeId = in.readInt();
  this.vlfCount = in.readInt();

  int arrayLen = InternalDataSerializer.readArrayLength(in);

  for (int i = 0; i < arrayLen; i++) {
    PdxField vft = new PdxField();
    vft.fromData(in);
    addField(vft);
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:21,代碼來源:PdxType.java

示例10: doStart

import java.io.DataInput; //導入依賴的package包/類
private final void doStart() throws IOException {
    ReadUtil.readCheckType(m_stream, AXML_CHUNK_TYPE);
    /*chunk size*/
    ReadUtil.readInt(m_stream);

    m_strings = StringBlock.read(new ExtDataInput((DataInput) new LittleEndianDataInputStream(m_stream)));

    ReadUtil.readCheckType(m_stream, RESOURCEIDS_CHUNK_TYPE);
    int chunkSize = ReadUtil.readInt(m_stream);
    if (chunkSize < 8 || (chunkSize % 4) != 0) {
        throw new IOException("Invalid resource ids size (" + chunkSize + ").");
    }
    m_resourceIDs = ReadUtil.readIntArray(m_stream, chunkSize / 4 - 2);

    resetState();
}
 
開發者ID:shazam,項目名稱:axmlparser,代碼行數:17,代碼來源:AXMLParser.java

示例11: testStack

import java.io.DataInput; //導入依賴的package包/類
/**
 * Tests data serializing an {@link Stack}
 */
@Test
public void testStack() throws Exception {
  Random random = getRandom();
  Stack list = new Stack();
  int size = random.nextInt(50);
  for (int i = 0; i < size; i++) {
    list.add(new Long(random.nextLong()));
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeStack(list, out);
  out.flush();

  DataInput in = getDataInput();
  Stack list2 = DataSerializer.readStack(in);
  assertEquals(list, list2);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:21,代碼來源:DataSerializableJUnitTest.java

示例12: testTreeMapObject

import java.io.DataInput; //導入依賴的package包/類
/**
 * Tests data serializing an {@link TreeMap} using {@link DataSerializer#writeObject}.
 */
@Test
public void testTreeMapObject() throws Exception {
  Random random = getRandom();
  TreeMap map = new TreeMap();
  int size = random.nextInt(50);
  for (int i = 0; i < size; i++) {
    Object key = new Long(random.nextLong());
    Object value = String.valueOf(random.nextLong());
    map.put(key, value);
  }

  DataOutputStream out = getDataOutput();
  DataSerializer.writeObject(map, out);
  out.flush();

  DataInput in = getDataInput();
  TreeMap map2 = (TreeMap) DataSerializer.readObject(in);
  assertEquals(map, map2);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:DataSerializableJUnitTest.java

示例13: deserializeFromWritable

import java.io.DataInput; //導入依賴的package包/類
/**
 * Deserialize the file trailer as writable data
 * @param input
 * @throws IOException
 */
void deserializeFromWritable(DataInput input) throws IOException {
  fileInfoOffset = input.readLong();
  loadOnOpenDataOffset = input.readLong();
  dataIndexCount = input.readInt();
  uncompressedDataIndexSize = input.readLong();
  metaIndexCount = input.readInt();

  totalUncompressedBytes = input.readLong();
  entryCount = input.readLong();
  compressionCodec = Compression.Algorithm.values()[input.readInt()];
  numDataIndexLevels = input.readInt();
  firstDataBlockOffset = input.readLong();
  lastDataBlockOffset = input.readLong();
  // TODO this is a classname encoded into an  HFile's trailer. We are going to need to have 
  // some compat code here.
  setComparatorClass(getComparatorClass(Bytes.readStringFixedSize(input,
      MAX_COMPARATOR_NAME_LENGTH)));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:24,代碼來源:FixedFileTrailer.java

示例14: fromData

import java.io.DataInput; //導入依賴的package包/類
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  this.hasKeys = in.readBoolean();
  if (this.hasKeys) {
    this.keys = new ArrayList();
  }
  int numObjects = in.readInt();
  if (numObjects > 0) {
    for (int index = 0; index < numObjects; ++index) {
      if (this.hasKeys) {
        Object key = DataSerializer.readObject(in);
        this.keys.add(key);
      }
      boolean isException = in.readBoolean();
      Object value;
      if (isException) {
        byte[] exBytes = DataSerializer.readByteArray(in);
        value = CacheServerHelper.deserialize(exBytes);
        // ignore the exception string meant for native clients
        DataSerializer.readString(in);
      } else {
        value = DataSerializer.readObject(in);
      }
      this.objects.add(value);
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:27,代碼來源:ObjectPartList.java

示例15: readFields

import java.io.DataInput; //導入依賴的package包/類
@Override public void readFields(DataInput in) throws IOException {
  int size = in.readInt();
  ranges = new MDRange[size];
  for (int i = 0; i < size; i++) {
    int min = in.readInt();
    int max = in.readInt();
    ranges[i] = new MDRange(min, max);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:10,代碼來源:MDRangeFilter.java


注:本文中的java.io.DataInput類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。