List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.geoserver.wfs.xslt.config.TransformRepository.java
/** * Deletes a transformation definition and its associated XSLT file (assuming the * latter is not shared with other transformations) * // w w w . j a v a 2 s . com * @param info * @return * @throws IOException */ public boolean removeTransformInfo(TransformInfo info) throws IOException { File infoFile = getTransformInfoFile(info.getName()); boolean result = infoFile.delete(); File xsltFile = getTransformFile(info); infoCache.removeItem(infoFile); boolean shared = false; if (xsltFile.exists()) { for (TransformInfo ti : getAllTransforms()) { File curr = getTransformFile(ti); if (curr.equals(xsltFile)) { shared = true; break; } } } if (!shared) { result = result && xsltFile.delete(); transformCache.removeItem(xsltFile); } return result; }
From source file:org.lunifera.examples.vaaclipse.demo1.e4.views.VirtualFilesystemView.java
private void createProjectTree() { demoRoot = Demo1Activator.getInstance().getSrcStore(); tree = new Tree(); tree.setSizeFull();//from www. ja v a2 s .co m tree.setImmediate(true); panel.setContent(tree); FilesystemContainer fsc = new FilesystemContainer(demoRoot, true); FileTypeResolver.addExtension("java", "java"); FileTypeResolver.addIcon("java", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/java.png")); FileTypeResolver.addExtension("xml", "xml"); FileTypeResolver.addIcon("xml", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xml.png")); FileTypeResolver.addExtension("e4xmi", "e4xmi"); FileTypeResolver.addIcon("e4xmi", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xmi.png")); FileTypeResolver.addExtension("css", "css"); FileTypeResolver.addIcon("css", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/css.png")); FileTypeResolver.addExtension("html", "html"); FileTypeResolver.addIcon("html", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/html.png")); FileTypeResolver.addIcon("image/png", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/img.png")); FileTypeResolver.addIcon("inode/directory", BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/folder.png")); tree.setContainerDataSource(fsc); tree.addListener(new ItemClickEvent.ItemClickListener() { long lastTime = 0; File lastFile; public void itemClick(final ItemClickEvent event) { if (event.getButton() == ItemClickEvent.BUTTON_LEFT) { long time = System.currentTimeMillis(); if (lastTime > 0 && time - lastTime < 300) { tree.select(event.getItemId()); FileItem fileItem = (FileItem) event.getItem(); try { for (Field f : FilesystemContainer.FileItem.class.getDeclaredFields()) { if (f.getName().equals("file")) { f.setAccessible(true); final File file = (File) f.get(fileItem); if (!file.equals(lastFile)) { eventBroker.send(Demo1Constants.OPEN_FILE, file); lastFile = file; } break; } } } catch (Exception e) { e.printStackTrace(); } } lastTime = time; } } }); // Set tree to show the 'name' property as caption for items tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME); tree.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON); for (Object id : tree.rootItemIds()) { tree.expandItem(id); } String projectName = "org.lunifera.examples.vaaclipse.demo1.e4"; File data = FileUtils.getFile(demoRoot, projectName, "data"); if (data != null) tree.expandItem(data); File rootPackage = FileUtils.getFile(demoRoot, projectName, "src"); if (rootPackage != null) tree.expandItemsRecursively(rootPackage); }
From source file:org.apache.maven.doxia.tools.DefaultSiteTool.java
private static MavenProject getModuleFromReactor(MavenProject project, List<MavenProject> reactorProjects, String module) throws IOException { File moduleBasedir = new File(project.getBasedir(), module).getCanonicalFile(); for (MavenProject reactorProject : reactorProjects) { if (moduleBasedir.equals(reactorProject.getBasedir())) { return reactorProject; }/*w w w .j av a 2 s . c om*/ } // module not found in reactor return null; }
From source file:com.glasshack.checkmymath.CheckMyMath.java
private void processPictureWhenReady(final String picturePath) { final File pictureFile = new File(picturePath); if (pictureFile.exists()) { // The picture is ready; process it. Log.e("Picture Path", picturePath); List<NameValuePair> postData = new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("file", picturePath)); postData.add(new BasicNameValuePair("answer", "1")); postData.add(new BasicNameValuePair("submit", "Submit")); String postResp = post("http://54.187.58.53/glassmath.php", postData); evaluateResponse(postResp);/*www. j a va 2 s . com*/ } else { // The file does not exist yet. Before starting the file observer, you // can update your UI to let the user know that the application is // waiting for the picture (for example, by displaying the thumbnail // image and a progress indicator). final File parentDirectory = pictureFile.getParentFile(); FileObserver observer = new FileObserver(parentDirectory.getPath(), FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) { // Protect against additional pending events after CLOSE_WRITE // or MOVED_TO is handled. private boolean isFileWritten; @Override public void onEvent(int event, String path) { if (!isFileWritten) { // For safety, make sure that the file that was created in // the directory is actually the one that we're expecting. File affectedFile = new File(parentDirectory, path); isFileWritten = affectedFile.equals(pictureFile); if (isFileWritten) { stopWatching(); // Now that the file is ready, recursively call // processPictureWhenReady again (on the UI thread). runOnUiThread(new Runnable() { @Override public void run() { processPictureWhenReady(picturePath); } }); } } } }; observer.startWatching(); } }
From source file:tools.descartes.bungee.viewer.RunResultView.java
/** * Shows the given selection in this view. */// www .j a va2s . co m public void showSelection(IWorkbenchPart sourcepart, ISelection selection) { if (selection instanceof IStructuredSelection) { Iterator<?> iterator = ((IStructuredSelection) selection).iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof IResource) { File file = ((IResource) element).getLocation().toFile(); if (!file.equals(lastRunResultFile) && RunResult.isRunresult(file)) { lastRunResultFile = file; setContentDescription(file.toString()); responseChart = null; scheduleChart = null; runResult = RunResult.read(file); update(); } } } } }
From source file:com.servoy.extension.install.LibActivationHandler.java
protected String getRelativePluginPath(File jnlp) { String result = jnlp.getName(); File current = jnlp.getParentFile(); while (current != null && !current.equals(pluginsDir)) { result = current.getName() + "/" + result; //$NON-NLS-1$ current = current.getParentFile(); }// w w w . ja v a 2 s . co m return current == null ? jnlp.getAbsolutePath() : result; }
From source file:org.apache.hadoop.sqoop.orm.CompilationManager.java
/** * Create an output jar file to use when executing MapReduce jobs *///from ww w . j av a2 s . co m public void jar() throws IOException { String jarOutDir = options.getJarOutputDir(); List<File> outDirEntries = FileListing.getFileListing(new File(jarOutDir)); String jarFilename = getJarFilename(); LOG.info("Writing jar file: " + jarFilename); findThisJar(); File jarFileObj = new File(jarFilename); if (jarFileObj.exists()) { if (!jarFileObj.delete()) { LOG.warn("Could not remove existing jar file: " + jarFilename); } } FileOutputStream fstream = null; JarOutputStream jstream = null; try { fstream = new FileOutputStream(jarFilename); jstream = new JarOutputStream(fstream); // for each input class file, create a zipfile entry for it, // read the file into a buffer, and write it to the jar file. for (File entry : outDirEntries) { if (entry.equals(jarFileObj)) { // don't include our own jar! continue; } else if (entry.isDirectory()) { // don't write entries for directories continue; } else { String fileName = entry.getName(); boolean include = fileName.endsWith(".class") && sources .contains(fileName.substring(0, fileName.length() - ".class".length()) + ".java"); if (include) { // include this file. // chomp off the portion of the full path that is shared // with the base directory where class files were put; // we only record the subdir parts in the zip entry. String fullPath = entry.getAbsolutePath(); String chompedPath = fullPath.substring(jarOutDir.length()); LOG.debug("Got classfile: " + entry.getPath() + " -> " + chompedPath); ZipEntry ze = new ZipEntry(chompedPath); jstream.putNextEntry(ze); copyFileToStream(entry, jstream); jstream.closeEntry(); } } } // put our own jar in there in its lib/ subdir String thisJarFile = findThisJar(); if (null != thisJarFile) { File thisJarFileObj = new File(thisJarFile); String thisJarBasename = thisJarFileObj.getName(); String thisJarEntryName = "lib" + File.separator + thisJarBasename; ZipEntry ze = new ZipEntry(thisJarEntryName); jstream.putNextEntry(ze); copyFileToStream(thisJarFileObj, jstream); jstream.closeEntry(); } else { // couldn't find our own jar (we were running from .class files?) LOG.warn("Could not find jar for Sqoop; MapReduce jobs may not run correctly."); } } finally { IOUtils.closeStream(jstream); IOUtils.closeStream(fstream); } }
From source file:de.u808.simpleinquest.util.DirectoryTraverser.java
private void processFile(File file) { if (!file.isHidden()) { if (file.isDirectory()) { if (traversalMode.equals(TraversalMode.FilesAndDirectories) || traversalMode.equals(TraversalMode.JustDirectories)) { this.fileProcessor.processFile(file); }//from w w w. j a v a 2s. co m if (!file.equals(this.rootDir)) { processRootDirectory(file); } } else if (traversalMode.equals(TraversalMode.JustFiles) || traversalMode.equals(TraversalMode.FilesAndDirectories)) { this.fileProcessor.processFile(file); } } else { log.info("Ignoring hidden file: " + file.getPath()); } }
From source file:org.commonjava.maven.ext.cli.CliTest.java
@Test public void checkTargetMatches() throws Exception { Cli c = new Cli(); File pom1 = temp.newFile(); File settings = writeSettings(temp.newFile()); executeMethod(c, "createSession", new Object[] { pom1, settings }); assertTrue("Session file should match", pom1.equals(((ManipulationSession) FieldUtils.readField(c, "session", true)).getPom())); }
From source file:org.piwigo.remotesync.api.sync.SyncDirectoryWalker.java
@Override protected void handleDirectoryStart(File directory, int depth, Collection<File> results) throws IOException { LegacyCache legacyCache = new LegacyCache(syncConfiguration.getUrl(), LegacyCache.getLegacyCacheFile(directory)).parseFile(); legacyCaches.put(directory, legacyCache); // do not create an album for root directory if (directory.equals(startDirectory)) return;// ww w. j a va 2 s .co m if (legacyCache.getAlbumCacheElement() != null) { logger.debug("album already in cache : " + directory); } else { Integer parentAlbumId = null; try { parentAlbumId = legacyCaches.get(directory.getParentFile()).getAlbumCacheElement().getId(); } catch (Exception e) { // FIXME : ignore me } logger.info("will create album for " + directory); legacyCache.addAlbum(createAlbum(directory, parentAlbumId)); } }