java.io.DataInputStream.readInt()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(385)

本文整理了Java中java.io.DataInputStream.readInt()方法的一些代码示例,展示了DataInputStream.readInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.readInt()方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:readInt

DataInputStream.readInt介绍

[英]See the general contract of the readInt method of DataInput.

Bytes for this operation are read from the contained input stream.
[中]参见readInt方法DataInput的总合同。
此操作的字节从包含的输入流中读取。

代码示例

代码示例来源:origin: redisson/redisson

protected AttributeInfo(ConstPool cp, int n, DataInputStream in)
  throws IOException
{
  constPool = cp;
  name = n;
  int len = in.readInt();
  info = new byte[len];
  if (len > 0)
    in.readFully(info);
}

代码示例来源:origin: stackoverflow.com

import java.io.DataInputStream;
DataInputStream dis = new DataInputStream(System.in);
int i = dis.readInt();

代码示例来源:origin: stanfordnlp/CoreNLP

protected void read(DataInputStream inf) throws IOException {
 num = inf.readInt();
 // mg2008: slight speedup:
 val = inf.readUTF();
 // intern the tag strings as they are read, since there are few of them. This saves tons of memory.
 tag = inf.readUTF();
 hashCode = 0;
}

代码示例来源:origin: google/j2objc

private boolean checkMagic(File file, long magic) throws IOException {
  DataInputStream in = new DataInputStream(new FileInputStream(file));
  try {
    int m = in.readInt();
    return magic == m; 
  } finally {
    in.close();
  }
}

代码示例来源:origin: stackoverflow.com

byte[] test = new byte[] {0, 0, 1, 0, 0, 0, 1, 1, 8, 9};
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(test));
int value0 = stream.readInt();
int value1 = stream.readInt();
byte value2 = stream.readByte();
byte value3 = stream.readByte();
stream.close();
System.out.println(value0 + " " + value1 + " " + value2 + " " + value3);

代码示例来源:origin: addthis/stream-lib

public static int[] getBits(byte[] mBytes) throws IOException {
  int bitSize = mBytes.length / 4;
  int[] bits = new int[bitSize];
  DataInputStream dis = new DataInputStream(new ByteArrayInputStream(mBytes));
  for (int i = 0; i < bitSize; i++) {
    bits[i] = dis.readInt();
  }
  return bits;
}

代码示例来源:origin: stackoverflow.com

File file = new File("C:/text.bin");
DataInputStream stream = new DataInputStream(new FileInputStream(file));
boolean isTrue = stream.readBoolean();
int value = stream.readInt();
stream.close();
System.out.printlin(isTrue + " " + value);

代码示例来源:origin: apache/hive

try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(decoded))) {
 String databaseName = in.readUTF();
 String tableName = in.readUTF();
 boolean createPartitions = in.readBoolean();
 long writeId = in.readLong();
 TableType tableType = TableType.valueOf(in.readByte());
 int thriftLength = in.readInt();
  try {
   byte[] thriftEncoded = new byte[thriftLength];
   in.readFully(thriftEncoded, 0, thriftLength);
   new TDeserializer(new TCompactProtocol.Factory()).deserialize(metaTable, thriftEncoded);
   table.setTable(metaTable);

代码示例来源:origin: wildfly/wildfly

public void readState(InputStream instream) throws IOException {
  DataInputStream in=new DataInputStream(new BufferedInputStream(instream));
  Map<Point,Color> new_state=new LinkedHashMap<>();
  int num=in.readInt();
  for(int i=0; i < num; i++) {
    Point point=new Point(in.readInt(), in.readInt());
    Color col=new Color(in.readInt());
    new_state.put(point, col);
  }
  synchronized(state) {
    state.clear();
    state.putAll(new_state);
    System.out.println("read " + state.size() + " elements");
    createOffscreenImage(true);
  }
}

代码示例来源:origin: pmd/pmd

if (cacheExists()) {
  try (
    DataInputStream inputStream = new DataInputStream(
      new BufferedInputStream(Files.newInputStream(cacheFile.toPath())));
  ) {
    final String cacheVersion = inputStream.readUTF();
      rulesetChecksum = inputStream.readLong();
      auxClassPathChecksum = inputStream.readLong();
      executionClassPathChecksum = inputStream.readLong();
        final String fileName = inputStream.readUTF();
        final long checksum = inputStream.readLong();
        final int countViolations = inputStream.readInt();
        final List<RuleViolation> violations = new ArrayList<>(countViolations);
        for (int i = 0; i < countViolations; i++) {

代码示例来源:origin: apache/incubator-druid

/**
 * Deserialize a bloom filter
 * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)}
 * into a {@code BloomKFilter}
 *
 * @param in input bytestream
 *
 * @return deserialized BloomKFilter
 */
public static BloomKFilter deserialize(InputStream in) throws IOException
{
 if (in == null) {
  throw new IOException("Input stream is null");
 }
 try {
  DataInputStream dataInputStream = new DataInputStream(in);
  int numHashFunc = dataInputStream.readByte();
  int bitsetArrayLen = dataInputStream.readInt();
  long[] data = new long[bitsetArrayLen];
  for (int i = 0; i < bitsetArrayLen; i++) {
   data[i] = dataInputStream.readLong();
  }
  return new BloomKFilter(data, numHashFunc);
 }
 catch (RuntimeException e) {
  IOException io = new IOException("Unable to deserialize BloomKFilter");
  io.initCause(e);
  throw io;
 }
}

代码示例来源:origin: uber/NullAway

if (in.readInt() != VERSION_0_FILE_MAGIC_NUMBER) {
 throw new Error("Invalid file version/magic number for stubx file!" + stubxLocation);
int numStrings = in.readInt();
int numPackages = in.readInt();
 in.readInt(); // String packageName = strings[in.readInt()];
 in.readInt(); // String annotation = strings[in.readInt()];
int numTypes = in.readInt();
 in.readInt(); // String typeName = strings[in.readInt()];
 in.readInt(); // String annotation = strings[in.readInt()];
int numMethods = in.readInt();
 String methodSig = strings[in.readInt()];
 String annotation = strings[in.readInt()];
 LOG(DEBUG, "DEBUG", "method: " + methodSig + ", return annotation: " + annotation);
 cacheAnnotation(methodSig, RETURN, annotation);
int numArgumentRecords = in.readInt();
 String methodSig = strings[in.readInt()];
 if (methodSig.lastIndexOf(':') == -1 || methodSig.split(":")[0].lastIndexOf('.') == -1) {
  throw new Error(
    "Invalid method signature " + methodSig + " in stubx file " + stubxLocation);

代码示例来源:origin: kilim/kilim

/** get the major version of klass by loading the bytecode from source */
public static int getVersion(ClassLoader source,Class klass) {
  String cname = WeavingClassLoader.makeResourceName(klass.getName());
  DataInputStream in = new DataInputStream(source.getResourceAsStream(cname));
  try {
    int magic = in.readInt();
    int minor = in.readUnsignedShort();
    int major = in.readUnsignedShort();
    in.close();
    return major;
  }
  catch (IOException ex) { throw new RuntimeException(ex); }
}

代码示例来源:origin: apache/geode

private void readHeaderToken() throws IOException {
 byte archiveVersion = dataIn.readByte();
 if (archiveVersion <= 1) {
  throw new GemFireIOException(
    String.format("Archive version: %s is no longer supported.",
      new Byte(archiveVersion)),
    null);
 }
 if (archiveVersion > ARCHIVE_VERSION) {
  throw new GemFireIOException(
    String.format("Unsupported archive version: %s .  The supported version is: %s .",
      new Object[] {new Byte(archiveVersion), new Byte(ARCHIVE_VERSION)}),
    null);
 }
 this.archiveVersion = archiveVersion;
 this.startTimeStamp = dataIn.readLong();
 this.systemId = dataIn.readLong();
 this.systemStartTimeStamp = dataIn.readLong();
 this.timeZoneOffset = dataIn.readInt();
 this.timeZoneName = dataIn.readUTF();
 this.systemDirectory = dataIn.readUTF();
 this.productVersion = dataIn.readUTF();
 this.os = dataIn.readUTF();
 this.machine = dataIn.readUTF();
}

代码示例来源:origin: redisson/redisson

public static SnappyCodec readHeader(InputStream in)
      throws IOException
  {
    DataInputStream d = new DataInputStream(in);
    byte[] magic = new byte[MAGIC_LEN];
    d.readFully(magic, 0, MAGIC_LEN);
    int version = d.readInt();
    int compatibleVersion = d.readInt();
    return new SnappyCodec(magic, version, compatibleVersion);
  }
}

代码示例来源:origin: apache/flink

@Override
public Schema readSchema(InputStream in) throws IOException {
  DataInputStream dataInputStream = new DataInputStream(in);
  if (dataInputStream.readByte() != 0) {
    throw new IOException("Unknown data format. Magic number does not match");
  } else {
    int schemaId = dataInputStream.readInt();
    try {
      return schemaRegistryClient.getById(schemaId);
    } catch (RestClientException e) {
      throw new IOException(format("Could not find schema with id %s in registry", schemaId), e);
    }
  }
}

代码示例来源:origin: apache/nifi

@Override
protected boolean listen(final InputStream in, final OutputStream out, final int version) throws IOException {
  final DataInputStream dis = new DataInputStream(in);
  final DataOutputStream dos = new DataOutputStream(out);
  final String action = dis.readUTF();
  if (action.equals("close")) {
    return false;
  }
  final int valueLength = dis.readInt();
  final byte[] value = new byte[valueLength];
  dis.readFully(value);
  final ByteBuffer valueBuffer = ByteBuffer.wrap(value);
  final SetCacheResult response;
  switch (action) {
    case "addIfAbsent":
      response = cache.addIfAbsent(valueBuffer);
      break;
    case "contains":
      response = cache.contains(valueBuffer);
      break;
    case "remove":
      response = cache.remove(valueBuffer);
      break;
    default:
      throw new IOException("IllegalRequest");
  }
  dos.writeBoolean(response.getResult());
  dos.flush();
  return true;
}

代码示例来源:origin: apache/nifi

private SnapshotHeader validateHeader(final DataInputStream dataIn) throws IOException {
  final String snapshotClass = dataIn.readUTF();
  logger.debug("Snapshot Class Name for {} is {}", storageDirectory, snapshotClass);
  if (!snapshotClass.equals(HashMapSnapshot.class.getName())) {
    throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using the "
      + snapshotClass + " class; cannot restore using " + getClass().getName());
  }
  final int snapshotVersion = dataIn.readInt();
  logger.debug("Snapshot version for {} is {}", storageDirectory, snapshotVersion);
  if (snapshotVersion > getVersion()) {
    throw new IOException("Write-Ahead Log Snapshot located at " + storageDirectory + " was written using version "
      + snapshotVersion + " of the " + snapshotClass + " class; cannot restore using Version " + getVersion());
  }
  final String serdeEncoding = dataIn.readUTF(); // ignore serde class name for now
  logger.debug("Serde encoding for Snapshot at {} is {}", storageDirectory, serdeEncoding);
  final int serdeVersion = dataIn.readInt();
  logger.debug("Serde version for Snapshot at {} is {}", storageDirectory, serdeVersion);
  final long maxTransactionId = dataIn.readLong();
  logger.debug("Max Transaction ID for Snapshot at {} is {}", storageDirectory, maxTransactionId);
  final int numRecords = dataIn.readInt();
  logger.debug("Number of Records for Snapshot at {} is {}", storageDirectory, numRecords);
  final SerDe<T> serde = serdeFactory.createSerDe(serdeEncoding);
  serde.readHeader(dataIn);
  return new SnapshotHeader(serde, serdeVersion, maxTransactionId, numRecords);
}

代码示例来源:origin: org.apache.commons/commons-compress

private StartHeader readStartHeader(final long startHeaderCrc) throws IOException {
  final StartHeader startHeader = new StartHeader();
  // using Stream rather than ByteBuffer for the benefit of the
  // built-in CRC check
  try (DataInputStream dataInputStream = new DataInputStream(new CRC32VerifyingInputStream(
      new BoundedSeekableByteChannelInputStream(channel, 20), 20, startHeaderCrc))) {
     startHeader.nextHeaderOffset = Long.reverseBytes(dataInputStream.readLong());
     startHeader.nextHeaderSize = Long.reverseBytes(dataInputStream.readLong());
     startHeader.nextHeaderCrc = 0xffffFFFFL & Integer.reverseBytes(dataInputStream.readInt());
     return startHeader;
  }
}

代码示例来源:origin: google/ExoPlayer

@Override
 public ProgressiveDownloadAction readFromStream(int version, DataInputStream input)
   throws IOException {
  Uri uri = Uri.parse(input.readUTF());
  boolean isRemoveAction = input.readBoolean();
  int dataLength = input.readInt();
  byte[] data = new byte[dataLength];
  input.readFully(data);
  String customCacheKey = input.readBoolean() ? input.readUTF() : null;
  return new ProgressiveDownloadAction(uri, isRemoveAction, data, customCacheKey);
 }
};

相关文章