Class DexFile

java.lang.Object
com.android.dx.dex.file.DexFile

public final class DexFile extends Object
Representation of an entire .dex (Dalvik EXecutable) file, which itself consists of a set of Dalvik classes.
  • Constructor Details

    • DexFile

      public DexFile(DexOptions dexOptions)
      Constructs an instance. It is initially empty.
      Parameters:
      dexOptions - non-null; DEX file generations options to apply
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Returns true if this dex doesn't contain any class defs.
    • getDexOptions

      public DexOptions getDexOptions()
      Gets the dex-creation options object.
    • add

      public void add(ClassDefItem clazz)
      Adds a class to this instance. It is illegal to attempt to add more than one class with the same name.
      Parameters:
      clazz - non-null; the class to add
    • getClassOrNull

      public ClassDefItem getClassOrNull(String name)
      Gets the class definition with the given name, if any.
      Parameters:
      name - non-null; the class name to look for
      Returns:
      null-ok; the class with the given name, or null if there is no such class
    • writeTo

      public void writeTo(OutputStream out, Writer humanOut, boolean verbose) throws IOException
      Writes the contents of this instance as either a binary or a human-readable form, or both.
      Parameters:
      out - null-ok; where to write to
      humanOut - null-ok; where to write human-oriented output to
      verbose - whether to be verbose when writing human-oriented output
      Throws:
      IOException
    • writeTo

      public void writeTo(OutputStream out, DexFile.Storage storage, Writer humanOut, boolean verbose) throws IOException
      Writes the contents of this instance as either a binary or a human-readable form, or both.
      Parameters:
      out - null-ok; where to write to
      storage - temporary storage for storing dexing.
      humanOut - null-ok; where to write human-oriented output to
      verbose - whether to be verbose when writing human-oriented output
      Throws:
      IOException
    • writeTo

      public ByteArrayAnnotatedOutput writeTo(DexFile.Storage storage)
      Writes the contents of this instance as a binary.
      Parameters:
      storage - temporary storage for storing dexing.
      Returns:
      the stored content.
    • toDex

      public byte[] toDex(Writer humanOut, boolean verbose) throws IOException
      Returns the contents of this instance as a .dex file, in byte[] form.
      Parameters:
      humanOut - null-ok; where to write human-oriented output to
      verbose - whether to be verbose when writing human-oriented output
      Returns:
      non-null; a .dex file for this instance
      Throws:
      IOException
    • setDumpWidth

      public void setDumpWidth(int dumpWidth)
      Sets the maximum width of the human-oriented dump of the instance.
      Parameters:
      dumpWidth - >= 40; the width
    • getFileSize

      public int getFileSize()
      Gets the total file size, if known.

      This is package-scope in order to allow the HeaderSection to set itself up properly.

      Returns:
      >= 0; the total file size
      Throws:
      RuntimeException - thrown if the file size is not yet known
    • getClassDefs

      public ClassDefsSection getClassDefs()
      Gets the class definitions section.

      This is package-scope in order to allow the various Item instances to add items to the instance.

      Returns:
      non-null; the class definitions section
    • getTypeIds

      public TypeIdsSection getTypeIds()
      Gets the type identifiers section.

      This is public in order to allow the various Item instances to add items to the instance and help early counting of type ids.

      Returns:
      non-null; the class identifiers section
    • getFieldIds

      public FieldIdsSection getFieldIds()
      Gets the field identifiers section.

      This is public in order to allow the various Item instances to add items to the instance and help early counting of field ids.

      Returns:
      non-null; the field identifiers section
    • getMethodIds

      public MethodIdsSection getMethodIds()
      Gets the method identifiers section.

      This is public in order to allow the various Item instances to add items to the instance and help early counting of method ids.

      Returns:
      non-null; the method identifiers section
    • getMethodHandles

      public MethodHandlesSection getMethodHandles()
      Gets the method handles section.

      This is public in order to allow the various Item instances to add items to the instance and help early counting of method handles.

      Returns:
      non-null; the method handles section
    • getCallSiteIds

      public CallSiteIdsSection getCallSiteIds()
      Gets the call site identifiers section.

      This is public in order to allow the various Item instances to add items to the instance and help early counting of call site identifiers.

      Returns:
      non-null; the call site identifiers section
    • getStatistics

      public Statistics getStatistics()
      Generates and returns statistics for all the items in the file.
      Returns:
      non-null; the statistics