Build 1.0_r1(from source)

dalvik.system
Class DexFile

java.lang.Object
  extended by dalvik.system.DexFile

public final class DexFile
extends Object

Manipulate DEX files. Similar in principle to java.util.zip.ZipFile. Used primarily by class loaders. We don't directly open and read the DEX file here. They're mapped read-only by the VM.


Constructor Summary
DexFile(File file)
          Open a DEX file from a File object.
DexFile(String fileName)
          Open a DEX file from a filename (preferrably a full path).
 
Method Summary
 void close()
          Close a DEX file.
 Enumeration<String> entries()
          Enumerate the names of the classes in this DEX file.
protected  void finalize()
          GC helper.
 String getName()
          Get the name of the open file.
static boolean isDexOptNeeded(String fileName)
          Returns true if the VM believes that the apk/jar file is out of date and should be passed through "dexopt" again.
 Class loadClass(String name, ClassLoader loader)
          Load a class.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DexFile

public DexFile(File file)
        throws IOException
Open a DEX file from a File object.

Throws:
IOException

DexFile

public DexFile(String fileName)
        throws IOException
Open a DEX file from a filename (preferrably a full path). This will usually be a Zip/Jar with a "classes.dex" inside. Do not specify the "dalvik-cache" version directly.

Throws:
IOException
Method Detail

getName

public String getName()
Get the name of the open file.


close

public void close()
           throws IOException
Close a DEX file. This may not be able to release any resources. If classes have been loaded, the underlying storage can't be discarded.

Throws:
IOException

loadClass

public Class loadClass(String name,
                       ClassLoader loader)
Load a class. Returns the class on success, or a null reference on failure. If you are not calling this from a class loader, this is most likely not going to do what you want. Use Class.forName() instead. "name" should look like "java/lang/String". I'm not throwing an exception if the class isn't found because I don't want to be throwing exceptions wildly every time we load a class that isn't in the first DEX file we look at. This method *will* throw exceptions for anything that isn't ClassNotFoundException.


entries

public Enumeration<String> entries()
Enumerate the names of the classes in this DEX file.


finalize

protected void finalize()
                 throws IOException
GC helper.

Overrides:
finalize in class Object
Throws:
IOException

isDexOptNeeded

public static boolean isDexOptNeeded(String fileName)
                              throws FileNotFoundException,
                                     IOException
Returns true if the VM believes that the apk/jar file is out of date and should be passed through "dexopt" again.

Parameters:
fileName - the absolute path to the apk/jar file to examine.
Returns:
true if dexopt should be called on the file, false otherwise.
Throws:
FileNotFoundException - if fileName is not readable, not a file, or not present.
IOException - if fileName is not a valid apk/jar file or if problems occur while parsing it.
NullPointerException - if fileName is null.
StaleDexCacheError - if the optimized dex file is stale but exists on a read-only partition.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature