FileDocCategorySizeDatePackage
StringDataItem.javaAPI DocAndroid 5.1 API2795Thu Mar 12 22:18:30 GMT 2015com.android.dx.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.dx.rop.cst.CstString
value
{@code non-null;} the string value
Constructors Summary
public StringDataItem(com.android.dx.rop.cst.CstString 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.dx.rop.cst.CstString 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 Leb128.unsignedLeb128Size(utf16Size)
            + value.getUtf8Size() + 1;
    
public voidwriteTo0(DexFile file, com.android.dx.util.AnnotatedOutput out)
{@inheritDoc}

        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);