java.io.DataInputStream#readInt ( )源码实例Demo

下面列出了java.io.DataInputStream#readInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: flink   文件: Checkpoints.java
public static Savepoint loadCheckpointMetadata(DataInputStream in, ClassLoader classLoader) throws IOException {
	checkNotNull(in, "input stream");
	checkNotNull(classLoader, "classLoader");

	final int magicNumber = in.readInt();

	if (magicNumber == HEADER_MAGIC_NUMBER) {
		final int version = in.readInt();
		final SavepointSerializer<?> serializer = SavepointSerializers.getSerializer(version);

		if (serializer != null) {
			return serializer.deserialize(in, classLoader);
		}
		else {
			throw new IOException("Unrecognized checkpoint version number: " + version);
		}
	}
	else {
		throw new IOException("Unexpected magic number. This can have multiple reasons: " +
				"(1) You are trying to load a Flink 1.0 savepoint, which is not supported by this " +
				"version of Flink. (2) The file you were pointing to is not a savepoint at all. " +
				"(3) The savepoint file has been corrupted.");
	}
}
 
源代码2 项目: zeno   文件: ThreadSafeBitSet.java
/**
 * Deserialize a ThreadSafeBitSet from an InputStream
 */
public static ThreadSafeBitSet deserializeFrom(DataInputStream dis) throws IOException {
    int log2SegmentSize = dis.read();

    int numLongsPerSegment = (1 << (log2SegmentSize - 6));

    int numSegments = dis.readInt();

    ThreadSafeBitSetSegments segments = new ThreadSafeBitSetSegments(numSegments, numLongsPerSegment);

    for(int i=0;i<segments.numSegments();i++) {
        AtomicLongArray arr = segments.getSegment(i);

        for(int j=0;j<numLongsPerSegment;j++) {
            arr.set(j, dis.readLong());
        }
    }

    return new ThreadSafeBitSet(segments, log2SegmentSize);
}
 
源代码3 项目: hbase   文件: FixedFileTrailer.java
/**
 * Deserialize the fixed file trailer from the given stream. The version needs
 * to already be specified. Make sure this is consistent with
 * {@link #serialize(DataOutputStream)}.
 */
void deserialize(DataInputStream inputStream) throws IOException {
  HFile.checkFormatVersion(majorVersion);

  BlockType.TRAILER.readAndCheck(inputStream);

  if (majorVersion > 2
    || (majorVersion == 2 && minorVersion >= HFileReaderImpl.PBUF_TRAILER_MINOR_VERSION)) {
    deserializeFromPB(inputStream);
  } else {
    deserializeFromWritable(inputStream);
  }

  // The last 4 bytes of the file encode the major and minor version universally
  int version = inputStream.readInt();
  expectMajorVersion(extractMajorVersion(version));
  expectMinorVersion(extractMinorVersion(version));
}
 
源代码4 项目: Alite   文件: LocalScreen.java
public static boolean initialize(Alite alite, final DataInputStream dis) {
	LocalScreen ls = new LocalScreen(alite);
	try {
		ls.zoomFactor = dis.readFloat();
		ls.centerX = dis.readInt();
		ls.centerY = dis.readInt();
		ls.pendingZoomFactor = ls.zoomFactor;
		ls.pendingCenterX    = ls.centerX;
		ls.pendingCenterY    = ls.centerY;
	} catch (Exception e) {
		AliteLog.e("Local Screen Initialize", "Error in initializer.", e);
		return false;
	}
	alite.setScreen(ls);
	return true;
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: BinaryAttribute.java
/**
 * Load a list of attributes
 */
public static BinaryAttribute load(DataInputStream in, BinaryConstantPool cpool, int mask) throws IOException {
    BinaryAttribute atts = null;
    int natt = in.readUnsignedShort();  // JVM 4.6 method_info.attrutes_count

    for (int i = 0 ; i < natt ; i++) {
        // id from JVM 4.7 attribute_info.attribute_name_index
        Identifier id = cpool.getIdentifier(in.readUnsignedShort());
        // id from JVM 4.7 attribute_info.attribute_length
        int len = in.readInt();

        if (id.equals(idCode) && ((mask & ATT_CODE) == 0)) {
            in.skipBytes(len);
        } else {
            byte data[] = new byte[len];
            in.readFully(data);
            atts = new BinaryAttribute(id, data, atts);
        }
    }
    return atts;
}
 
源代码6 项目: attic-apex-malhar   文件: FunctionOperator.java
@SuppressWarnings("unchecked")
private void readFunction()
{
  try {
    if (statelessF != null || statefulF.getValue() != null) {
      return;
    }
    DataInputStream input = new DataInputStream(new ByteArrayInputStream(annonymousFunctionClass));
    byte[] classNameBytes = new byte[input.readInt()];
    input.read(classNameBytes);
    String className = new String(classNameBytes);
    byte[] classData = new byte[input.readInt()];
    input.read(classData);
    Map<String, byte[]> classBin = new HashMap<>();
    classBin.put(className, classData);
    ByteArrayClassLoader byteArrayClassLoader = new ByteArrayClassLoader(classBin, Thread.currentThread().getContextClassLoader());
    statelessF = ((Class<FUNCTION>)byteArrayClassLoader.findClass(className)).newInstance();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
源代码7 项目: gemfirexd-oss   文件: CompiledCode.java
CompiledCode( byte[] code_block ) throws IOException {
    int idx;
    
    ByteArrayInputStream bis = new ByteArrayInputStream(code_block);
    DataInputStream source = new DataInputStream(bis);

    max_stack = source.readUnsignedShort();
    max_locals = source.readUnsignedShort();
    code_length = source.readInt();
    code = new byte[code_length];
    source.read(code);
    exception_table_length = source.readUnsignedShort();
    exceptionTable = new ExceptionTableEntry[exception_table_length];
    for (int i=0; i<exception_table_length; i++) {
      exceptionTable[i] = new ExceptionTableEntry(source);
    }
    attributes_count = source.readUnsignedShort();
    attributes_info = new CompiledAttribute[attributes_count];
    for (idx=0; idx<attributes_count; idx++) {
        attributes_info[idx] = new CompiledAttribute(source);
    }
}
 
源代码8 项目: gemfirexd-oss   文件: Util.java
public static byte[] readByteBuffer(DataInputStream in) throws IOException {
    int b=in.read();
    if(b == 1) {
        b=in.readInt();
        byte[] buf=new byte[b];
        if (buf.length != in.read(buf, 0, buf.length)) {
          throw new IOException("Failed to read " + buf.length + "bytes"); // GemStoneAddition
        }
        return buf;
    }
    return null;
}
 
源代码9 项目: GNSS_Compare   文件: IonoGalileo.java
@Override
public void read(DataInputStream dai, boolean oldVersion) throws IOException {
	int v=1;
	if(!oldVersion) v=dai.readInt();

	if(v==1){

		health = dai.readLong();
		utcA1 = dai.readDouble();
		utcA0 = dai.readDouble();
		utcTOW = dai.readLong();
		utcWNT = dai.readInt();
		utcLS = dai.readInt();
		utcWNF = dai.readInt();
		utcDN = dai.readInt();
		utcLSF = dai.readInt();
		for(int i=0;i<alpha.length;i++){
			alpha[i] = dai.readFloat();
		}
		for(int i=0;i<beta.length;i++){
			beta[i] = dai.readFloat();
		}
		validHealth = dai.readBoolean();
		validUTC = dai.readBoolean();
		validKlobuchar = dai.readBoolean();
		long l = dai.readLong();
		refTime = new Time(l>0?l:System.currentTimeMillis());
	}else{
		throw new IOException("Unknown format version:"+v);
	}
}
 
源代码10 项目: T0rlib4j   文件: Utilities.java
public static Socket socks4aSocketConnection(String networkHost, int networkPort, String socksHost, int socksPort)
        throws IOException {

    Socket socket = new Socket();
    socket.setSoTimeout(READ_TIMEOUT_MILLISECONDS);
    SocketAddress socksAddress = new InetSocketAddress(socksHost, socksPort);
    socket.connect(socksAddress, CONNECT_TIMEOUT_MILLISECONDS);

    DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
    outputStream.write((byte) 0x04);
    outputStream.write((byte) 0x01);
    outputStream.writeShort((short) networkPort);
    outputStream.writeInt(0x01);
    outputStream.write((byte) 0x00);
    outputStream.write(networkHost.getBytes());
    outputStream.write((byte) 0x00);

    DataInputStream inputStream = new DataInputStream(socket.getInputStream());
    byte firstByte = inputStream.readByte();
    byte secondByte = inputStream.readByte();
    if (firstByte != (byte) 0x00 || secondByte != (byte) 0x5a) {
        socket.close();
        throw new IOException("SOCKS4a connect failed, got " + firstByte + " - " + secondByte +
                ", but expected 0x00 - 0x5a");
    }
    inputStream.readShort();
    inputStream.readInt();
    return socket;
}
 
源代码11 项目: reef   文件: StringDeserializer.java
@Override
public Iterable<String> create(final InputStream arg) {
  final DataInputStream dis = new DataInputStream(arg);
  return new Iterable<String>() {

    @Override
    public Iterator<String> iterator() {
      return new Iterator<String>() {

        @Override
        public void remove() {
          throw new UnsupportedOperationException();
        }

        @Override
        public String next() {
          int len = 0;
          try {
            len = dis.readInt();
            final byte[] b = new byte[len];
            dis.readFully(b);
            return new String(b, StandardCharsets.UTF_8);
          } catch (final IOException e) {
            throw new ServiceRuntimeException(e);
          }
        }

        @Override
        public boolean hasNext() {
          throw new UnsupportedOperationException();
        }
      };
    }
  };
}
 
NFCompressedGraphPointers deserializePointers(DataInputStream dis) throws IOException {
    int numTypes = dis.readInt();

    /// Backwards compatibility:  The representation of the pointers is encoded as
    /// In order to maintain backwards compatibility of produced artifacts,
    /// if more than 32 bits is required to represent the pointers, then flag
    /// the sign bit in the serialized number of node types.
    if((numTypes & Integer.MIN_VALUE) != 0) {
        numTypes &= Integer.MAX_VALUE;
        return deserializeLongPointers(dis, numTypes & Integer.MAX_VALUE);
    }

    return deserializeIntPointers(dis, numTypes);
}
 
源代码13 项目: reladomo   文件: BinaryCompressor.java
private String readString(DataInputStream dataIn) throws IOException
{
    int len = dataIn.readInt();
    byte[] bytes = new byte[len];
    dataIn.readFully(bytes);
    return new String(bytes, Charset.forName("UTF-8"));
}
 
public void readWire(final DataInputStream in) throws IOException, ClassNotFoundException {

      super.readWire(in);

      subscriberIdentity = in.readInt();

      final int eventListSize = in.readInt();
      events = new ArrayList<BinaryEntryModifiedEvent>(eventListSize);
      for (int i = 0; i < eventListSize; i++) {

         final BinaryEntryModifiedEvent event = new BinaryEntryModifiedEvent();
         event.readWire(in);
         events.add(event);
      }
   }
 
源代码15 项目: hop   文件: ValueMetaBaseSerializationTest.java
private static void checkRestoring( ValueMetaBase initial ) throws Exception {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  initial.writeMeta( new DataOutputStream( os ) );

  DataInputStream dataInputStream = new DataInputStream( new ByteArrayInputStream( os.toByteArray() ) );
  // an awkward hack, since readMetaData() expects object's type to have been read
  int restoredType = dataInputStream.readInt();
  assertEquals( "type", initial.getType(), restoredType );

  ValueMetaBase restored = new ValueMetaBase( initial.getName(), restoredType );
  restored.readMetaData( dataInputStream );

  assertMetaDataAreEqual( initial, restored );
}
 
源代码16 项目: JWebAssembly   文件: ClassFile.java
/**
 * Load a class file and create a model of the class.
 *
 * @param stream
 *            The InputStream of the class file. Will be closed if finish.
 * @throws IOException
 *             if this input stream reaches the end before reading the class file.
 */
public ClassFile( InputStream stream ) throws IOException {
    DataInputStream input = new DataInputStream( stream );
    int magic = input.readInt();
    if( magic != 0xCAFEBABE ) {
        throw new IOException( "Invalid class magic: " + Integer.toHexString( magic ) );
    }
    minorVersion = input.readUnsignedShort();
    majorVersion = input.readUnsignedShort();

    constantPool = new ConstantPool( input );
    accessFlags = input.readUnsignedShort();
    thisClass = (ConstantClass)constantPool.get( input.readUnsignedShort() );
    superClass = (ConstantClass)constantPool.get( input.readUnsignedShort() );
    interfaces = new ConstantClass[input.readUnsignedShort()];
    for( int i = 0; i < interfaces.length; i++ ) {
        interfaces[i] = (ConstantClass)constantPool.get( input.readUnsignedShort() );
    }
    fields = readFields( input );
    methods = readMethods( input );
    attributes = new Attributes( input, constantPool );

    stream.close();

    AttributeInfo info = attributes.get( "Signature" );
    if( info != null ) {
        int idx = info.getDataInputStream().readShort();
        String signature = (String)constantPool.get( idx );
        int count = 0;
        for( int i = 0; i < signature.length(); i++ ) {
            char ch = signature.charAt( i );
            switch( ch ) {
                case '<':
                    count++;
                    continue;
                case '>':
                    count--;
                    continue;
            }
            if( count == 0 ) {
                thisSignature = signature.substring( 0, i );
                superSignature = signature.substring( i );
                break;
            }
        }
    }
}
 
源代码17 项目: hadoop   文件: FSEditLogOp.java
@Override
void readFields(DataInputStream in, int logVersion)
    throws IOException {
  if (!NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
    this.length = in.readInt();
  }
  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.ADD_INODE_ID, logVersion)) {
    this.inodeId = in.readLong();
  } else {
    // The inodeId should be updated when this editLogOp is applied
    this.inodeId = INodeId.GRANDFATHER_INODE_ID;
  }
  if ((-17 < logVersion && length != 4) ||
      (logVersion <= -17 && length != 5 && !NameNodeLayoutVersion.supports(
          LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion))) {
    throw new IOException("Incorrect data format."  +
                          " logVersion is " + logVersion +
                          " but writables.length is " +
                          length + ". ");
  }
  this.path = FSImageSerialization.readString(in);

  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
    this.replication = FSImageSerialization.readShort(in);
    this.mtime = FSImageSerialization.readLong(in);
  } else {
    this.replication = readShort(in);
    this.mtime = readLong(in);
  }

  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.FILE_ACCESS_TIME, logVersion)) {
    if (NameNodeLayoutVersion.supports(
        LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
      this.atime = FSImageSerialization.readLong(in);
    } else {
      this.atime = readLong(in);
    }
  } else {
    this.atime = 0;
  }

  if (NameNodeLayoutVersion.supports(
      LayoutVersion.Feature.EDITLOG_OP_OPTIMIZATION, logVersion)) {
    this.blockSize = FSImageSerialization.readLong(in);
  } else {
    this.blockSize = readLong(in);
  }

  this.blocks = readBlocks(in, logVersion);
  this.permissions = PermissionStatus.read(in);

  if (this.opCode == OP_ADD) {
    aclEntries = AclEditLogUtil.read(in, logVersion);
    this.xAttrs = readXAttrsFromEditLog(in, logVersion);
    this.clientName = FSImageSerialization.readString(in);
    this.clientMachine = FSImageSerialization.readString(in);
    if (NameNodeLayoutVersion.supports(
        NameNodeLayoutVersion.Feature.CREATE_OVERWRITE, logVersion)) {
      this.overwrite = FSImageSerialization.readBoolean(in);
    } else {
      this.overwrite = false;
    }
    if (NameNodeLayoutVersion.supports(
        NameNodeLayoutVersion.Feature.BLOCK_STORAGE_POLICY, logVersion)) {
      this.storagePolicyId = FSImageSerialization.readByte(in);
    } else {
      this.storagePolicyId = BlockStoragePolicySuite.ID_UNSPECIFIED;
    }
    // read clientId and callId
    readRpcIds(in, logVersion);
  } else {
    this.clientName = "";
    this.clientMachine = "";
  }
}
 
源代码18 项目: ambry   文件: MessageInfoAndMetadataListSerde.java
/**
 * Deserialize the given stream and return the MessageInfo and Metadata lists.
 * @param stream the stream to deserialize from.
 * @param map the clustermap to use.
 * @param versionToDeserializeIn the SerDe version to use to deserialize.
 * @return the deserialized {@link MessageInfoAndMetadataListSerde}.
 * @throws IOException if an I/O error occurs while reading from the stream.
 */
static MessageInfoAndMetadataListSerde deserializeMessageInfoAndMetadataList(DataInputStream stream, ClusterMap map,
    short versionToDeserializeIn) throws IOException {
  if (versionToDeserializeIn >= VERSION_5) {
    short versionFromStream = stream.readShort();
    if (versionFromStream != versionToDeserializeIn) {
      throw new IllegalArgumentException(
          "Argument provided [" + versionToDeserializeIn + "] and stream [" + versionFromStream
              + "] disagree on version");
    }
  } else {
    versionToDeserializeIn =
        versionToDeserializeIn == DETERMINE_VERSION ? stream.readShort() : versionToDeserializeIn;
  }
  int messageCount = stream.readInt();
  ArrayList<MessageInfo> messageInfoList = new ArrayList<>(messageCount);
  ArrayList<MessageMetadata> messageMetadataList = new ArrayList<>(messageCount);
  for (int i = 0; i < messageCount; i++) {
    BlobId id = new BlobId(stream, map);
    long size = stream.readLong();
    long ttl = stream.readLong();
    boolean isDeleted = stream.readByte() == UPDATED;
    boolean isTtlUpdated = false;
    boolean isUndeleted = false;
    short lifeVersion = 0;
    Long crc = null;
    short accountId = Account.UNKNOWN_ACCOUNT_ID;
    short containerId = Container.UNKNOWN_CONTAINER_ID;
    long operationTime = Utils.Infinite_Time;
    if (versionToDeserializeIn < VERSION_1 || versionToDeserializeIn > VERSION_MAX) {
      throw new IllegalArgumentException("Unknown version to deserialize MessageInfoList " + versionToDeserializeIn);
    }
    if (versionToDeserializeIn >= VERSION_5) {
      isTtlUpdated = stream.readByte() == UPDATED;
    }
    if (versionToDeserializeIn >= VERSION_6) {
      isUndeleted = stream.readByte() == UPDATED;
    }
    if (versionToDeserializeIn > VERSION_1) {
      crc = stream.readByte() == FIELD_PRESENT ? stream.readLong() : null;
    }
    if (versionToDeserializeIn > VERSION_2) {
      accountId = stream.readShort();
      containerId = stream.readShort();
      operationTime = stream.readLong();
    }
    if (versionToDeserializeIn >= VERSION_6) {
      lifeVersion = stream.readShort();
    }

    messageInfoList.add(
        new MessageInfo(id, size, isDeleted, isTtlUpdated, isUndeleted, ttl, crc, accountId, containerId,
            operationTime, lifeVersion));

    if (versionToDeserializeIn > VERSION_3) {
      MessageMetadata messageMetadata =
          stream.readByte() == FIELD_PRESENT ? MessageMetadata.deserializeMessageMetadata(stream) : null;
      messageMetadataList.add(messageMetadata);
    } else {
      messageMetadataList.add(null);
    }
  }
  return new MessageInfoAndMetadataListSerde(messageInfoList, messageMetadataList, versionToDeserializeIn);
}
 
源代码19 项目: amidst   文件: RealClassBuilder.java
private RealClassConstant<Integer> readInteger(DataInputStream stream, byte type) throws IOException {
	int value = stream.readInt();
	return new RealClassConstant<>(type, value);
}
 
源代码20 项目: nifi   文件: StandardFlowFileCodec.java
private String readString(final DataInputStream in) throws IOException {
    final int numBytes = in.readInt();
    final byte[] bytes = new byte[numBytes];
    StreamUtils.fillBuffer(in, bytes, true);
    return new String(bytes, "UTF-8");
}