FileDocCategorySizeDatePackage
StringDataItem.javaAPI DocAndroid 1.5 API2794Wed May 06 22:41:02 BST 2009com.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.CstUtf8
value
non-null; the string value
Constructors Summary
public StringDataItem(com.android.dx.rop.cst.CstUtf8 value)
Constructs an instance.

param
value 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.CstUtf8 value)
Gets the write size for a given value.

param
value non-null; the string value
return
>= 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.dx.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);