Class MixedItemSection

java.lang.Object
com.android.dx.dex.file.Section
com.android.dx.dex.file.MixedItemSection

public final class MixedItemSection extends Section
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 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 purposes
      file - non-null; file that this instance is part of
      alignment - > 0; alignment requirement for the final output; must be a power of 2
      sort - how the items should be sorted in the final output
  • Method Details

    • items

      public Collection<? extends Item> items()
      Gets the collection of all the items in this section. It is not valid to attempt to change the returned list.
      Specified by:
      items in class Section
      Returns:
      non-null; the items
    • writeSize

      public int writeSize()
      Gets the size of this instance when output, in bytes.
      Specified by:
      writeSize in class Section
      Returns:
      >= 0; the size of this instance, in bytes
    • getAbsoluteItemOffset

      public int getAbsoluteItemOffset(Item item)
      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 (via Section.setFileOffset(int)).

      Note: Subclasses must implement this as appropriate for their contents.

      Specified by:
      getAbsoluteItemOffset in class Section
      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

      public void writeHeaderPart(AnnotatedOutput out)
      Writes the portion of the file header that refers to this instance.
      Parameters:
      out - non-null; where to write
    • add

      public void add(OffsettedItem item)
      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

      public <T extends OffsettedItem> T intern(T item)
      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

      public <T extends OffsettedItem> T get(T item)
      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

      public void writeIndexAnnotation(AnnotatedOutput out, ItemType itemType, String intro)
      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 to
      itemType - non-null; the item type of interest
      intro - non-null; the introductory string for non-empty indices
    • prepare0

      protected void prepare0()
      Does the main work of Section.prepare().
      Specified by:
      prepare0 in class Section
    • placeItems

      public void placeItems()
      Places all the items in this instance at particular offsets. This will call OffsettedItem.place(com.android.dx.dex.file.Section, int) on each item. If an item does not know its write size before the call to place, 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

      protected void writeTo0(AnnotatedOutput out)
      Writes this instance to the given raw data object. This gets called by Section.writeTo(com.android.dx.util.AnnotatedOutput) after aligning the cursor of out and verifying that either the assigned file offset matches the actual cursor out or that the file offset was not previously assigned, in which case it gets assigned to out's cursor.
      Specified by:
      writeTo0 in class Section
      Parameters:
      out - non-null; where to write to