List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:com.frostwire.gui.library.LibraryCoverArt.java
/** * Async/* w ww. ja v a 2 s.com*/ * @param file */ public void setFile(final File file) { if (this.file != null && file != null && this.file.equals(file)) { return; } this.file = file; Thread t = new Thread(new Runnable() { public void run() { Image image = retrieveImage(file); if (file != null && file.equals(LibraryCoverArt.this.file)) { setPrivateImage(image); } } }, "Cover Art extract"); t.setDaemon(true); t.start(); }
From source file:edu.isi.wings.portal.controllers.ComponentController.java
public String listComponentDirectory(String cid, String path) { try {/*w w w.j a v a 2 s . c o m*/ ArrayList<FileAttrib> files = new ArrayList<FileAttrib>(); String loc = cc.getComponentLocation(cid); if (loc != null) { if (path != null) loc = loc + "/" + path; File floc = new File(loc); if (floc.isDirectory()) { for (File f : floc.listFiles()) { if (!f.equals(floc) && !f.getName().equals(".DS_Store")) files.add(new FileAttrib(f.getName(), (path != null ? path + "/" : "") + f.getName(), f.isFile())); } } } return json.toJson(files); } catch (Exception e) { e.printStackTrace(); return null; } finally { cc.end(); dc.end(); prov.end(); } }
From source file:org.apache.camel.component.file.FileOperations.java
public boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException { ObjectHelper.notNull(endpoint, "endpoint"); // always create endpoint defined directory if (endpoint.isAutoCreate() && !endpoint.getFile().exists()) { if (LOG.isTraceEnabled()) { LOG.trace("Building starting directory: " + endpoint.getFile()); }//from www. j a va 2 s .c om endpoint.getFile().mkdirs(); } if (ObjectHelper.isEmpty(directory)) { // no directory to build so return true to indicate ok return true; } File endpointPath = endpoint.getFile(); File target = new File(directory); File path; if (absolute) { // absolute path path = target; } else if (endpointPath.equals(target)) { // its just the root of the endpoint path path = endpointPath; } else { // relative after the endpoint path String afterRoot = ObjectHelper.after(directory, endpointPath.getPath() + File.separator); if (ObjectHelper.isNotEmpty(afterRoot)) { // dir is under the root path path = new File(endpoint.getFile(), afterRoot); } else { // dir is relative to the root path path = new File(endpoint.getFile(), directory); } } if (path.isDirectory() && path.exists()) { // the directory already exists return true; } else { if (LOG.isTraceEnabled()) { LOG.trace("Building directory: " + path); } return path.mkdirs(); } }
From source file:org.apache.solr.core.DirectoryFactory.java
public void cleanupOldIndexDirectories(final String dataDirPath, final String currentIndexDirPath) { File dataDir = new File(dataDirPath); if (!dataDir.isDirectory()) { log.debug("{} does not point to a valid data directory; skipping clean-up of old index directories.", dataDirPath);//from w w w .j a v a 2 s. co m return; } final File currentIndexDir = new File(currentIndexDirPath); File[] oldIndexDirs = dataDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { String fileName = file.getName(); return file.isDirectory() && !file.equals(currentIndexDir) && (fileName.equals("index") || fileName.matches(INDEX_W_TIMESTAMP_REGEX)); } }); if (oldIndexDirs == null || oldIndexDirs.length == 0) return; // nothing to do (no log message needed) log.info("Found {} old index directories to clean-up under {}", oldIndexDirs.length, dataDirPath); for (File dir : oldIndexDirs) { String dirToRmPath = dir.getAbsolutePath(); try { if (deleteOldIndexDirectory(dirToRmPath)) { log.info("Deleted old index directory: {}", dirToRmPath); } else { log.warn("Delete old index directory {} failed.", dirToRmPath); } } catch (IOException ioExc) { log.error("Failed to delete old directory {} due to: {}", dir.getAbsolutePath(), ioExc.toString()); } } }
From source file:org.freeplane.plugin.script.ScriptingConfiguration.java
private void addScript(final File file, final Map<File, Script> addOnScriptMap) { final Script scriptConfig = addOnScriptMap.get(file); if (scriptConfig != null && !scriptConfig.active) { LogUtils.info("skipping deactivated " + scriptConfig); return;/*w ww . j a va 2s . c o m*/ } final String menuTitle = disambiguateMenuTitle(getOrCreateMenuTitle(file, scriptConfig)); try { menuTitleToPathMap.put(menuTitle, file.getAbsolutePath()); final ScriptMetaData metaData = createMetaData(file, menuTitle, scriptConfig); menuTitleToMetaDataMap.put(menuTitle, metaData); final File parentFile = file.getParentFile(); if (parentFile.equals(ScriptResources.getBuiltinScriptsDir())) { metaData.setPermissions(ScriptingPermissions.getPermissiveScriptingPermissions()); } } catch (final IOException e) { LogUtils.warn("problems with script " + file.getAbsolutePath(), e); menuTitleToPathMap.remove(menuTitle); menuTitleToMetaDataMap.remove(menuTitle); } }
From source file:com.microsoft.tfs.client.common.wit.QueryDocumentService.java
public QueryDocument getQueryDocumentForFile(final File file) { Check.notNull(file, "file"); //$NON-NLS-1$ synchronized (queriesLock) { for (final Iterator<QueryDocumentWrapper> it = queries.iterator(); it.hasNext();) { final QueryDocumentWrapper wrapper = it.next(); if (file.equals(wrapper.queryDocument.getFile())) { log.trace("getQueryDocumentForFile(" //$NON-NLS-1$ + file.getAbsolutePath() + "): returning cached QueryDocument: " //$NON-NLS-1$ + wrapper.queryDocument); return wrapper.queryDocument; }/* w w w . j a v a 2 s.c om*/ } final QueryDocument queryDocument = new QueryDocument(workItemClient); queryDocument.setFile(file); queryDocument.load(); queries.add(new QueryDocumentWrapper(queryDocument)); log.trace("getQueryDocumentForFile(" //$NON-NLS-1$ + file.getAbsolutePath() + "): returning new QueryDocument: " //$NON-NLS-1$ + queryDocument); return queryDocument; } }
From source file:eu.stratosphere.test.util.TestBase2.java
private File createAndRegisterTempFile(String fileName) throws IOException { File baseDir = new File(System.getProperty("java.io.tmpdir")); File f = new File(baseDir, fileName); if (f.exists()) { deleteRecursively(f);/*from w w w. ja v a2 s .c om*/ } 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); this.tempFiles.add(parentToDelete); return f; }
From source file:com.atlassian.clover.CloverInstr.java
private boolean processArgs(String[] args) { cfg = new JavaInstrumentationConfig(); try {/* www .j a va 2 s .co m*/ int i = 0; while (i < args.length) { if (args[i].equals("-i") || args[i].equals("--initstring")) { i++; cfg.setInitstring(args[i]); } else if (args[i].equals("-r") || args[i].equals("--relative")) { cfg.setRelative(true); } else if (args[i].equals("-s") || args[i].equals("--srcdir")) { i++; inDir = (new File(args[i])).getAbsoluteFile(); } else if (args[i].equals("-d") || args[i].equals("--destdir")) { i++; outDir = (new File(args[i])).getAbsoluteFile(); } else if (args[i].equals("-e") || args[i].equals("--encoding")) { i++; cfg.setEncoding(args[i]); } else if (args[i].equals("--recordTestResults")) { i++; cfg.setRecordTestResults(Boolean.valueOf(args[i]).booleanValue()); } else if (args[i].equals("-dc") || args[i].equals("--distributedCoverage")) { i++; cfg.setDistributedConfig(new DistributedConfig(args[i])); } else if (args[i].equalsIgnoreCase("--dontFullyQualifyJavaLang")) { cfg.setFullyQualifyJavaLang(false); } else if (args[i].equals("-p") || args[i].equals("--flushpolicy")) { i++; String policy = args[i]; try { cfg.setFlushPolicyFromString(policy); } catch (CloverException e) { usage(e.getMessage()); return false; } } else if (args[i].equals("-f") || args[i].equals("--flushinterval")) { i++; try { cfg.setFlushInterval(Integer.parseInt(args[i])); if (cfg.getFlushInterval() <= 0) { throw new NumberFormatException(); } } catch (NumberFormatException e) { usage("expecting a positive integer value for flush interval"); return false; } } else if (args[i].equals("-u") || args[i].equals("--useclass")) { i++; log.warn("the useclass parameter has been deprecated and will be ignored."); } else if (args[i].equals("--source")) { i++; cfg.setSourceLevel(args[i]); } else if (args[i].equals("--instrumentation")) { i++; String instr = args[i]; cfg.setInstrStrategy(instr); } else if (args[i].equals("--instrlevel")) { i++; String instr = args[i]; cfg.setInstrLevelStrategy(instr); } else if (args[i].equals("--instrlambda")) { try { i++; cfg.setInstrumentLambda(LambdaInstrumentation.valueOf(args[i].toUpperCase(Locale.ENGLISH))); } catch (IllegalArgumentException ex) { usage("Invalid value: " + args[i] + ". " + ex.getMessage()); return false; } } else if (args[i].equals("-v") || args[i].equals("--verbose")) { Logger.setVerbose(true); } else if (args[i].equals("-mc") || args[i].equals("--methodContext")) { // expected in the format: name=value, where value may have one or more '=' i++; try { cfg.addMethodContext(parseContextDef(args[i])); } catch (CloverException e) { usage("Could not parse custom method context definition: " + args[i] + ". " + e.getMessage()); return false; } } else if (args[i].equals("-sc") || args[i].equals("--statementContext")) { // expected in the format: name=value, where value may have one or more '=' i++; try { cfg.addStatementContext(parseContextDef(args[i])); } catch (CloverException e) { usage("Could not parse custom statement context definition: " + args[i] + ". " + e.getMessage()); return false; } } else if (args[i].endsWith(".java")) { srcFiles.add(args[i]); } i++; } if (cfg.getInitString() == null) { try { cfg.createDefaultInitStringDir(); } catch (CloverException e) { usage("No --initstring value supplied, and default location could not be created: " + e.getMessage()); return false; } } if (inDir == null && srcFiles.size() == 0) { usage("No source files specified"); return false; } else if (outDir == null) { usage("No Destination dir specified"); return false; } else if ((cfg.getFlushPolicy() == InstrumentationConfig.INTERVAL_FLUSHING || cfg.getFlushPolicy() == InstrumentationConfig.THREADED_FLUSHING) && cfg.getFlushInterval() == 0) { usage("When using either \"interval\" or \"threaded\" flushpolicy, a flushinterval must be specified."); return false; } else { if (inDir != null) { if (inDir.equals(outDir)) { usage("Srcdir and destdir cannot be the same."); return false; } // check to see that indir is not a parent of outdir File outParent = outDir.getParentFile(); while (outParent != null) { if (outParent.equals(inDir)) { usage("Cannot specify a destdir that is a nested dir of the srcdir."); return false; } outParent = outParent.getParentFile(); } if (cfg.getFlushPolicy() == InstrumentationConfig.DIRECTED_FLUSHING && cfg.getFlushInterval() != 0) { log.warn( "ignoring flushinterval since flushpolicy is directed. To specify interval flushing, use -p interval."); } } return true; } } catch (ArrayIndexOutOfBoundsException e) { usage("Missing a parameter."); } return false; }
From source file:com.greenpepper.maven.runner.CommandLineRunner.java
private URL[] buildRuntimeClasspaths() throws IOException { final Map<String, File> actualClasspaths = getActualClasspaths(); List<URL> classpaths = new ArrayList<URL>(); for (Artifact artifact : artifacts) { File artifactFile = actualClasspaths.get(artifact.getFile().getName()); if (artifactFile == null || !artifactFile.equals(artifact.getFile())) { logger.debug(String.format("Artifact: %s (%s)", artifact, artifact.getFile())); classpaths.add(artifact.getFile().toURI().toURL()); }//w w w .j av a 2s . com } // Add project folders, if any. String buildOutputDirectory = project.getBuild().getOutputDirectory(); classpaths.add(new File(buildOutputDirectory).toURI().toURL()); @SuppressWarnings("unchecked") List<Plugin> buildPlugins = project.getBuildPlugins(); for (Plugin plugin : buildPlugins) { if (StringUtils.equals(PLUGIN_KEY, plugin.getKey())) { Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if (configuration != null) { Xpp3Dom fixtureOutputDirectory = configuration.getChild("fixtureOutputDirectory"); String relativeDirectory = fixtureOutputDirectory.getValue(); if (!StringUtils.isEmpty(relativeDirectory)) { File directory = FileUtils.getFile(project.getBasedir(), relativeDirectory); classpaths.add(directory.toURI().toURL()); } } break; } } logger.debug("Classpath used: " + classpaths.toString(), null); return toArray(classpaths, URL.class); }
From source file:org.apache.james.sieverepository.file.SieveFileRepository.java
private boolean isActive(File file, File activeFile) { return null != activeFile && activeFile.equals(file); }