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

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

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

DataInputStream.readUnsignedShort介绍

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

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

代码示例

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

private void readTimeDelta() throws IOException {
 int millisSinceLastSample = dataIn.readUnsignedShort();
 if (millisSinceLastSample == INT_TIMESTAMP_TOKEN) {
  millisSinceLastSample = dataIn.readInt();
 }
 this.currentDuration += millisSinceLastSample;
 this.startTimeStamp += millisSinceLastSample;
}

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

private int readTimeDelta() throws IOException {
 int result = dataIn.readUnsignedShort();
 if (result == INT_TIMESTAMP_TOKEN) {
  result = dataIn.readInt();
 }
 return result;
}

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

private int readResourceInstId() throws IOException {
 int token = dataIn.readUnsignedByte();
 if (token <= MAX_BYTE_RESOURCE_INST_ID) {
  return token;
 } else if (token == ILLEGAL_RESOURCE_INST_ID_TOKEN) {
  return ILLEGAL_RESOURCE_INST_ID;
 } else if (token == SHORT_RESOURCE_INST_ID_TOKEN) {
  return dataIn.readUnsignedShort();
 } else { /* token == INT_RESOURCE_INST_ID_TOKEN */
  return dataIn.readInt();
 }
}

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

CompiledAttribute(DataInputStream source) throws IOException {
 int idx;
 attribute_name_index = source.readUnsignedShort();
 attribute_length = source.readInt();
 info = new byte[(int) attribute_length];
 for (idx = 0; idx < attribute_length; idx++) {
  info[idx] = (byte) source.readUnsignedByte();
 }
}

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

private int readResourceInstId() throws IOException {
 int token = dataIn.readUnsignedByte();
 if (token <= MAX_BYTE_RESOURCE_INST_ID) {
  return token;
 } else if (token == ILLEGAL_RESOURCE_INST_ID_TOKEN) {
  return ILLEGAL_RESOURCE_INST_ID;
 } else if (token == SHORT_RESOURCE_INST_ID_TOKEN) {
  return dataIn.readUnsignedShort();
 } else { /* token == INT_RESOURCE_INST_ID_TOKEN */
  return dataIn.readInt();
 }
}

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

CodeAttribute(ConstPool cp, int name_id, DataInputStream in)
  throws IOException
{
  super(cp, name_id, (byte[])null);
  int attr_len = in.readInt();
  maxStack = in.readUnsignedShort();
  maxLocals = in.readUnsignedShort();
  int code_len = in.readInt();
  info = new byte[code_len];
  in.readFully(info);
  exceptions = new ExceptionTable(cp, in);
  attributes = new ArrayList();
  int num = in.readUnsignedShort();
  for (int i = 0; i < num; ++i)
    attributes.add(AttributeInfo.read(cp, in));
}

代码示例来源: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: org.javassist/javassist

CodeAttribute(ConstPool cp, int name_id, DataInputStream in)
  throws IOException
{
  super(cp, name_id, (byte[])null);
  @SuppressWarnings("unused")
  int attr_len = in.readInt();
  maxStack = in.readUnsignedShort();
  maxLocals = in.readUnsignedShort();
  int code_len = in.readInt();
  info = new byte[code_len];
  in.readFully(info);
  exceptions = new ExceptionTable(cp, in);
  attributes = new ArrayList<AttributeInfo>();
  int num = in.readUnsignedShort();
  for (int i = 0; i < num; ++i)
    attributes.add(AttributeInfo.read(cp, in));
}

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

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);
 }
}

代码示例来源:origin: scouter-project/scouter

CodeAttribute(ConstPool cp, int name_id, DataInputStream in)
  throws IOException
{
  super(cp, name_id, (byte[])null);
  int attr_len = in.readInt();
  maxStack = in.readUnsignedShort();
  maxLocals = in.readUnsignedShort();
  int code_len = in.readInt();
  info = new byte[code_len];
  in.readFully(info);
  exceptions = new ExceptionTable(cp, in);
  attributes = new ArrayList();
  int num = in.readUnsignedShort();
  for (int i = 0; i < num; ++i)
    attributes.add(AttributeInfo.read(cp, in));
}

代码示例来源:origin: scouter-project/scouter

CodeAttribute(ConstPool cp, int name_id, DataInputStream in)
  throws IOException
{
  super(cp, name_id, (byte[])null);
  @SuppressWarnings("unused")
  int attr_len = in.readInt();
  maxStack = in.readUnsignedShort();
  maxLocals = in.readUnsignedShort();
  int code_len = in.readInt();
  info = new byte[code_len];
  in.readFully(info);
  exceptions = new ExceptionTable(cp, in);
  attributes = new ArrayList<AttributeInfo>();
  int num = in.readUnsignedShort();
  for (int i = 0; i < num; ++i)
    attributes.add(AttributeInfo.read(cp, in));
}

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

import java.io.*;
public class ClassVersionChecker {
public static void main(String[] args) throws IOException {
  for (int i = 0; i < args.length; i++)
    checkClassVersion(args[i]);
}

  private static void checkClassVersion(String filename)
    throws IOException
  {
    DataInputStream in = new DataInputStream
     (new FileInputStream(filename));

    int magic = in.readInt();
    if(magic != 0xcafebabe) {
     System.out.println(filename + " is not a valid class!");;
    }
    int minor = in.readUnsignedShort();
    int major = in.readUnsignedShort();
    System.out.println(filename + ": " + major + " . " + minor);
    in.close();
  }
}

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

minor = in.readUnsignedShort();
major = in.readUnsignedShort();
constPool = new ConstPool(in);
accessFlags = in.readUnsignedShort();
thisClass = in.readUnsignedShort();
constPool.setThisClassInfo(thisClass);
superClass = in.readUnsignedShort();
n = in.readUnsignedShort();
if (n == 0)
  interfaces = null;
  interfaces = new int[n];
  for (i = 0; i < n; ++i)
    interfaces[i] = in.readUnsignedShort();
n = in.readUnsignedShort();
fields = new ArrayList();
for (i = 0; i < n; ++i)
  addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
methods = new ArrayList();
for (i = 0; i < n; ++i)
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
  addAttribute(AttributeInfo.read(cp, in));

代码示例来源:origin: org.apache.ant/ant

/**
 * Get the class name of a class in an input stream.
 *
 * @param input an <code>InputStream</code> value
 * @return the name of the class
 * @exception IOException if an error occurs
 */
public static String getClassName(InputStream input) throws IOException {
  DataInputStream data = new DataInputStream(input);
  // verify this is a valid class file.
  int cookie = data.readInt();
  if (cookie != CLASS_MAGIC_NUMBER) {
    return null;
  }
  /* int version = */ data.readInt();
  // read the constant pool.
  ConstantPool constants = new ConstantPool(data);
  Object[] values = constants.values;
  // read access flags and class index.
  /* int accessFlags = */ data.readUnsignedShort();
  int classIndex = data.readUnsignedShort();
  Integer stringIndex = (Integer) values[classIndex];
  return (String) values[stringIndex];
}

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

int idx;
magic = (long) source.readInt();
minor_version = source.readUnsignedShort();
major_version = source.readUnsignedShort();
constant_pool_count = source.readUnsignedShort();
  idx++;
access_flags = source.readUnsignedShort();
this_class = source.readUnsignedShort();
super_class = source.readUnsignedShort();
interfaces_count = source.readUnsignedShort();
 interfaces[idx] = source.readUnsignedShort();
fields_count = source.readUnsignedShort();
 fields[idx] = new CompiledField(source, this);
methods_count = source.readUnsignedShort();
 methods[idx] = new CompiledMethod(source, this);
attributes_count = source.readUnsignedShort();

代码示例来源:origin: org.javassist/javassist

minor = in.readUnsignedShort();
major = in.readUnsignedShort();
constPool = new ConstPool(in);
accessFlags = in.readUnsignedShort();
thisClass = in.readUnsignedShort();
constPool.setThisClassInfo(thisClass);
superClass = in.readUnsignedShort();
n = in.readUnsignedShort();
if (n == 0)
  interfaces = null;
  interfaces = new int[n];
  for (i = 0; i < n; ++i)
    interfaces[i] = in.readUnsignedShort();
n = in.readUnsignedShort();
fields = new ArrayList<FieldInfo>();
for (i = 0; i < n; ++i)
  addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
methods = new ArrayList<MethodInfo>();
for (i = 0; i < n; ++i)
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
  addAttribute(AttributeInfo.read(cp, in));

代码示例来源:origin: scouter-project/scouter

minor = in.readUnsignedShort();
major = in.readUnsignedShort();
constPool = new ConstPool(in);
accessFlags = in.readUnsignedShort();
thisClass = in.readUnsignedShort();
constPool.setThisClassInfo(thisClass);
superClass = in.readUnsignedShort();
n = in.readUnsignedShort();
if (n == 0)
  interfaces = null;
  interfaces = new int[n];
  for (i = 0; i < n; ++i)
    interfaces[i] = in.readUnsignedShort();
n = in.readUnsignedShort();
fields = new ArrayList<FieldInfo>();
for (i = 0; i < n; ++i)
  addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
methods = new ArrayList<MethodInfo>();
for (i = 0; i < n; ++i)
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
  addAttribute(AttributeInfo.read(cp, in));

代码示例来源:origin: scouter-project/scouter

minor = in.readUnsignedShort();
major = in.readUnsignedShort();
constPool = new ConstPool(in);
accessFlags = in.readUnsignedShort();
thisClass = in.readUnsignedShort();
constPool.setThisClassInfo(thisClass);
superClass = in.readUnsignedShort();
n = in.readUnsignedShort();
if (n == 0)
  interfaces = null;
  interfaces = new int[n];
  for (i = 0; i < n; ++i)
    interfaces[i] = in.readUnsignedShort();
n = in.readUnsignedShort();
fields = new ArrayList();
for (i = 0; i < n; ++i)
  addField2(new FieldInfo(cp, in));
n = in.readUnsignedShort();
methods = new ArrayList();
for (i = 0; i < n; ++i)
n = in.readUnsignedShort();
for (i = 0; i < n; ++i)
  addAttribute(AttributeInfo.read(cp, in));

代码示例来源:origin: org.apache.ant/ant

DataInputStream classStream = new DataInputStream(stream);
if (classStream.readInt() != CLASS_MAGIC) {
  throw new ClassFormatError(
    "No Magic Code Found - probably not a Java class file.");
/* int minorVersion = */ classStream.readUnsignedShort();
/* int majorVersion = */ classStream.readUnsignedShort();
constantPool.resolve();
/* int accessFlags = */ classStream.readUnsignedShort();
int thisClassIndex = classStream.readUnsignedShort();
/* int superClassIndex = */ classStream.readUnsignedShort();
ClassCPInfo classInfo
  = (ClassCPInfo) constantPool.getEntry(thisClassIndex);

代码示例来源:origin: nutzam/nutz

int constant_pool_count = dis.readUnsignedShort();
for (int i = 0; i < (constant_pool_count - 1); i++) {
  byte flag = dis.readByte();
  switch (flag) {
  case 7://CONSTANT_Class:
    int z = dis.readUnsignedShort();
    classIndex.put(i+1, z);
    break;
    break;
  case 1://CONSTANT_Utf8:
    int len = dis.readUnsignedShort();
    byte[] data = new byte[len];
    dis.readFully(data);
int z = dis.readUnsignedShort();
meta.type = strs.get(classIndex.get(z));
if (meta.type != null) {
int interfaces_count = dis.readUnsignedShort();
dis.skipBytes(2 * interfaces_count);//每个接口数据,是2个字节
int fields_count = dis.readUnsignedShort();
for (int i = 0; i < fields_count; i++) {
  dis.skipBytes(2);
  dis.skipBytes(2);
  dis.skipBytes(2);
  int attributes_count = dis.readUnsignedShort();
  for (int j = 0; j < attributes_count; j++) {

相关文章