Java Code Examples for com.android.dex.util.FileUtils

The following examples show how to use com.android.dex.util.FileUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Box   Source File: Dex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            try (InputStream inputStream = zipFile.getInputStream(entry)) {
                loadFrom(inputStream);
            }
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        try (InputStream inputStream = new FileInputStream(file)) {
            loadFrom(inputStream);
        }
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
Example 2
Source Project: Box   Source File: ClassPathOpener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Processes one file.
 *
 * @param file {@code non-null;} the file to process
 * @param topLevel whether this is a top-level file (that is,
 * specified directly on the commandline)
 * @return whether any processing actually happened
 */
private boolean processOne(File file, boolean topLevel) {
    try {
        if (file.isDirectory()) {
            return processDirectory(file, topLevel);
        }

        String path = file.getPath();

        if (path.endsWith(".zip") ||
                path.endsWith(".jar") ||
                path.endsWith(".apk")) {
            return processArchive(file);
        }
        if (filter.accept(path)) {
            byte[] bytes = FileUtils.readFile(file);
            return consumer.processFileBytes(path, file.lastModified(), bytes);
        } else {
            return false;
        }
    } catch (Exception ex) {
        consumer.onException(ex);
        return false;
    }
}
 
Example 3
Source Project: Box   Source File: Dex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            try (InputStream inputStream = zipFile.getInputStream(entry)) {
                loadFrom(inputStream);
            }
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        try (InputStream inputStream = new FileInputStream(file)) {
            loadFrom(inputStream);
        }
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
Example 4
Source Project: Box   Source File: ClassPathOpener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Processes one file.
 *
 * @param file {@code non-null;} the file to process
 * @param topLevel whether this is a top-level file (that is,
 * specified directly on the commandline)
 * @return whether any processing actually happened
 */
private boolean processOne(File file, boolean topLevel) {
    try {
        if (file.isDirectory()) {
            return processDirectory(file, topLevel);
        }

        String path = file.getPath();

        if (path.endsWith(".zip") ||
                path.endsWith(".jar") ||
                path.endsWith(".apk")) {
            return processArchive(file);
        }
        if (filter.accept(path)) {
            byte[] bytes = FileUtils.readFile(file);
            return consumer.processFileBytes(path, file.lastModified(), bytes);
        } else {
            return false;
        }
    } catch (Exception ex) {
        consumer.onException(ex);
        return false;
    }
}
 
Example 5
Source Project: J2ME-Loader   Source File: Dex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            try (InputStream inputStream = zipFile.getInputStream(entry)) {
                loadFrom(inputStream);
            }
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        try (InputStream inputStream = new FileInputStream(file)) {
            loadFrom(inputStream);
        }
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
Example 6
Source Project: J2ME-Loader   Source File: ClassPathOpener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Processes one file.
 *
 * @param file {@code non-null;} the file to process
 * @param topLevel whether this is a top-level file (that is,
 * specified directly on the commandline)
 * @return whether any processing actually happened
 */
private boolean processOne(File file, boolean topLevel) {
    try {
        if (file.isDirectory()) {
            return processDirectory(file, topLevel);
        }

        String path = file.getPath();

        if (path.endsWith(".zip") ||
                path.endsWith(".jar") ||
                path.endsWith(".apk")) {
            return processArchive(file);
        }
        if (filter.accept(path)) {
            byte[] bytes = FileUtils.readFile(file);
            return consumer.processFileBytes(path, file.lastModified(), bytes);
        } else {
            return false;
        }
    } catch (Exception ex) {
        consumer.onException(ex);
        return false;
    }
}
 
Example 7
Source Project: aapt   Source File: Dex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        try {
            if (entry != null) {
                try (InputStream inputStream = zipFile.getInputStream(entry)) {
                    loadFrom(inputStream);
                }
            } else {
                throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
            }
        } finally {
            zipFile.close();
        }
    } else if (file.getName().endsWith(".dex")) {
        try (InputStream inputStream = new FileInputStream(file)) {
            loadFrom(inputStream);
        }
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
Example 8
Source Project: buck   Source File: Dex.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new dex buffer from the dex file {@code file}.
 */
public Dex(File file) throws IOException {
    if (FileUtils.hasArchiveSuffix(file.getName())) {
        ZipFile zipFile = new ZipFile(file);
        ZipEntry entry = zipFile.getEntry(DexFormat.DEX_IN_JAR_NAME);
        if (entry != null) {
            loadFrom(zipFile.getInputStream(entry));
            zipFile.close();
        } else {
            throw new DexException("Expected " + DexFormat.DEX_IN_JAR_NAME + " in " + file);
        }
    } else if (file.getName().endsWith(".dex")) {
        loadFrom(new FileInputStream(file));
    } else {
        throw new DexException("unknown output extension: " + file);
    }
}
 
Example 9
Source Project: buck   Source File: ClassPathOpener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Processes one file.
 *
 * @param file {@code non-null;} the file to process
 * @param topLevel whether this is a top-level file (that is,
 * specified directly on the commandline)
 * @return whether any processing actually happened
 */
private boolean processOne(File file, boolean topLevel) {
    try {
        if (file.isDirectory()) {
            return processDirectory(file, topLevel);
        }

        String path = file.getPath();

        if (path.endsWith(".zip") ||
                path.endsWith(".jar") ||
                path.endsWith(".apk")) {
            return processArchive(file);
        }
        if (filter.accept(path)) {
            byte[] bytes = FileUtils.readFile(file);
            return consumer.processFileBytes(path, file.lastModified(), bytes);
        } else {
            return false;
        }
    } catch (Exception ex) {
        consumer.onException(ex);
        return false;
    }
}