List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.geogig.geoserver.web.repository.DirectoryChooser.java
private boolean isSubfile(File root, File selection) { if (selection == null || "".equals(selection.getPath())) return false; if (selection.equals(root)) return true; return isSubfile(root, selection.getParentFile()); }
From source file:com.threewks.thundr.view.velocity.ServletContextResourceLoader.java
/** * Checks to see if a resource has been deleted, moved or modified. * /*from ww w. j av a 2s . c o m*/ * @param resource Resource The resource to check for modification * @return boolean True if the resource has been modified */ @Override public boolean isSourceModified(Resource resource) { String rootPath = servletContext.getRealPath("/"); if (rootPath == null) { // rootPath is null if the servlet container cannot translate the // virtual path to a real path for any reason (such as when the // content is being made available from a .war archive) return false; } // first, try getting the previously found file String fileName = resource.getName(); File cachedFile = getCachedFile(rootPath, fileName); if (!cachedFile.exists()) { /* then the source has been moved and/or deleted */ return true; } /* * check to see if the file can now be found elsewhere * before it is found in the previously saved path */ File currentFile = new File(rootPath, fileName); /* if the current is the cached and it is readable */ if (cachedFile.equals(currentFile) && cachedFile.canRead()) { /* then (and only then) do we compare the last modified values */ return (cachedFile.lastModified() != resource.getLastModified()); } else { /* * we found a new file for the resource * or the resource is no longer readable. */ return true; } }
From source file:org.everit.osgi.dev.maven.util.FileManager.java
public boolean copyFile(final File source, final File target, final CopyModeType copyMode) throws MojoExecutionException { boolean fileChange = false; if (CopyModeType.FILE.equals(copyMode)) { if (target.exists() && Files.isSymbolicLink(target.toPath())) { target.delete();// w w w . ja v a 2 s.com } fileChange = overCopyFile(source, target); } else { try { if (target.exists()) { Path targetPath = target.toPath(); if (Files.isSymbolicLink(targetPath)) { Path symbolicLinkTarget = Files.readSymbolicLink(targetPath); File symbolicLinkTargetFile = symbolicLinkTarget.toFile(); if (!symbolicLinkTargetFile.equals(source)) { target.delete(); createSymbolicLink(target, source); fileChange = true; } } else { target.delete(); createSymbolicLink(target, source); fileChange = true; } } else { createSymbolicLink(target, source); fileChange = true; } } catch (IOException e) { throw new MojoExecutionException( "Could not check the target of the symbolic link " + target.getAbsolutePath(), e); } } return fileChange; }
From source file:eu.stratosphere.pact.test.util.TestBase2.java
public String createTempFile(String fileName, String contents) throws IOException { File baseDir = new File(System.getProperty("java.io.tmpdir")); File f = new File(baseDir, fileName); if (f.exists()) { deleteRecursively(f);/*from ww w . ja v a 2 s. com*/ } File parentToDelete = f; while (true) { File parent = parentToDelete.getParentFile(); if (parent == null) { throw new IOException("Missed temp dir while traversing parents of a temp file."); } if (parent.equals(baseDir)) { break; } parentToDelete = parent; } Files.createParentDirs(f); Files.write(contents, f, Charsets.UTF_8); this.tempFiles.add(parentToDelete); return "file://" + f.getAbsolutePath(); }
From source file:org.openoffice.maven.idl.IdlBuilderMojo.java
/** * Guess the root module of the OOo extension API. * //from w ww . ja v a 2 s . c o m * <p>The folders containing the IDL files has to follow the * same hierarchy than the IDL modules declared in the IDL files.</p> * * <p>The root module is the path of IDL folders which are the only * children of their parent. A valid IDL folder respects the * regular expression defined by {@link #IDENTIFIER_REGEX}.</p> * * @return the guessed module or an empty string if it can't be guessed. */ private String guessRootModule() { File idlDir = ConfigurationManager.getIdlDir(); int childCount = 1; File currentFile = idlDir; while (childCount == 1) { // List only the valid children String[] children = currentFile.list(new PackageNameFilter()); childCount = children.length; if (childCount == 1) { currentFile = new File(currentFile, children[0]); } } if (currentFile.equals(idlDir)) { this.getLog().warn("no children found in " + idlDir); return ""; } String modulePath = currentFile.getPath().substring(idlDir.getPath().length() + 1); modulePath = FilenameUtils.separatorsToUnix(modulePath); String rootModule = modulePath.replaceAll("/", "."); return rootModule; }
From source file:com.akman.excel.view.frmExportExcel.java
private void btnAddFileActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnAddFileActionPerformed {//GEN-HEADEREND:event_btnAddFileActionPerformed JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel files", "xlsx", "xlsm", "xlt", "xlsb", "xltx", "xltm", "xls", "xlt", "xls"); chooser.setFileFilter(filter);/* w w w. ja va2 s . c om*/ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setDialogTitle("Select The Image"); chooser.setMultiSelectionEnabled(false); int res = chooser.showOpenDialog(null); if (res == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); // checking file extension. it must be excel file. if (file.equals(filter)) { JOptionPane.showMessageDialog(null, "Wrong File selected", "ERROR", JOptionPane.ERROR_MESSAGE); return; } fileName = file.getAbsolutePath(); txtPath.setText(fileName); } }
From source file:jscover.report.MainTest.java
@Test public void shouldRunXMLSummaryReport() throws IOException { given(config.getReportFormat()).willReturn(ReportFormat.XMLSUMMARY); given(config.getVersion()).willReturn("version"); final File jsonDirectory = new File("jsonDir"); given(config.getJsonDirectory()).willReturn(jsonDirectory); String json = "json"; given(ioUtils.loadFromFileSystem(new File(jsonDirectory, "jscoverage.json"))).willReturn(json); SortedMap<String, FileData> list = new TreeMap<String, FileData>(); List<Integer> lines = new ArrayList<Integer>(); for (int i = 0; i <= 42; i++) lines.add(i);/* ww w . j av a2s .c o m*/ SortedMap<Integer, List<BranchData>> branches = new TreeMap<Integer, List<BranchData>>(); List<Integer> functions = new ArrayList<Integer>(); list.put("/test.js", new FileData("/test.js", lines, functions, branches)); given(jsonDataMerger.jsonToMap(json)).willReturn(list); main.runMain(new String[] {}); TypeSafeMatcher<File> fileMatcher = new TypeSafeMatcher<File>() { @Override protected boolean matchesSafely(File file) { return file.equals(jsonDirectory); } public void describeTo(Description description) { } }; TypeSafeMatcher<Coverable> coverableMatcher = new TypeSafeMatcher<Coverable>() { @Override protected boolean matchesSafely(Coverable coverable) { return coverable.getCodeLineCount() == 42; } public void describeTo(Description description) { } }; verify(xmlSummary).saveSummary(argThat(coverableMatcher), argThat(fileMatcher), argThat(is("version"))); verifyZeroInteractions(exitHelper); }
From source file:org.apache.webdav.ui.WebdavSystemView.java
/** * Returns the parent directory of <code>dir</code>. * @param dir the <code>File</code> being queried * @return the parent directory of <code>dir</code>, or * <code>null</code> if <code>dir</code> is <code>null</code> *///from w w w. j a va 2 s. c om public File getParentDirectory(File dir) { //System.out.println("dir : " + dir); if (dir == null) { return null; } else if (dir.equals(this.homedir)) { return this.homedir; } else { //System.out.println("getParentDirectory : calling getParentFile" + dir); return dir.getParentFile(); } }
From source file:com.teotigraphix.caustk.library.LibraryManager.java
/** * Loads the entire <code>libraries</code> directory into the manager. * <p>/*from w ww.j a v a 2 s . com*/ * Each sub directory located within the <code>libraries</code> directory * will be created as a {@link Library} instance. */ @Override public void load() { Collection<File> dirs = FileUtils.listFilesAndDirs(librariesDirectory, new IOFileFilter() { @Override public boolean accept(File arg0, String arg1) { return false; } @Override public boolean accept(File arg0) { return false; } }, new IOFileFilter() { @Override public boolean accept(File file, String name) { if (file.getParentFile().getName().equals("libraries")) return true; return false; } @Override public boolean accept(File file) { if (file.getParentFile().getName().equals("libraries")) return true; return false; } }); for (File directory : dirs) { if (directory.equals(librariesDirectory)) continue; loadLibrary(directory.getName()); } }
From source file:es.uvigo.ei.sing.adops.datatypes.ProjectExperiment.java
@Override public boolean isClean() { if (this.hasResult()) { return false; } else {/*from ww w.j a v a 2 s. co m*/ final FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.equals(ProjectExperiment.this.getNotesFile()) || pathname.equals(ProjectExperiment.this.getPropertiesFile()) || pathname.equals(ProjectExperiment.this.getFastaFile()) || pathname.equals(ProjectExperiment.this.getNamesFile())) { return false; } else if (pathname.equals(ProjectExperiment.this.getFilesFolder())) { final List<File> files = Arrays.asList(pathname.listFiles()); int countOutputFolders = 0; if (files.contains(new File(pathname, TCoffeeOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; if (files.contains(new File(pathname, MrBayesOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; if (files.contains(new File(pathname, CodeMLOutput.OUTPUT_FOLDER_NAME))) countOutputFolders++; return files.size() != countOutputFolders; } return true; } }; return this.getFolder().listFiles(filter).length == 0; } }