List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:com.github.blindpirate.gogradle.common.GoSourceCodeFilter.java
private static boolean isVendorDirectoryOfProject(File dir, File projectDir) { return VENDOR_DIRECTORY.equals(dir.getName()) && projectDir.equals(dir.getParentFile()); }
From source file:org.apache.lenya.util.FileUtil.java
/** * Deletes all dirs up to stop dir or if dirs in hirachy are not empty. * /*from ww w. j a va 2 s . c o m*/ * @param start File to delete the parents of. The File itself is not deleted. * @param stop Stop deleting at this dir. This dir is not deleted. * @throws IllegalArgumentException If stop is not a dir or start is not a descending sibling of * stop dir. */ public static void deleteParentDirs(File start, File stop) throws IllegalArgumentException { if (!stop.isDirectory()) throw new IllegalArgumentException("Stop dir '" + stop.getAbsolutePath() + "' is not a directory"); if (!start.getAbsolutePath().startsWith(stop.getAbsolutePath())) throw new IllegalArgumentException("Start dir '" + start.getAbsolutePath() + "' is not a descending sibling of stop directory '" + stop.getAbsolutePath() + "'."); File parent = start.getParentFile(); while (!parent.equals(stop) && parent.delete()) parent = parent.getParentFile(); }
From source file:org.eclipse.jdt.ls.core.internal.JVMConfigurator.java
public static boolean configureDefaultVM(Preferences preferences) throws CoreException { if (preferences == null) { return false; }//ww w . ja v a 2s . c om String javaHome = preferences.getJavaHome(); if (javaHome != null) { File jvmHome = new File(javaHome); if (jvmHome.isDirectory()) { IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall(); File location = defaultVM.getInstallLocation(); if (!location.equals(jvmHome)) { IVMInstall vm = findVM(jvmHome); if (vm == null) { IVMInstallType installType = JavaRuntime .getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE); long unique = System.currentTimeMillis(); while (installType.findVMInstall(String.valueOf(unique)) != null) { unique++; } String vmId = String.valueOf(unique); VMStandin vmStandin = new VMStandin(installType, vmId); String name = StringUtils.defaultIfBlank(jvmHome.getName(), "JRE"); vmStandin.setName(name); vmStandin.setInstallLocation(jvmHome); vm = vmStandin.convertToRealVM(); } JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor()); JDTUtils.setCompatibleVMs(vm.getId()); return true; } } } return false; }
From source file:org.jts.docGenerator.util.DirectoryScanner.java
private static void compareAndPrint(List<File> list1, List<File> list2) { if (list1.size() != list2.size()) { System.out.println(" Results pairs had different sizes!" + list1.size() + " vs " + list2.size()); System.out.println("list 1 contents: "); for (File file : list1) { System.out.println(file.getName()); }/* w w w . j ava 2 s.c o m*/ System.out.println("List 2 contents: "); for (File file : list2) { System.out.println(file.getName()); } } else { for (int i = 0; i < list1.size(); ++i) { File file1 = list1.get(i); File file2 = list2.get(i); if (!file1.equals(file2)) { System.out.println("Unequal files: " + file1.getName() + ", " + file2.getName()); } System.out.println("Equal files: " + file1.getName() + ", " + file2.getName()); } } }
From source file:com.gs.obevo.db.testutil.DirectoryAssert.java
public static String getRelativePath(File childFile, File baseFile) { if (childFile == null) { throw new IllegalArgumentException("childFile was not a child of the base file"); } else if (childFile.equals(baseFile)) { return ""; } else {/*from www.ja v a 2 s.c o m*/ return getRelativePath(childFile.getParentFile(), baseFile) + "/" + childFile.getName(); } }
From source file:org.apache.hadoop.hdfs.server.namenode.NNUpgradeUtil.java
/** * Perform any steps that must succeed across all storage dirs/JournalManagers * involved in an upgrade before proceeding onto the actual upgrade stage. If * a call to any JM's or local storage dir's doPreUpgrade method fails, then * doUpgrade will not be called for any JM. The existing current dir is * renamed to previous.tmp, and then a new, empty current dir is created. * * @param conf configuration for creating {@link EditLogFileOutputStream} * @param sd the storage directory to perform the pre-upgrade procedure. * @throws IOException in the event of error *//*from w w w . j a v a2 s . c o m*/ static void doPreUpgrade(Configuration conf, StorageDirectory sd) throws IOException { LOG.info("Starting upgrade of storage directory " + sd.getRoot()); // rename current to tmp renameCurToTmp(sd); final File curDir = sd.getCurrentDir(); final File tmpDir = sd.getPreviousTmp(); List<String> fileNameList = IOUtils.listDirectory(tmpDir, new FilenameFilter() { @Override public boolean accept(File dir, String name) { return dir.equals(tmpDir) && name.startsWith(NNStorage.NameNodeFile.EDITS.getName()); } }); for (String s : fileNameList) { File prevFile = new File(tmpDir, s); File newFile = new File(curDir, prevFile.getName()); Files.createLink(newFile.toPath(), prevFile.toPath()); } }
From source file:org.jahia.configuration.deployers.jboss.DriverDeploymentHelper.java
public static boolean deploy(File targetServerDirectory, File driverJar) throws IOException { String driverKey = getDriverKey(driverJar.getName()); String driverType = getDriverType(driverKey, driverJar.getName()); File targetDir = new File(targetServerDirectory, "/modules/org/jahia/jdbc/" + driverType + "/main"); boolean inPlace = targetDir.equals(driverJar.getParentFile()); if (targetDir.isDirectory()) { // special case for the second JAR of the Oracle driver // second test is for the case driver JAR is already in-place (used only in configurators to configure module.xml) if (!"oracle".equals(driverType) && !inPlace) { FileUtils.cleanDirectory(targetDir); }/*from w w w . j a v a2 s. c om*/ } else { if (!targetDir.mkdirs()) { throw new IOException("Unable to create target directory: " + targetDir); } } if (!inPlace) { FileUtils.copyFileToDirectory(driverJar, targetDir); } File moduleXml = new File(targetDir, "module.xml"); String existingContent = moduleXml.isFile() ? FileUtils.readFileToString(moduleXml, FILE_CONTENT_ENCODING) : null; FileUtils.writeStringToFile(moduleXml, generateModuleXmlContent(existingContent, driverJar.getName(), driverType), FILE_CONTENT_ENCODING); return Boolean.TRUE; }
From source file:de.tudarmstadt.lt.lm.app.GenerateNgrams.java
public static File generateNgrams(File src_dir, AbstractStringProvider prvdr, int from_cardinality, int to_cardinality, boolean overwrite) { final File ngram_file = new File(src_dir, String.format("%s.%s", src_dir.getName(), "ngrams.txt.gz")); int n_b = from_cardinality, n_e = to_cardinality; if (ngram_file.exists()) { LOG.info("Output file already exists: '{}'.", ngram_file.getAbsolutePath()); if (overwrite) { ngram_file.delete();//from w w w . j a va 2s . com LOG.info("Overwriting file: '{}'.", ngram_file.getAbsolutePath()); } else return ngram_file; } File[] src_files = src_dir.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isFile() && f.getName().endsWith(".txt") && (!f.equals(ngram_file)); } }); String[] basenames = new String[src_files.length]; for (int i = 0; i < basenames.length; i++) basenames[i] = src_files[i].getName(); LOG.info(String.format("Reading txt files from dir: '%s'; Files: %s.", src_dir.getAbsolutePath(), StringUtils.abbreviate(Arrays.toString(basenames), 200))); LOG.info(String.format("Writing ngrams to file: '%s'.", ngram_file.getAbsolutePath())); PrintWriter pw = null; try { pw = new PrintWriter( new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(ngram_file)), "UTF-8")); } catch (IOException e) { LOG.error("Could not open writer for file: '{}'.", ngram_file.getAbsolutePath(), e); return null; } long num_ngrams = 0l; List<String>[] ngrams = null; for (int i = 0; i < src_files.length; i++) { File src_file = src_files[i]; LOG.info("Processing file {} / {} ('{}')", i + 1, src_files.length, src_file.getAbsolutePath()); long num_ngrams_f = 0l; try { LineIterator liter = new LineIterator( new BufferedReader(new InputStreamReader(new FileInputStream(src_file), "UTF-8"))); int lc = 0; while (liter.hasNext()) { if (++lc % 1000 == 0) LOG.debug("Processing line {} ({})", lc, src_file); String line = liter.next(); for (String sentence : prvdr.splitSentences(line)) { for (int n = n_b; n <= n_e; n++) { ngrams = null; try { List<String> tokens = prvdr.tokenizeSentence(sentence); if (tokens.isEmpty()) continue; ngrams = AbstractLanguageModel.getNgramSequence(tokens, n); } catch (Exception e) { LOG.warn( "Could not get ngram of cardinality {} from String '{}' in line '{}' from file '{}'.", n, StringUtils.abbreviate(line, 100), lc, src_file.getAbsolutePath()); continue; } for (List<String> ngram : ngrams) pw.println(StringUtils.join(ngram, " ")); pw.flush(); num_ngrams_f += ngrams.length; } } } liter.close(); } catch (Exception e) { LOG.warn("Could not read file '{}'.", src_file.getAbsolutePath(), e); } LOG.debug("Generated {} ngrams from file {}.", num_ngrams_f, src_file); num_ngrams += num_ngrams_f; } if (pw != null) pw.close(); LOG.info("Generated {} ngrams.", num_ngrams); return ngram_file; }
From source file:net.landora.video.info.file.FileHasher.java
public static void checkDirectory(File dir) throws IOException { for (File file : dir.listFiles()) { if (file.isHidden()) { continue; }/*w w w.ja va2 s . c om*/ if (file.isDirectory()) { checkDirectory(file); } else { String extension = ExtensionUtils.getExtension(file); if (!ExtensionUtils.isVideoExtension(extension)) { continue; } FileInfo info = FileInfoManager.getInstance().getFileInfo(file); VideoMetadata md = MetadataProvidersManager.getInstance().getMetadata(info); if (md == null) { continue; } file = file.getCanonicalFile(); String filename = getOutputFilename(md) + "." + extension; File outputFile = new File(getOutputFolder(md), filename); outputFile.getParentFile().mkdirs(); outputFile = outputFile.getCanonicalFile(); if (!outputFile.equals(file)) { if (outputFile.exists()) { } else { FileUtils.moveFile(file, outputFile); } } } } }
From source file:org.eclipse.smila.binarystorage.persistence.io.BssIOUtils.java
/** * Delete empty parent folders.//w w w . j a v a 2 s . c o m * * @param leafFolder * the leaf folder */ public static void deleteEmptyParentFolders(File leafFolder) { while (leafFolder != null && !leafFolder.equals(_root)) { final String[] elements = leafFolder.list(); if (elements == null || elements.length > 0) { // folder does not exist anymore or is not empty. return; } leafFolder.delete(); leafFolder = leafFolder.getParentFile(); } }