FileDocCategorySizeDatePackage
StringDataItem.javaAPI DocAndroid 5.1 API2837Thu Mar 12 22:18:30 GMT 2015com.android.dexgen.dex.file

StringDataItem

public final class StringDataItem extends OffsettedItem
Representation of string data for a particular string, in a Dalvik file.

Fields Summary
private final com.android.dexgen.rop.cst.CstUtf8
value
{@code non-null;} the string value
Constructors Summary
public StringDataItem(com.android.dexgen.rop.cst.CstUtf8 value)
Constructs an instance.

param
value {@code non-null;} the string value

        super(1, writeSize(value));

        this.value = value;
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        // Nothing to do here.
    
protected intcompareTo0(OffsettedItem other)
{@inheritDoc}

        StringDataItem otherData = (StringDataItem) other;

        return value.compareTo(otherData.value);
    
public ItemTypeitemType()
{@inheritDoc}

        return ItemType.TYPE_STRING_DATA_ITEM;
    
public java.lang.StringtoHuman()
{@inheritDoc}

        return value.toQuoted();
    
private static intwriteSize(com.android.dexgen.rop.cst.CstUtf8 value)
Gets the write size for a given value.

param
value {@code non-null;} the string value
return
{@code >= 2}; the write size, in bytes

        int utf16Size = value.getUtf16Size();

        // The +1 is for the '\0' termination byte.
        return Leb128Utils.unsignedLeb128Size(utf16Size)
            + value.getUtf8Size() + 1;
    
public voidwriteTo0(DexFile file, com.android.dexgen.util.AnnotatedOutput out)
{@inheritDoc}

        ByteArray bytes = value.getBytes();
        int utf16Size = value.getUtf16Size();

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

        out.writeUnsignedLeb128(utf16Size);
        out.write(bytes);
        out.writeByte(0);