com.android.dx.dex.file
Class DexFile

java.lang.Object
  extended by 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 Summary
DexFile(DexOptions dexOptions)
          Constructs an instance.
 
Method Summary
 void add(ClassDefItem clazz)
          Adds a class to this instance.
 ClassDefsSection getClassDefs()
          Gets the class definitions section.
 ClassDefItem getClassOrNull(String name)
          Gets the class definition with the given name, if any.
 DexOptions getDexOptions()
          Gets the dex-creation options object.
 FieldIdsSection getFieldIds()
          Gets the field identifiers section.
 int getFileSize()
          Gets the total file size, if known.
 MethodIdsSection getMethodIds()
          Gets the method identifiers section.
 Statistics getStatistics()
          Generates and returns statistics for all the items in the file.
 TypeIdsSection getTypeIds()
          Gets the type identifiers section.
 boolean isEmpty()
          Returns true if this dex doesn't contain any class defs.
 void setDumpWidth(int dumpWidth)
          Sets the maximum width of the human-oriented dump of the instance.
 byte[] toDex(Writer humanOut, boolean verbose)
          Returns the contents of this instance as a .dex file, in byte[] form.
 void writeTo(OutputStream out, Writer humanOut, boolean verbose)
          Writes the contents of this instance as either a binary or a human-readable form, or both.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DexFile

public DexFile(DexOptions dexOptions)
Constructs an instance. It is initially empty.

Method Detail

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

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

getStatistics

public Statistics getStatistics()
Generates and returns statistics for all the items in the file.

Returns:
non-null; the statistics


Copyright © 2015. All rights reserved.