Class DexFile
.dex
(Dalvik EXecutable)
file, which itself consists of a set of Dalvik classes.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Holder for a byte[] that can grow on demand. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ClassDefItem clazz) Adds a class to this instance.Gets the call site identifiers section.Gets the class definitions section.getClassOrNull
(String name) Gets the class definition with the given name, if any.Gets the dex-creation options object.Gets the field identifiers section.int
Gets the total file size, if known.Gets the method handles section.Gets the method identifiers section.Generates and returns statistics for all the items in the file.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[]
Returns the contents of this instance as a.dex
file, inbyte[]
form.writeTo
(DexFile.Storage storage) Writes the contents of this instance as a binary.void
writeTo
(OutputStream out, DexFile.Storage storage, Writer humanOut, boolean verbose) Writes the contents of this instance as either a binary or a human-readable form, or both.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.
-
Constructor Details
-
DexFile
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
Gets the dex-creation options object. -
add
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
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, ornull
if there is no such class
-
writeTo
Writes the contents of this instance as either a binary or a human-readable form, or both.- Parameters:
out
-null-ok;
where to write tohumanOut
-null-ok;
where to write human-oriented output toverbose
- 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 tostorage
- temporary storage for storing dexing.humanOut
-null-ok;
where to write human-oriented output toverbose
- whether to be verbose when writing human-oriented output- Throws:
IOException
-
writeTo
Writes the contents of this instance as a binary.- Parameters:
storage
- temporary storage for storing dexing.- Returns:
- the stored content.
-
toDex
Returns the contents of this instance as a.dex
file, inbyte[]
form.- Parameters:
humanOut
-null-ok;
where to write human-oriented output toverbose
- 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
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
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
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
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
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
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
Generates and returns statistics for all the items in the file.- Returns:
non-null;
the statistics
-