Java Code Examples for com.android.dx.util.AnnotatedOutput#write()

The following examples show how to use com.android.dx.util.AnnotatedOutput#write() . 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: ClassDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        encodeOutput(file, out);
    } else {
        out.write(encodedForm);
    }
}
 
Example 2
Source File: EncodedArrayItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        out.annotate(0, offsetString() + " encoded array");

        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeArray(array, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 3
Source File: StringDataItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 4
Source File: StringDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 5
Source File: StringDataItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 6
Source File: EncodedArrayItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        out.annotate(0, offsetString() + " encoded array");

        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeArray(array, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 7
Source File: ClassDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        encodeOutput(file, out);
    } else {
        out.write(encodedForm);
    }
}
 
Example 8
Source File: EncodedArrayItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        out.annotate(0, offsetString() + " encoded array");

        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeArray(array, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 9
Source File: ClassDataItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        encodeOutput(file, out);
    } else {
        out.write(encodedForm);
    }
}
 
Example 10
Source File: AnnotationItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 11
Source File: DebugInfoItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        /*
         * Re-run the encoder to generate the annotations,
         * but write the bits from the original encode
         */

        out.annotate(offsetString() + " debug info");
        encode(file, null, null, out, true);
    }

    out.write(encoded);
}
 
Example 12
Source File: CatchStructs.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 13
Source File: CatchStructs.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 14
Source File: AnnotationItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 15
Source File: DebugInfoItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        /*
         * Re-run the encoder to generate the annotations,
         * but write the bits from the original encode
         */

        out.annotate(offsetString() + " debug info");
        encode(file, null, null, out, true);
    }

    out.write(encoded);
}
 
Example 16
Source File: CatchStructs.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 17
Source File: AnnotationItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 18
Source File: AnnotationItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 19
Source File: DebugInfoItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        /*
         * Re-run the encoder to generate the annotations,
         * but write the bits from the original encode
         */

        out.annotate(offsetString() + " debug info");
        encode(file, null, null, out, true);
    }

    out.write(encoded);
}
 
Example 20
Source File: CallSiteItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    if (out.annotates()) {
        out.annotate(0, offsetString() + " call site");
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeArray(value, true);
    } else {
        out.write(encodedForm);
    }
}