Java Code Examples for java.io.DataInputStream#readUnsignedShort()

The following examples show how to use java.io.DataInputStream#readUnsignedShort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: io.java    From letv with Apache License 2.0 6 votes vote down vote up
public io a(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return null;
    }
    DataInputStream anonymousClass2 = new DataInputStream(this, inputStream) {
        final /* synthetic */ a a;

        public void close() {
        }
    };
    io ioVar = new io();
    short readShort = anonymousClass2.readShort();
    if (readShort == (short) 0) {
        return null;
    }
    ioVar.c = new byte[readShort];
    anonymousClass2.readFully(ioVar.c);
    if (anonymousClass2.readUnsignedShort() == 0) {
    }
    return ioVar;
}
 
Example 2
Source File: CompiledCode.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: VerificationTypeInfo.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static VerificationTypeInfo loadVerificationTypeInfo(DataInputStream in, ConstantPool pool) 
  throws IOException {
    int tag = in.readUnsignedByte();
    switch (tag) {
        case ITEM_Top: return new TopVariableInfo();
        case ITEM_Integer: return new IntegerVariableInfo();
        case ITEM_Float: return new FloatVariableInfo();
        case ITEM_Long: return new LongVariableInfo();
        case ITEM_Double: return new DoubleVariableInfo();
        case ITEM_Null: return new NullVariableInfo();
        case ITEM_UninitializedThis: return new UninitializedThisVariableInfo();
        case ITEM_Object: {
            int cpool_index = in.readUnsignedShort();
            return new ObjectVariableInfo(pool.get(cpool_index));
        }
        case ITEM_Uninitialized: {
            int offset = in.readUnsignedShort();
            return new UninitializedVariableInfo(offset);
        }
        default:
            throw new InvalidClassFormatException("invalid verification_type_info tag: " + tag);
    }
}
 
Example 4
Source File: BinaryMember.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get exceptions
 */
public ClassDeclaration[] getExceptions(Environment env) {
    if ((!isMethod()) || (exp != null)) {
        return exp;
    }
    byte data[] = getAttribute(idExceptions);
    if (data == null) {
        return new ClassDeclaration[0];
    }

    try {
        BinaryConstantPool cpool = ((BinaryClass)getClassDefinition()).getConstants();
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
        // JVM 4.7.5 Exceptions_attribute.number_of_exceptions
        int n = in.readUnsignedShort();
        exp = new ClassDeclaration[n];
        for (int i = 0 ; i < n ; i++) {
            // JVM 4.7.5 Exceptions_attribute.exception_index_table[]
            exp[i] = cpool.getDeclaration(env, in.readUnsignedShort());
        }
        return exp;
    } catch (IOException e) {
        throw new CompilerError(e);
    }
}
 
Example 5
Source File: AiffFileReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * read_ieee_extended
 * Extended precision IEEE floating-point conversion routine.
 * @argument DataInputStream
 * @return double
 * @exception IOException
 */
private double read_ieee_extended(DataInputStream dis) throws IOException {

    double f = 0;
    int expon = 0;
    long hiMant = 0, loMant = 0;
    long t1, t2;
    double HUGE = ((double)3.40282346638528860e+38);


    expon = dis.readUnsignedShort();

    t1 = (long)dis.readUnsignedShort();
    t2 = (long)dis.readUnsignedShort();
    hiMant = t1 << 16 | t2;

    t1 = (long)dis.readUnsignedShort();
    t2 = (long)dis.readUnsignedShort();
    loMant = t1 << 16 | t2;

    if (expon == 0 && hiMant == 0 && loMant == 0) {
        f = 0;
    } else {
        if (expon == 0x7FFF)
            f = HUGE;
        else {
            expon -= 16383;
            expon -= 31;
            f = (hiMant * Math.pow(2, expon));
            expon -= 32;
            f += (loMant * Math.pow(2, expon));
        }
    }

    return f;
}
 
Example 6
Source File: BootstrapMethod.java    From netbeans with Apache License 2.0 5 votes vote down vote up
BootstrapMethod(DataInputStream in, ConstantPool pool) throws IOException {
    this.methodRef = in.readUnsignedShort();
    int args = in.readUnsignedShort();
    arguments = new int[args];
    for (int i = 0; i < args; i++) {
        arguments[i] = in.readUnsignedShort();
    }
}
 
Example 7
Source File: AiffFileReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * read_ieee_extended
 * Extended precision IEEE floating-point conversion routine.
 * @argument DataInputStream
 * @return double
 * @exception IOException
 */
private double read_ieee_extended(DataInputStream dis) throws IOException {

    double f = 0;
    int expon = 0;
    long hiMant = 0, loMant = 0;
    long t1, t2;
    double HUGE = ((double)3.40282346638528860e+38);


    expon = dis.readUnsignedShort();

    t1 = (long)dis.readUnsignedShort();
    t2 = (long)dis.readUnsignedShort();
    hiMant = t1 << 16 | t2;

    t1 = (long)dis.readUnsignedShort();
    t2 = (long)dis.readUnsignedShort();
    loMant = t1 << 16 | t2;

    if (expon == 0 && hiMant == 0 && loMant == 0) {
        f = 0;
    } else {
        if (expon == 0x7FFF)
            f = HUGE;
        else {
            expon -= 16383;
            expon -= 31;
            f = (hiMant * Math.pow(2, expon));
            expon -= 32;
            f += (loMant * Math.pow(2, expon));
        }
    }

    return f;
}
 
Example 8
Source File: HeaderDecoder.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 5 votes vote down vote up
/**
    * Reads TLM marker segment and realigns the codestream where the next
    * marker should be found. Informations stored in these fields are
    * currently NOT taken into account.
    *
    * @param ehs The encoder header stream.
    *
    * @exception IOException If an I/O error occurs while reading from the
    * encoder header stream
    * */
   private void readTLM(DataInputStream ehs) throws IOException {
int length;

length = ehs.readUnsignedShort();
//Ignore all informations contained
ehs.skipBytes(length-2);

       FacilityManager.getMsgLogger().
           printmsg(MsgLogger.INFO,"Skipping unsupported TLM marker");
   }
 
Example 9
Source File: MDNSDiscover.java    From tinydnssd with MIT License 5 votes vote down vote up
private static SRV decodeSRV(byte[] srvData, byte[] packetData, int packetLength) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(srvData));
    SRV srv = new SRV();
    srv.priority = dis.readUnsignedShort();
    srv.weight = dis.readUnsignedShort();
    srv.port = dis.readUnsignedShort();
    srv.target = decodeFQDN(dis, packetData, packetLength);
    if (DEBUG) System.out.printf("Priority: %d Weight: %d Port: %d Target: %s%n", srv.priority, srv.weight, srv.port, srv.target);
    return srv;
}
 
Example 10
Source File: AbstractBackedByteData.java    From cfr with MIT License 5 votes vote down vote up
@Override
public int getU2At(long o) throws ConfusedCFRException {
    // Let's find an EFFICIENT way to do this later!
    DataInputStream dis = rawDataAsStream((int) o, 2);
    try {
        return dis.readUnsignedShort();
    } catch (Exception e) {
        throw new ConfusedCFRException(e);
    }
}
 
Example 11
Source File: ConstantPool.java    From awacs with Apache License 2.0 4 votes vote down vote up
public ConstantPool(DataInputStream in) throws IOException {
  int size = in.readUnsignedShort();
  pool = new ArrayList<>(size);
  BitSet[] nextPass = {new BitSet(size), new BitSet(size), new BitSet(size)};

  // first dummy constant
  pool.add(null);

  // first pass: read the elements
  for (int i = 1; i < size; i++) {
    byte tag = (byte)in.readUnsignedByte();

    switch (tag) {
      case CodeConstants.CONSTANT_Utf8:
        pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Utf8, in.readUTF()));
        break;

      case CodeConstants.CONSTANT_Integer:
        pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Integer, Integer.valueOf(in.readInt())));
        break;

      case CodeConstants.CONSTANT_Float:
        pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Float, Float.valueOf(in.readFloat())));
        break;

      case CodeConstants.CONSTANT_Long:
        pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Long, Long.valueOf(in.readLong())));
        pool.add(null);
        i++;
        break;

      case CodeConstants.CONSTANT_Double:
        pool.add(new PrimitiveConstant(CodeConstants.CONSTANT_Double, Double.valueOf(in.readDouble())));
        pool.add(null);
        i++;
        break;

      case CodeConstants.CONSTANT_Class:
      case CodeConstants.CONSTANT_String:
      case CodeConstants.CONSTANT_MethodType:
        pool.add(new PrimitiveConstant(tag, in.readUnsignedShort()));
        nextPass[0].set(i);
        break;

      case CodeConstants.CONSTANT_NameAndType:
        pool.add(new LinkConstant(tag, in.readUnsignedShort(), in.readUnsignedShort()));
        nextPass[0].set(i);
        break;

      case CodeConstants.CONSTANT_Fieldref:
      case CodeConstants.CONSTANT_Methodref:
      case CodeConstants.CONSTANT_InterfaceMethodref:
      case CodeConstants.CONSTANT_InvokeDynamic:
        pool.add(new LinkConstant(tag, in.readUnsignedShort(), in.readUnsignedShort()));
        nextPass[1].set(i);
        break;

      case CodeConstants.CONSTANT_MethodHandle:
        pool.add(new LinkConstant(tag, in.readUnsignedByte(), in.readUnsignedShort()));
        nextPass[2].set(i);
        break;
    }
  }

  // resolving complex pool elements
  for (BitSet pass : nextPass) {
    int idx = 0;
    while ((idx = pass.nextSetBit(idx + 1)) > 0) {
      pool.get(idx).resolveConstant(this);
    }
  }

  // get global constant pool interceptor instance, if any available
  interceptor = DecompilerContext.getPoolInterceptor();
}
 
Example 12
Source File: BinaryConstantPool.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 */
BinaryConstantPool(DataInputStream in) throws IOException {
    // JVM 4.1 ClassFile.constant_pool_count
    types = new byte[in.readUnsignedShort()];
    cpool = new Object[types.length];
    for (int i = 1 ; i < cpool.length ; i++) {
        int j = i;
        // JVM 4.4 cp_info.tag
        switch(types[i] = in.readByte()) {
          case CONSTANT_UTF8:
            cpool[i] = in.readUTF();
            break;

          case CONSTANT_INTEGER:
            cpool[i] = new Integer(in.readInt());
            break;
          case CONSTANT_FLOAT:
            cpool[i] = new Float(in.readFloat());
            break;
          case CONSTANT_LONG:
            cpool[i++] = new Long(in.readLong());
            break;
          case CONSTANT_DOUBLE:
            cpool[i++] = new Double(in.readDouble());
            break;

          case CONSTANT_CLASS:
          case CONSTANT_STRING:
            // JVM 4.4.3 CONSTANT_String_info.string_index
            // or JVM 4.4.1 CONSTANT_Class_info.name_index
            cpool[i] = new Integer(in.readUnsignedShort());
            break;

          case CONSTANT_FIELD:
          case CONSTANT_METHOD:
          case CONSTANT_INTERFACEMETHOD:
          case CONSTANT_NAMEANDTYPE:
            // JVM 4.4.2 CONSTANT_*ref_info.class_index & name_and_type_index
            cpool[i] = new Integer((in.readUnsignedShort() << 16) | in.readUnsignedShort());
            break;

          case CONSTANT_METHODHANDLE:
            cpool[i] = readBytes(in, 3);
            break;
          case CONSTANT_METHODTYPE:
            cpool[i] = readBytes(in, 2);
            break;
          case CONSTANT_INVOKEDYNAMIC:
            cpool[i] = readBytes(in, 4);
            break;

          case 0:
          default:
            throw new ClassFormatError("invalid constant type: " + (int)types[i]);
        }
    }
}
 
Example 13
Source File: BinaryConstantPool.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 */
BinaryConstantPool(DataInputStream in) throws IOException {
    // JVM 4.1 ClassFile.constant_pool_count
    types = new byte[in.readUnsignedShort()];
    cpool = new Object[types.length];
    for (int i = 1 ; i < cpool.length ; i++) {
        int j = i;
        // JVM 4.4 cp_info.tag
        switch(types[i] = in.readByte()) {
          case CONSTANT_UTF8:
            cpool[i] = in.readUTF();
            break;

          case CONSTANT_INTEGER:
            cpool[i] = new Integer(in.readInt());
            break;
          case CONSTANT_FLOAT:
            cpool[i] = new Float(in.readFloat());
            break;
          case CONSTANT_LONG:
            cpool[i++] = new Long(in.readLong());
            break;
          case CONSTANT_DOUBLE:
            cpool[i++] = new Double(in.readDouble());
            break;

          case CONSTANT_CLASS:
          case CONSTANT_STRING:
            // JVM 4.4.3 CONSTANT_String_info.string_index
            // or JVM 4.4.1 CONSTANT_Class_info.name_index
            cpool[i] = new Integer(in.readUnsignedShort());
            break;

          case CONSTANT_FIELD:
          case CONSTANT_METHOD:
          case CONSTANT_INTERFACEMETHOD:
          case CONSTANT_NAMEANDTYPE:
            // JVM 4.4.2 CONSTANT_*ref_info.class_index & name_and_type_index
            cpool[i] = new Integer((in.readUnsignedShort() << 16) | in.readUnsignedShort());
            break;

          case CONSTANT_METHODHANDLE:
            cpool[i] = readBytes(in, 3);
            break;
          case CONSTANT_METHODTYPE:
            cpool[i] = readBytes(in, 2);
            break;
          case CONSTANT_INVOKEDYNAMIC:
            cpool[i] = readBytes(in, 4);
            break;

          case 0:
          default:
            throw new ClassFormatError("invalid constant type: " + (int)types[i]);
        }
    }
}
 
Example 14
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
private RealClassConstant<Void> readInvokeDynamic(DataInputStream stream, byte type) throws IOException {
	stream.readUnsignedShort();
	stream.readUnsignedShort();
	// return a dummy
	return new RealClassConstant<Void>(type, null);
}
 
Example 15
Source File: Socks5Message.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
   Initialises Message from the stream. Reads server response or client 
   request from given stream.
   
   @param in Input stream to read response from.
   @param clinetMode If true read server response, else read client request.
   @throws SocksException If server response code is not SOCKS_SUCCESS(0) and
   reading in client mode, or if any error with protocol occurs.
   @throws IOException If any error happens with I/O.
 */
 public void read(InputStream in,boolean clientMode) throws SocksException,
                                         IOException{
    data = null;
    ip = null;

    DataInputStream di = new DataInputStream(in);

    version = di.readUnsignedByte();
    command = di.readUnsignedByte();
    if(clientMode && command != 0)
      throw new SocksException(command);

    @SuppressWarnings("unused")
int reserved = di.readUnsignedByte();
    addrType = di.readUnsignedByte();

    byte addr[];

    switch(addrType){
       case SOCKS_ATYP_IPV4:
          addr = new byte[4];
          di.readFully(addr);
          host = bytes2IPV4(addr,0);
       break;
       case SOCKS_ATYP_IPV6:
         addr = new byte[SOCKS_IPV6_LENGTH];//I believe it is 16 bytes,huge!
         di.readFully(addr);
         host = bytes2IPV6(addr,0);
       break;
       case SOCKS_ATYP_DOMAINNAME:
         //System.out.println("Reading ATYP_DOMAINNAME");
         addr = new byte[di.readUnsignedByte()];//Next byte shows the length
         di.readFully(addr);
         host = new String(addr);
       break;
       default:
          throw(new SocksException(Proxy.SOCKS_JUST_ERROR));
    }

    port = di.readUnsignedShort();

    if(addrType != SOCKS_ATYP_DOMAINNAME && doResolveIP){
       try{
          ip = InetAddress.getByName(host);
       }catch(UnknownHostException uh_ex){
       }
    }
 }
 
Example 16
Source File: RealClassBuilder.java    From amidst with GNU General Public License v3.0 4 votes vote down vote up
private RealClassConstant<Void> readInvokeDynamic(DataInputStream stream, byte type) throws IOException {
	stream.readUnsignedShort();
	stream.readUnsignedShort();
	// return a dummy
	return new RealClassConstant<Void>(type, null);
}
 
Example 17
Source File: CompiledClass.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * read a ClassFile structure from the given input source (usually a file)
 */
public CompiledClass( DataInputStream source ) throws IOException {
    int idx;

    magic  = (long)source.readInt();
    minor_version = source.readUnsignedShort();
    major_version = source.readUnsignedShort();
    // the first constant-pool slot is reserved by Java and is not in the classes file
    constant_pool_count = source.readUnsignedShort();
    // read the constant pool list
    constant_pool = new Cp[constant_pool_count];
    constant_pool[0] = null;
    for (idx=1; idx<constant_pool_count; idx++) {
        constant_pool[idx] = Cp.readCp(source);
         // from Venkatesh: workaround for Javasoft hack
         //   From the Java Virtual Machine Specification,
         //   all eight-byte constants take up two spots in the constant pool.
         //   If this is the nth item in the constant pool, then the next
         //   item will be numbered n+2.
        if ((constant_pool[idx] instanceof CpLong) ||
           (constant_pool[idx] instanceof CpDouble)) idx++;
    }
    access_flags = source.readUnsignedShort();
    this_class = source.readUnsignedShort();
    super_class = source.readUnsignedShort();
    interfaces_count = source.readUnsignedShort();
    // read the interfaces list (ptrs into constant_pool)
    interfaces = new int[interfaces_count];
    for (idx=0; idx<interfaces_count; idx++) {
        interfaces[idx] = source.readUnsignedShort();
    }
    fields_count = source.readUnsignedShort();
    // read the fields list (only includes this class, not inherited variables)
    fields = new CompiledField[fields_count];
    for (idx=0; idx<fields_count; idx++) {
        fields[idx] = new CompiledField(source, this);
    }
    methods_count = source.readUnsignedShort();
    // read the methods list
    methods = new CompiledMethod[methods_count];
    for (idx=0; idx<methods_count; idx++) {
        methods[idx] = new CompiledMethod(source, this);
    }
    attributes_count = source.readUnsignedShort();
    // read the attributes
    attributes = new CompiledAttribute[attributes_count];
    for (idx=0; idx<attributes_count; idx++) {
        attributes[idx] = new CompiledAttribute(source);
    }
}
 
Example 18
Source File: StructTypeAnnotationAttribute.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
private static TypeAnnotation parse(DataInputStream data, ConstantPool pool) throws IOException {
    int targetType = data.readUnsignedByte();
    int target = targetType << 24;

    switch (targetType) {
        case TypeAnnotation.CLASS_TYPE_PARAMETER:
        case TypeAnnotation.METHOD_TYPE_PARAMETER:
        case TypeAnnotation.METHOD_PARAMETER:
            target |= data.readUnsignedByte();
            break;

        case TypeAnnotation.SUPER_TYPE_REFERENCE:
        case TypeAnnotation.CLASS_TYPE_PARAMETER_BOUND:
        case TypeAnnotation.METHOD_TYPE_PARAMETER_BOUND:
        case TypeAnnotation.THROWS_REFERENCE:
        case TypeAnnotation.CATCH_CLAUSE:
        case TypeAnnotation.EXPR_INSTANCEOF:
        case TypeAnnotation.EXPR_NEW:
        case TypeAnnotation.EXPR_CONSTRUCTOR_REF:
        case TypeAnnotation.EXPR_METHOD_REF:
            target |= data.readUnsignedShort();
            break;

        case TypeAnnotation.TYPE_ARG_CAST:
        case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_CALL:
        case TypeAnnotation.TYPE_ARG_METHOD_CALL:
        case TypeAnnotation.TYPE_ARG_CONSTRUCTOR_REF:
        case TypeAnnotation.TYPE_ARG_METHOD_REF:
            data.skipBytes(3);
            break;

        case TypeAnnotation.LOCAL_VARIABLE:
        case TypeAnnotation.RESOURCE_VARIABLE:
            data.skipBytes(data.readUnsignedShort() * 6);
            break;

        case TypeAnnotation.FIELD:
        case TypeAnnotation.METHOD_RETURN_TYPE:
        case TypeAnnotation.METHOD_RECEIVER:
            break;

        default:
            throw new RuntimeException("unknown target type: " + targetType);
    }

    int pathLength = data.readUnsignedByte();
    byte[] path = null;
    if (pathLength > 0) {
        path = new byte[2 * pathLength];
        data.readFully(path);
    }

    AnnotationExprent annotation = StructAnnotationAttribute.parseAnnotation(data, pool);

    return new TypeAnnotation(target, path, annotation);
}
 
Example 19
Source File: MethodInfo.java    From JWebAssembly with Apache License 2.0 3 votes vote down vote up
/**
 * Read the method_info structure http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6
 * http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#1513
 *
 * @param input
 *            the stream of the class file
 * @param constantPool
 *            the ConstantPool of the class
 * @param classFile
 *            the declaring class file
 * @throws IOException
 *             if an I/O error occurs
 */
MethodInfo( DataInputStream input, ConstantPool constantPool, ClassFile classFile ) throws IOException {
    this.accessFlags = input.readUnsignedShort();
    this.name = (String)constantPool.get( input.readUnsignedShort() );
    this.description = (String)constantPool.get( input.readUnsignedShort() );
    this.constantPool = constantPool;
    this.attributes = new Attributes( input, constantPool );
    this.classFile = classFile;
}
 
Example 20
Source File: NameAndTypeInfo.java    From whyline with MIT License 3 votes vote down vote up
public NameAndTypeInfo(ConstantPool pool, DataInputStream in) throws IOException {

    	super(pool);
        indexOfName = in.readUnsignedShort();
        indexOfTypeDescriptor = in.readUnsignedShort();
    
    }