/** * Read constants from given input stream. * * @param input Input stream * @throws IOException * @throws ClassFormatException */ public ConstantPool(final DataInput input) throws IOException, ClassFormatException { byte tag; final int constant_pool_count = input.readUnsignedShort(); constant_pool = new Constant[constant_pool_count]; /* constant_pool[0] is unused by the compiler and may be used freely * by the implementation. */ for (int i = 1; i < constant_pool_count; i++) { constant_pool[i] = Constant.readConstant(input); /* Quote from the JVM specification: * "All eight byte constants take up two spots in the constant pool. * If this is the n'th byte in the constant pool, then the next item * will be numbered n+2" * * Thus we have to increment the index counter. */ tag = constant_pool[i].getTag(); if ((tag == Const.CONSTANT_Double) || (tag == Const.CONSTANT_Long)) { i++; } } }
/** * Read constants from given file stream. * * @param file Input stream * @throws IOException * @throws ClassFormatException */ ConstantPool(DataInputStream file) throws IOException, ClassFormatException { byte tag; constant_pool_count = file.readUnsignedShort(); constant_pool = new Constant[constant_pool_count]; /* constant_pool[0] is unused by the compiler and may be used freely * by the implementation. */ for(int i=1; i < constant_pool_count; i++) { constant_pool[i] = Constant.readConstant(file); /* Quote from the JVM specification: * "All eight byte constants take up two spots in the constant pool. * If this is the n'th byte in the constant pool, then the next item * will be numbered n+2" * * Thus we have to increment the index counter. */ tag = constant_pool[i].getTag(); if((tag == Constants.CONSTANT_Double) || (tag == Constants.CONSTANT_Long)) i++; } }