Package com.android.dx.dex.file
Class MixedItemSection
java.lang.Object
com.android.dx.dex.file.Section
com.android.dx.dex.file.MixedItemSection
A section of a
.dex
file which consists of a sequence of
OffsettedItem
objects, which may each be of a different concrete
class and/or size.
Note: It is invalid for an item in an instance of this class to
have a larger alignment requirement than the alignment of this instance.-
Constructor Summary
ConstructorDescriptionMixedItemSection
(String name, DexFile file, int alignment, com.android.dx.dex.file.MixedItemSection.SortType sort) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(OffsettedItem item) Adds an item to this instance.<T extends OffsettedItem>
Tget
(T item) Gets an item which was previously interned.int
getAbsoluteItemOffset
(Item item) Returns the absolute file offset of the given item which must be contained in this section.<T extends OffsettedItem>
Tintern
(T item) Interns an item in this instance, returning the interned instance (which may not be the one passed in).Collection
<? extends Item> items()
Gets the collection of all the items in this section.void
Places all the items in this instance at particular offsets.protected void
prepare0()
Does the main work ofSection.prepare()
.int
size()
Gets the size of this instance, in items.void
Writes the portion of the file header that refers to this instance.void
writeIndexAnnotation
(AnnotatedOutput out, ItemType itemType, String intro) Writes an index of contents of the items in this instance of the given type.int
Gets the size of this instance when output, in bytes.protected void
writeTo0
(AnnotatedOutput out) Writes this instance to the given raw data object.Methods inherited from class com.android.dx.dex.file.Section
align, getAbsoluteOffset, getAlignment, getFile, getFileOffset, getName, prepare, setFileOffset, throwIfNotPrepared, throwIfPrepared, validateAlignment, writeTo
-
Constructor Details
-
MixedItemSection
public MixedItemSection(String name, DexFile file, int alignment, com.android.dx.dex.file.MixedItemSection.SortType sort) Constructs an instance. The file offset is initially unknown.- Parameters:
name
-null-ok;
the name of this instance, for annotation purposesfile
-non-null;
file that this instance is part ofalignment
-> 0;
alignment requirement for the final output; must be a power of 2sort
- how the items should be sorted in the final output
-
-
Method Details
-
items
Gets the collection of all the items in this section. It is not valid to attempt to change the returned list. -
writeSize
public int writeSize()Gets the size of this instance when output, in bytes. -
getAbsoluteItemOffset
Returns the absolute file offset of the given item which must be contained in this section. This is only valid to call once this instance has been assigned a file offset (viaSection.setFileOffset(int)
).Note: Subclasses must implement this as appropriate for their contents.
- Specified by:
getAbsoluteItemOffset
in classSection
- Parameters:
item
-non-null;
the item in question- Returns:
>= 0;
the item's absolute file offset
-
size
public int size()Gets the size of this instance, in items.- Returns:
>= 0;
the size
-
writeHeaderPart
Writes the portion of the file header that refers to this instance.- Parameters:
out
-non-null;
where to write
-
add
Adds an item to this instance. This will in turn tell the given item that it has been added to this instance. It is invalid to add the same item to more than one instance, nor to add the same items multiple times to a single instance.- Parameters:
item
-non-null;
the item to add
-
intern
Interns an item in this instance, returning the interned instance (which may not be the one passed in). This will add the item if no equal item has been added.- Parameters:
item
-non-null;
the item to intern- Returns:
non-null;
the equivalent interned instance
-
get
Gets an item which was previously interned.- Parameters:
item
-non-null;
the item to look for- Returns:
non-null;
the equivalent already-interned instance
-
writeIndexAnnotation
Writes an index of contents of the items in this instance of the given type. If there are none, this writes nothing. If there are any, then the index is preceded by the given intro string.- Parameters:
out
-non-null;
where to write toitemType
-non-null;
the item type of interestintro
-non-null;
the introductory string for non-empty indices
-
prepare0
protected void prepare0()Does the main work ofSection.prepare()
. -
placeItems
public void placeItems()Places all the items in this instance at particular offsets. This will callOffsettedItem.place(com.android.dx.dex.file.Section, int)
on each item. If an item does not know its write size before the call toplace
, it is that call which is responsible for setting the write size. This method may only be called once per instance; subsequent calls will throw an exception. -
writeTo0
Writes this instance to the given raw data object. This gets called bySection.writeTo(com.android.dx.util.AnnotatedOutput)
after aligning the cursor ofout
and verifying that either the assigned file offset matches the actual cursorout
or that the file offset was not previously assigned, in which case it gets assigned toout
's cursor.
-