public void read()

in modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java [87:358]


    public void read(InputStream in) throws IOException, Pack200Exception {

        AttributeLayoutMap attributeDefinitionMap = segment
                .getAttrDefinitionBands().getAttributeDefinitionMap();
        int classCount = header.getClassCount();
        long[][] methodFlags = segment.getClassBands().getMethodFlags();

        int bcCaseCountCount = 0;
        int bcByteCount = 0;
        int bcShortCount = 0;
        int bcLocalCount = 0;
        int bcLabelCount = 0;
        int bcIntRefCount = 0;
        int bcFloatRefCount = 0;
        int bcLongRefCount = 0;
        int bcDoubleRefCount = 0;
        int bcStringRefCount = 0;
        int bcClassRefCount = 0;
        int bcFieldRefCount = 0;
        int bcMethodRefCount = 0;
        int bcIMethodRefCount = 0;
        int bcThisFieldCount = 0;
        int bcSuperFieldCount = 0;
        int bcThisMethodCount = 0;
        int bcSuperMethodCount = 0;
        int bcInitRefCount = 0;
        int bcEscCount = 0;
        int bcEscRefCount = 0;

        AttributeLayout abstractModifier = attributeDefinitionMap
                .getAttributeLayout(AttributeLayout.ACC_ABSTRACT,
                        AttributeLayout.CONTEXT_METHOD);
        AttributeLayout nativeModifier = attributeDefinitionMap
                .getAttributeLayout(AttributeLayout.ACC_NATIVE,
                        AttributeLayout.CONTEXT_METHOD);

        methodByteCodePacked = new byte[classCount][][];
        int bcParsed = 0;

        List switchIsTableSwitch = new ArrayList();
        wideByteCodes = new ArrayList();
        for (int c = 0; c < classCount; c++) {
            int numberOfMethods = methodFlags[c].length;
            methodByteCodePacked[c] = new byte[numberOfMethods][];
            for (int m = 0; m < numberOfMethods; m++) {
                long methodFlag = methodFlags[c][m];
                if (!abstractModifier.matches(methodFlag)
                        && !nativeModifier.matches(methodFlag)) {
                    ByteArrayOutputStream codeBytes = new ByteArrayOutputStream();
                    byte code;
                    while ((code = (byte) (0xff & in.read())) != -1)
                        codeBytes.write(code);
                    methodByteCodePacked[c][m] = codeBytes.toByteArray();
                    bcParsed += methodByteCodePacked[c][m].length;
                    int[] codes = new int[methodByteCodePacked[c][m].length];
                    for (int i = 0; i < codes.length; i++) {
                        codes[i] = methodByteCodePacked[c][m][i] & 0xff;
                    }
                    for (int i = 0; i < methodByteCodePacked[c][m].length; i++) {
                        int codePacked = 0xff & methodByteCodePacked[c][m][i];
                        switch (codePacked) {
                        case 16: // bipush
                        case 188: // newarray
                            bcByteCount++;
                            break;
                        case 17: // sipush
                            bcShortCount++;
                            break;
                        case 18: // (a)ldc
                        case 19: // aldc_w
                            bcStringRefCount++;
                            break;
                        case 234: // ildc
                        case 237: // ildc_w
                            bcIntRefCount++;
                            break;
                        case 235: // fldc
                        case 238: // fldc_w
                            bcFloatRefCount++;
                            break;
                        case 197: // multianewarray
                            bcByteCount++;
                            // fallthrough intended
                        case 233: // cldc
                        case 236: // cldc_w
                        case 187: // new
                        case 189: // anewarray
                        case 192: // checkcast
                        case 193: // instanceof
                            bcClassRefCount++;
                            break;
                        case 20: // lldc2_w
                            bcLongRefCount++;
                            break;
                        case 239: // dldc2_w
                            bcDoubleRefCount++;
                            break;
                        case 169: // ret
                            bcLocalCount++;
                            break;
                        case 167: // goto
                        case 168: // jsr
                        case 200: // goto_w
                        case 201: // jsr_w
                            bcLabelCount++;
                            break;
                        case 170: // tableswitch
                            switchIsTableSwitch.add(new Boolean(true));
                            bcCaseCountCount++;
                            bcLabelCount++;
                            break;
                        case 171: // lookupswitch
                            switchIsTableSwitch.add(new Boolean(false));
                            bcCaseCountCount++;
                            bcLabelCount++;
                            break;
                        case 178: // getstatic
                        case 179: // putstatic
                        case 180: // getfield
                        case 181: // putfield
                            bcFieldRefCount++;
                            break;
                        case 182: // invokevirtual
                        case 183: // invokespecial
                        case 184: // invokestatic
                            bcMethodRefCount++;
                            break;
                        case 185: // invokeinterface
                            bcIMethodRefCount++;
                            break;
                        case 202: // getstatic_this
                        case 203: // putstatic_this
                        case 204: // getfield_this
                        case 205: // putfield_this
                        case 209: // aload_0_getstatic_this
                        case 210: // aload_0_putstatic_this
                        case 211: // aload_0_putfield_this
                        case 212: // aload_0_putfield_this
                            bcThisFieldCount++;
                            break;
                        case 206: // invokevirtual_this
                        case 207: // invokespecial_this
                        case 208: // invokestatic_this
                        case 213: // aload_0_invokevirtual_this
                        case 214: // aload_0_invokespecial_this
                        case 215: // aload_0_invokestatic_this
                            bcThisMethodCount++;
                            break;
                        case 216: // getstatic_super
                        case 217: // putstatic_super
                        case 218: // getfield_super
                        case 219: // putfield_super
                        case 223: // aload_0_getstatic_super
                        case 224: // aload_0_putstatic_super
                        case 225: // aload_0_getfield_super
                        case 226: // aload_0_putfield_super
                            bcSuperFieldCount++;
                            break;
                        case 220: // invokevirtual_super
                        case 221: // invokespecial_super
                        case 222: // invokestatic_super
                        case 227: // aload_0_invokevirtual_super
                        case 228: // aload_0_invokespecial_super
                        case 229: // aload_0_invokestatic_super
                            bcSuperMethodCount++;
                            break;
                        case 132: // iinc
                            bcLocalCount++;
                            bcByteCount++;
                            break;
                        case 196: // wide
                            int nextInstruction = 0xff & methodByteCodePacked[c][m][i + 1];
                            wideByteCodes.add(new Integer(nextInstruction));
                            if (nextInstruction == 132) { // iinc
                                bcLocalCount++;
                                bcShortCount++;
                            } else if (endsWithLoad(nextInstruction)
                                    || endsWithStore(nextInstruction)
                                    || nextInstruction == 169) {
                                bcLocalCount++;
                            } else {
                                segment
                                        .log(
                                                Segment.LOG_LEVEL_VERBOSE,
                                                "Found unhandled "
                                                        + ByteCode
                                                                .getByteCode(nextInstruction));
                            }
                            i++;
                            break;
                        case 230: // invokespecial_this_init
                        case 231: // invokespecial_super_init
                        case 232: // invokespecial_new_init
                            bcInitRefCount++;
                            break;
                        case 253: // ref_escape
                            bcEscRefCount++;
                            break;
                        case 254: // byte_escape
                            bcEscCount++;
                            break;
                        default:
                            if (endsWithLoad(codePacked)
                                    || endsWithStore(codePacked)) {
                                bcLocalCount++;
                            } else if (startsWithIf(codePacked)) {
                                bcLabelCount++;
                            }
                        }
                    }
                }
            }
        }
        // other bytecode bands
        bcCaseCount = decodeBandInt("bc_case_count", in, Codec.UNSIGNED5,
                bcCaseCountCount);
        int bcCaseValueCount = 0;
        for (int i = 0; i < bcCaseCount.length; i++) {
            boolean isTableSwitch = ((Boolean) switchIsTableSwitch.get(i))
                    .booleanValue();
            if (isTableSwitch) {
                bcCaseValueCount += 1;
            } else {
                bcCaseValueCount += bcCaseCount[i];
            }
        }
        bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5,
                bcCaseValueCount);
        // Every case value needs a label. We weren't able to count these
        // above, because we didn't know how many cases there were.
        // Have to correct it now.
        for (int index = 0; index < bcCaseCountCount; index++) {
            bcLabelCount += bcCaseCount[index];
        }
        bcByte = decodeBandInt("bc_byte", in, Codec.BYTE1, bcByteCount);
        bcShort = decodeBandInt("bc_short", in, Codec.DELTA5, bcShortCount);
        bcLocal = decodeBandInt("bc_local", in, Codec.UNSIGNED5, bcLocalCount);
        bcLabel = decodeBandInt("bc_label", in, Codec.BRANCH5, bcLabelCount);
        bcIntRef = decodeBandInt("bc_intref", in, Codec.DELTA5, bcIntRefCount);
        bcFloatRef = decodeBandInt("bc_floatref", in, Codec.DELTA5,
                bcFloatRefCount);
        bcLongRef = decodeBandInt("bc_longref", in, Codec.DELTA5,
                bcLongRefCount);
        bcDoubleRef = decodeBandInt("bc_doubleref", in, Codec.DELTA5,
                bcDoubleRefCount);
        bcStringRef = decodeBandInt("bc_stringref", in, Codec.DELTA5,
                bcStringRefCount);
        bcClassRef = decodeBandInt("bc_classref", in, Codec.UNSIGNED5,
                bcClassRefCount);
        bcFieldRef = decodeBandInt("bc_fieldref", in, Codec.DELTA5,
                bcFieldRefCount);
        bcMethodRef = decodeBandInt("bc_methodref", in, Codec.UNSIGNED5,
                bcMethodRefCount);
        bcIMethodRef = decodeBandInt("bc_imethodref", in, Codec.DELTA5,
                bcIMethodRefCount);
        bcThisField = decodeBandInt("bc_thisfield", in, Codec.UNSIGNED5,
                bcThisFieldCount);
        bcSuperField = decodeBandInt("bc_superfield", in, Codec.UNSIGNED5,
                bcSuperFieldCount);
        bcThisMethod = decodeBandInt("bc_thismethod", in, Codec.UNSIGNED5,
                bcThisMethodCount);
        bcSuperMethod = decodeBandInt("bc_supermethod", in, Codec.UNSIGNED5,
                bcSuperMethodCount);
        bcInitRef = decodeBandInt("bc_initref", in, Codec.UNSIGNED5,
                bcInitRefCount);
        bcEscRef = decodeBandInt("bc_escref", in, Codec.UNSIGNED5,
                bcEscRefCount);
        bcEscRefSize = decodeBandInt("bc_escrefsize", in, Codec.UNSIGNED5,
                bcEscRefCount);
        bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
        bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
    }