List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE
IOFileFilter INSTANCE
To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.
Click Source Link
From source file:com.taobao.android.TPatchTool.java
/** * ?bundle??// w ww.ja v a 2 s. c om * * @param newApkUnzipFolder * @param baseApkUnzipFolder * @param patchTmpDir * @throws IOException */ private void copyMainBundleResources(final File newApkUnzipFolder, final File baseApkUnzipFolder, File patchTmpDir) throws IOException { boolean resoureModified = false; Collection<File> retainFiles = FileUtils.listFiles(newApkUnzipFolder, new IOFileFilter() { @Override public boolean accept(File file) { String relativePath = PathUtils.toRelative(newApkUnzipFolder, file.getAbsolutePath()); if (pathMatcher.match(DEFAULT_NOT_INCLUDE_RESOURCES, relativePath)) { return false; } if (null != notIncludeFiles && pathMatcher.match(notIncludeFiles, relativePath)) { return false; } return true; } @Override public boolean accept(File file, String s) { return accept(new File(file, s)); } }, TrueFileFilter.INSTANCE); for (File retainFile : retainFiles) { String relativePath = PathUtils.toRelative(newApkUnzipFolder, retainFile.getAbsolutePath()); File baseFile = new File(baseApkUnzipFolder, relativePath); if (isFileModify(retainFile, baseFile)) { resoureModified = true; File destFile = new File(patchTmpDir, relativePath); FileUtils.copyFile(retainFile, destFile); } } if (resoureModified) { File AndroidMenifestFile = new File(newApkUnzipFolder, ANDROID_MANIFEST); FileUtils.copyFileToDirectory(AndroidMenifestFile, patchTmpDir); } }
From source file:io.manasobi.utils.FileUtils.java
/** * ? ? ?? File ? ./* www .j av a 2s. c o m*/ * * @param dir * @param recursive ?? ? ?? * @param extList ? ? * @return ? ? ?? File ? */ public static File[] listFilesExcludeExt(String dir, boolean recursive, String... extList) { IOFileFilter suffixFileFilters = new SuffixFileFilter(extList, IOCase.INSENSITIVE); IOFileFilter excludeExtFilter = FileFilterUtils.notFileFilter(FileFilterUtils.or(suffixFileFilters)); Collection<File> resultFiles = org.apache.commons.io.FileUtils.listFiles(new File(dir), excludeExtFilter, TrueFileFilter.INSTANCE); return org.apache.commons.io.FileUtils.convertFileCollectionToFileArray(resultFiles); }
From source file:com.splout.db.dnode.DNodeHandler.java
/** * Returns an {@link com.splout.db.dnode.beans.DNodeSystemStatus} filled with * the appropriated data./*from w w w . j a v a 2 s. c o m*/ */ @Override public String status() throws DNodeException { try { DNodeSystemStatus status = new DNodeSystemStatus(); if (lastException == null) { status.setSystemStatus("UP"); status.setLastExceptionTime(-1); } else { status.setSystemStatus("Last exception: " + lastException); status.setLastExceptionTime(lastExceptionTime); } status.setUpSince(upSince); status.setFailedQueries(failedQueries.get()); status.setnQueries(performanceTool.getNQueries()); status.setAverage(performanceTool.getAverage()); status.setSlowQueries(slowQueries); status.setDeploysInProgress(deployInProgress.get()); status.setHttpExchangerAddress(httpExchangerAddress()); status.setTcpAddress(getTCPAPIAddress()); status.setBalanceActionsStateMap(balanceActionsStateMap); File folder = new File(config.getString(DNodeProperties.DATA_FOLDER)); if (folder.exists()) { status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(folder.toString())); status.setOccupiedSpaceInDisk(FileUtils.sizeOfDirectory(folder)); Collection<File> files = FileUtils.listFilesAndDirs(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); status.setFiles(new ArrayList<String>( Lists.transform(Lists.newArrayList(files), new Function<File, String>() { @Override public String apply(File file) { return file.getAbsolutePath() + " (" + FileUtils.sizeOf(file) + " bytes)"; } }))); Collections.sort(status.getFiles()); } else { status.setOccupiedSpaceInDisk(0); status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(".")); status.setFiles(new ArrayList<String>()); } return JSONSerDe.ser(status); } catch (Throwable t) { unexpectedException(t); throw new DNodeException(EXCEPTION_UNEXPECTED, t.getMessage()); } }
From source file:com.kdmanalytics.toif.assimilator.Assimilator.java
/** * get all the files from the argument list. * /*from www .j a v a 2 s .c om*/ * @param args * the arguments handed to main. * @return the list of files in the argument array with the given extension. * @throws ToifException */ List<File> getFiles(String[] args, final String... extensions) throws ToifException { checkNotNull(args); checkNotNull(extensions); // set up a file filter. IOFileFilter fileFilter = new IOFileFilter() { @Override public boolean accept(File arg0) { for (String extension : extensions) { if (arg0.getName().endsWith(extension)) { return true; } } return false; } @Override public boolean accept(File arg0, String arg1) { for (String extension : extensions) { if (arg1.endsWith(extension)) { return true; } } return false; } }; // the files of the specific extension final List<File> files = new ArrayList<File>(); // int startIndex = 2; // for (String string : args) // { // if ("-p".equals(string)) // { // startIndex = 4; // } // } // starting at the unparsed options, ie the files in the arguments. for (int i = 2; i < args.length; i++) { if ("-p".equals(args[i])) { i = i += 2; } final String path = args[i]; final File file = new File(path); // if the file does not exist, bail. if (!file.exists()) { final String msg = "File does not exist: " + file.getName(); LOG.error(msg); throw new ToifException(msg); } if (file.isDirectory()) { files.addAll(FileUtils.listFiles(file, fileFilter, TrueFileFilter.INSTANCE)); } else { /* * only add the file to the results list if the file has the extension and is a file. */ for (String extension : extensions) { if (file.getAbsolutePath().endsWith(extension)) { files.add(file); Assimilator.debug(LOG, file.getName() + " added to the " + extension + " list"); } } } } if (debug) { for (File file : files) { System.err.println(file.getName()); } } // return the list of files. return files; }
From source file:com.taobao.android.tools.TPatchTool.java
/** * Adds a directory to a {@link} with a directory prefix. * * @param jos ZipArchiver to use to archive the file. * @param directory The directory to add. * @param prefix An optional prefix for where in the Jar file the directory's contents should go. *//* w w w . ja v a2 s.c o m*/ protected void addDirectory(JarOutputStream jos, File directory, String prefix) throws IOException { if (directory != null && directory.exists()) { Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); byte[] buf = new byte[8064]; for (File file : files) { if (file.isDirectory()) { continue; } String path = prefix + "/" + PathUtils.toRelative(directory, file.getAbsolutePath()); InputStream in = null; try { in = new FileInputStream(file); ZipEntry fileEntry = new ZipEntry(path); jos.putNextEntry(fileEntry); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { jos.write(buf, 0, len); } // Complete the entry jos.closeEntry(); in.close(); } finally { IOUtils.closeQuietly(in); } } } }
From source file:com.taobao.android.tools.TPatchTool.java
@Override public PatchFile doPatch() throws Exception { TpatchInput tpatchInput = (TpatchInput) input; TpatchFile tpatchFile = new TpatchFile(); File hisPatchJsonFile = new File(tpatchInput.outPutJson.getParentFile(), "patchs-" + input.newApkBo.getVersionName() + ".json"); hisTpatchFolder = new File( tpatchInput.outPatchDir.getParentFile().getParentFile().getParentFile().getParentFile(), "hisTpatch"); tpatchFile.diffJson = new File(((TpatchInput) input).outPatchDir, "diff.json"); tpatchFile.patchInfo = new File(((TpatchInput) input).outPatchDir, "patchInfo.json"); final File patchTmpDir = new File(((TpatchInput) input).outPatchDir, "tpatch-tmp"); final File mainDiffFolder = new File(patchTmpDir, ((TpatchInput) input).mainBundleName); patchTmpDir.mkdirs();/*from w ww . j ava2 s. c o m*/ FileUtils.cleanDirectory(patchTmpDir); mainDiffFolder.mkdirs(); File lastPatchFile = null; readWhiteList(((TpatchInput) input).bundleWhiteList); lastPatchFile = getLastPatchFile(input.baseApkBo.getVersionName(), ((TpatchInput) input).productName, ((TpatchInput) input).outPatchDir); PatchUtils.getTpatchClassDef(lastPatchFile, bundleClassMap); Profiler.release(); Profiler.enter("unzip apks"); // unzip apk File unzipFolder = unzipApk(((TpatchInput) input).outPatchDir); final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME); final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME); Profiler.release(); ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(); String taskName = "diffBundleTask"; // Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true); //process remote bumdle if ((((TpatchInput) input).splitDiffBundle != null)) { for (final Pair<BundleBO, BundleBO> bundle : ((TpatchInput) input).splitDiffBundle) { if (bundle.getFirst() == null || bundle.getSecond() == null) { logger.warning("remote bundle is not set to splitDiffBundles"); continue; } executorServicesHelper.submitTask(taskName, new Callable<Boolean>() { @Override public Boolean call() throws Exception { TPatchTool.this.processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir); return true; } }); } } Profiler.enter("awbspatch"); Collection<File> retainFiles = FileUtils.listFiles(newApkUnzipFolder, new IOFileFilter() { @Override public boolean accept(File file) { String relativePath = PathUtils.toRelative(newApkUnzipFolder, file.getAbsolutePath()); if (pathMatcher.match(DEFAULT_NOT_INCLUDE_RESOURCES, relativePath)) { return false; } if (null != ((TpatchInput) (input)).notIncludeFiles && pathMatcher.match(((TpatchInput) (input)).notIncludeFiles, relativePath)) { return false; } return true; } @Override public boolean accept(File file, String s) { return accept(new File(file, s)); } }, TrueFileFilter.INSTANCE); executorServicesHelper.submitTask(taskName, new Callable<Boolean>() { @Override public Boolean call() throws Exception { // bundledex diff // File mianDiffDestDex = new File(mainDiffFolder, DEX_NAME); // File tmpDexFolder = new File(patchTmpDir, ((TpatchInput)input).mainBundleName + "-dex"); createBundleDexPatch(newApkUnzipFolder, baseApkUnzipFolder, mainDiffFolder, // tmpDexFolder, true); // ??bundle? if (isRetainMainBundleRes()) { copyMainBundleResources(newApkUnzipFolder, baseApkUnzipFolder, new File(patchTmpDir, ((TpatchInput) input).mainBundleName), retainFiles); } return true; } }); for (final File soFile : soFiles) { System.out.println("do patch:" + soFile.getAbsolutePath()); final String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath()); if (null != ((TpatchInput) input).notIncludeFiles && pathMatcher.match(((TpatchInput) input).notIncludeFiles, relativePath)) { continue; } executorServicesHelper.submitTask(taskName, new Callable<Boolean>() { @Override public Boolean call() throws Exception { File destFile = new File(patchTmpDir, ((TpatchInput) input).mainBundleName + "/" + relativePath); File baseSoFile = new File(baseApkUnzipFolder, relativePath); if (isBundleFile(soFile)) { processBundleFiles(soFile, baseSoFile, patchTmpDir); } else if (isFileModify(soFile, baseSoFile)) { if (destFile.exists()) { FileUtils.deleteQuietly(destFile); } if (!baseSoFile.exists() || !((TpatchInput) input).diffNativeSo) { // FileUtils.copyFile(soFile, destFile); } else { destFile = new File(destFile.getParentFile(), destFile.getName() + ".patch"); SoDiffUtils.diffSo(patchTmpDir, baseSoFile, soFile, destFile); soFileDefs.add(new SoFileDef(baseSoFile, soFile, destFile, relativePath)); } } return true; } }); } executorServicesHelper.waitTaskCompleted(taskName); executorServicesHelper.stop(); Profiler.release(); Profiler.enter("ziptpatchfile"); // zip file File patchFile = createTPatchFile(((TpatchInput) input).outPatchDir, patchTmpDir); tpatchFile.patchFile = patchFile; PatchInfo curPatchInfo = createBasePatchInfo(patchFile); Profiler.release(); Profiler.enter("createhistpatch"); BuildPatchInfos buildPatchInfos = createIncrementPatchFiles(((TpatchInput) input).productName, patchFile, ((TpatchInput) input).outPatchDir, newApkUnzipFolder, curPatchInfo, ((TpatchInput) input).hisPatchUrl); Profiler.release(); Profiler.enter("writejson"); buildPatchInfos.getPatches().add(curPatchInfo); buildPatchInfos.setBaseVersion(input.baseApkBo.getVersionName()); buildPatchInfos.setDiffBundleDex(input.diffBundleDex); FileUtils.writeStringToFile(((TpatchInput) input).outPutJson, JSON.toJSONString(buildPatchInfos)); BuildPatchInfos testForBuildPatchInfos = new BuildPatchInfos(); testForBuildPatchInfos.setBaseVersion(buildPatchInfos.getBaseVersion()); List<PatchInfo> patchInfos = new ArrayList<>(); testForBuildPatchInfos.setPatches(patchInfos); testForBuildPatchInfos.setDiffBundleDex(buildPatchInfos.isDiffBundleDex()); for (PatchInfo patchInfo : buildPatchInfos.getPatches()) { if (patchInfo.getTargetVersion().equals(buildPatchInfos.getBaseVersion())) { patchInfos.add(patchInfo); } } FileUtils.writeStringToFile(hisPatchJsonFile, JSON.toJSONString(testForBuildPatchInfos)); tpatchFile.updateJsons = new ArrayList<File>(); Map<String, List<String>> map = new HashMap<>(); for (PatchInfo patchInfo : buildPatchInfos.getPatches()) { UpdateInfo updateInfo = new UpdateInfo(patchInfo, buildPatchInfos.getBaseVersion()); // System.out.println("start to check:"+patchInfo.getTargetVersion()+"......"); // List<PatchChecker.ReasonMsg> msgs = new PatchChecker(updateInfo,bundleInfos.get(patchInfo.getTargetVersion()),new File(((TpatchInput) input).outPatchDir,patchInfo.getFileName())).check(); // map.put(patchInfo.getFileName(),msgToString(msgs)); File updateJson = new File(((TpatchInput) input).outPatchDir, "update-" + patchInfo.getTargetVersion() + ".json"); FileUtils.writeStringToFile(updateJson, JSON.toJSONString(updateInfo, true)); tpatchFile.updateJsons.add(updateJson); } // tpatchFile.patchChecker = new File(((TpatchInput) input).outPatchDir,"patch-check.json"); // FileUtils.writeStringToFile(tpatchFile.patchChecker, JSON.toJSONString(map, true)); // FileUtils.deleteDirectory(patchTmpDir); apkDiff.setBaseApkVersion(input.baseApkBo.getVersionName()); apkDiff.setNewApkVersion(input.newApkBo.getVersionName()); apkDiff.setBundleDiffResults(bundleDiffResults); boolean newApkFileExist = input.newApkBo.getApkFile().exists() && input.newApkBo.getApkFile().isFile(); if (newApkFileExist) { apkDiff.setNewApkMd5(MD5Util.getFileMD5String(input.newApkBo.getApkFile())); } apkDiff.setFileName(input.newApkBo.getApkName()); apkPatchInfos.setBaseApkVersion(input.baseApkBo.getVersionName()); apkPatchInfos.setNewApkVersion(input.newApkBo.getVersionName()); apkPatchInfos.setBundleDiffResults(diffPatchInfos); apkPatchInfos.setFileName(patchFile.getName()); apkPatchInfos.setNewApkMd5(MD5Util.getFileMD5String(patchFile)); FileUtils.writeStringToFile(tpatchFile.diffJson, JSON.toJSONString(apkDiff)); FileUtils.writeStringToFile(tpatchFile.patchInfo, JSON.toJSONString(apkPatchInfos)); FileUtils.copyFileToDirectory(tpatchFile.diffJson, ((TpatchInput) input).outPatchDir.getParentFile(), true); if (newApkFileExist) { FileUtils.copyFileToDirectory(input.newApkBo.getApkFile(), ((TpatchInput) input).outPatchDir.getParentFile(), true); } Profiler.release(); logger.warning(Profiler.dump()); return tpatchFile; }
From source file:de.tarent.maven.plugins.pkg.helper.Helper.java
public List<AuxFile> generateFilelist() throws MojoExecutionException { List<AuxFile> list = new ArrayList<AuxFile>(); for (File file : FileUtils.listFiles(getBaseBuildDir(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { list.add(new AuxFile(file.getAbsolutePath().replace(getBaseBuildDir().toString(), ""))); }//from ww w . j a v a 2 s .c o m return list; }
From source file:neembuu.uploader.NeembuuUploader.java
private void selectFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectFolderButtonActionPerformed //Open up the Open File dialog //If the user clicks cancel or close, do not continue. f.setMultiSelectionEnabled(false);//from ww w . java 2 s .c o m f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); f.setAcceptAllFileFilterUsed(false); if (f.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) { return; } File folder = f.getSelectedFile(); //getSelectedFiles() returns as File array. //We need ArrayList for efficiency. So convert array to ArrayList this.files = new ArrayList<File>( FileUtils.listFiles(folder, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)); //Same stuff as in FileDrop code in constructor if (files.size() == 1) { inputFileTextField.setText(files.get(0) + ""); } else { inputFileTextField.setText(files.size() + " " + Translation.T().nfilesselected()); } NULogger.getLogger().info("Files selected"); }
From source file:io.snappydata.hydra.cluster.SnappyTest.java
protected static String getAbsoluteJarLocation(String jarPath, final String jarName) { String absoluteJarPath = null; File baseDir = new File(jarPath); try {/*ww w .j a va 2 s.c om*/ IOFileFilter filter = new WildcardFileFilter(jarName); List<File> files = (List<File>) FileUtils.listFiles(baseDir, filter, TrueFileFilter.INSTANCE); Log.getLogWriter().info("Jar file found: " + Arrays.asList(files)); for (File file1 : files) { if (!file1.getAbsolutePath().contains("/work/")) absoluteJarPath = file1.getAbsolutePath(); } } catch (Exception e) { Log.getLogWriter().info("Unable to find " + jarName + " jar at " + jarPath + " location."); } return absoluteJarPath; }
From source file:com.peterbochs.PeterBochsDebugger.java
private void openELF(File file) { String lines = ElfUtil.getDebugLine(file); String filenames[] = lines.split("\n")[0].split(","); SourceCodeTableModel model = (SourceCodeTableModel) elfTable.getModel(); model.setDebugLine(lines);/*w w w . j ava 2 s .c om*/ for (int x = 0; x < filenames.length; x++) { // find source file Collection<File> found = FileUtils.listFiles(file.getParentFile(), FileFilterUtils.nameFileFilter(filenames[x]), TrueFileFilter.INSTANCE); if (found.size() == 0) { this.jELFFileComboBox.addItem(file.getName() + " - " + filenames[x] + " (missing)"); } else { File foundFile = (File) found.toArray()[0]; // read source code try { List<String> list = FileUtils.readLines(foundFile); model.getSourceCodes().put(foundFile.getName(), list); } catch (IOException e) { e.printStackTrace(); } this.jELFFileComboBox.addItem( file.getName() + " - " + foundFile.getAbsolutePath().substring(file.getParent().length())); // end read source code } // end find source file } jELFFileComboBoxActionPerformed(null); model.updateBreakpoint(getRealEIP()); // save history Setting.getInstance().setLastElfHistoryOpenDir(file.getParentFile().getAbsolutePath()); Setting.getInstance().save(); // end save history }