/** * Returns true if the library (jar or folder) contains class files, false otherwise. */ private static boolean checkLibraryClassesJar(@NonNull File input) throws IOException { if (!input.exists()) { return false; } if (input.isDirectory()) { return checkFolder(input); } try (ZipFile zipFile = new ZipFile(input)) { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while(entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.endsWith(DOT_CLASS) || name.endsWith(DOT_DEX)) { return true; } } return false; } }
/** * Returns true if this folder or one of its subfolder contains a class file, false otherwise. */ private static boolean checkFolder(@NonNull File folder) { File[] subFolders = folder.listFiles(); if (subFolders != null) { for (File childFolder : subFolders) { if (childFolder.isFile()) { String name = childFolder.getName(); if (name.endsWith(DOT_CLASS) || name.endsWith(DOT_DEX)) { return true; } } if (childFolder.isDirectory()) { // if childFolder returns false, continue search otherwise return success. if (checkFolder(childFolder)) { return true; } } } } return false; } }