public void testListFilesString() { // see if it just works. try { ArrayList<String> testdata1 = FileUtils.getAllImages(new File("testdata/ferrari/black"), true); assertEquals(19, testdata1.size()); } catch (IOException e) { e.printStackTrace(); } // see if it just fails. try { ArrayList<String> testdata2 = null; testdata2 = FileUtils.getAllImages(new File("testdata/ferrari/black/nothing"), true); fail(); } catch (Exception e) { // e.printStackTrace(); } }
public void testIndexingSpeed() throws IOException { ArrayList<String> images = FileUtils.getAllImages(new File(testExtensive), false); testFeatureSpeed(images, AutoColorCorrelogram.class); testFeatureSpeed(images, CEDD.class); testFeatureSpeed(images, FCTH.class); testFeatureSpeed(images, JCD.class); testFeatureSpeed(images, SPACC.class); testFeatureSpeed(images, SPCEDD.class); testFeatureSpeed(images, SPFCTH.class); testFeatureSpeed(images, SPJCD.class); }
/** * Returns all jpg images from a directory in an array. * * @param directory the directory to start with * @param descendIntoSubDirectories should we include sub directories? * @return an ArrayList<String> containing all the files or nul if none are found.. * @throws IOException */ public static ArrayList<String> getAllImages(File directory, boolean descendIntoSubDirectories) throws IOException { ArrayList<String> resultList = new ArrayList<String>(256); File[] f = directory.listFiles(); for (File file : f) { if (file != null && (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png") || file.getName().toLowerCase().endsWith(".gif")) && !file.getName().startsWith("tn_")) { resultList.add(file.getCanonicalPath()); } if (descendIntoSubDirectories && file.isDirectory()) { ArrayList<String> tmp = getAllImages(file, true); if (tmp != null) { resultList.addAll(tmp); } } } if (resultList.size() > 0) return resultList; else return null; }
writer = new IndexWriter(FSDirectory.open(new File(indexPath)), config); if (imageList == null) { files = FileUtils.getAllImages(new File(imageDirectory), true); } else { files = new LinkedList<String>();