package com.android.dx.cf.direct;
-import com.android.dx.util.FileUtils;
-
+import com.android.dex.util.FileUtils;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-import java.util.zip.ZipFile;
-import java.util.zip.ZipEntry;
-import java.util.Arrays;
-import java.util.Comparator;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
/**
* Opens all the class files found in a class path element. Path elements
* package.
*/
private final boolean sort;
+ private FileNameFilter filter;
/**
* Callback interface for {@code ClassOpener}.
* @param name {@code non-null;} filename of element. May not be a valid
* filesystem path.
*
+ * @param lastModified milliseconds since 1970-Jan-1 00:00:00 GMT
* @param bytes {@code non-null;} file data
* @return true on success. Result is or'd with all other results
* from {@code processFileBytes} and returned to the caller
* of {@code process()}.
*/
- boolean processFileBytes(String name, byte[] bytes);
+ boolean processFileBytes(String name, long lastModified, byte[] bytes);
/**
* Informs consumer that an exception occurred while processing
}
/**
+ * Filter interface for {@code ClassOpener}.
+ */
+ public interface FileNameFilter {
+
+ boolean accept(String path);
+ }
+
+ /**
+ * An accept all filter.
+ */
+ public static final FileNameFilter acceptAll = new FileNameFilter() {
+
+ @Override
+ public boolean accept(String path) {
+ return true;
+ }
+ };
+
+ /**
* Constructs an instance.
*
* @param pathname {@code non-null;} path element to process
* @param consumer {@code non-null;} callback interface
*/
public ClassPathOpener(String pathname, boolean sort, Consumer consumer) {
+ this(pathname, sort, acceptAll, consumer);
+ }
+
+ /**
+ * Constructs an instance.
+ *
+ * @param pathname {@code non-null;} path element to process
+ * @param sort if true, sort such that classes appear before their inner
+ * classes and "package-info" occurs before all other classes in that
+ * package.
+ * @param consumer {@code non-null;} callback interface
+ */
+ public ClassPathOpener(String pathname, boolean sort, FileNameFilter filter,
+ Consumer consumer) {
this.pathname = pathname;
this.sort = sort;
this.consumer = consumer;
+ this.filter = filter;
}
/**
path.endsWith(".apk")) {
return processArchive(file);
}
-
- byte[] bytes = FileUtils.readFile(file);
- return consumer.processFileBytes(path, bytes);
+ 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;
in.close();
byte[] bytes = baos.toByteArray();
- any |= consumer.processFileBytes(path, bytes);
+ any |= consumer.processFileBytes(path, one.getTime(), bytes);
}
zip.close();