Java Code Examples for java.io.File.equals()

The following are Jave code examples for showing how to use equals() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VirtualHook   File: PackageInstallerSession.java   View Source Code Vote up 6 votes
private void validateInstallLocked() throws PackageManagerException {
    mResolvedBaseFile = null;
    mResolvedStagedFiles.clear();
    File[] addedFiles = this.mResolvedStageDir.listFiles();
    if (addedFiles == null || addedFiles.length == 0) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, "No packages staged");
    }
    for (File addedFile : addedFiles) {
        if (!addedFile.isDirectory()) {
            final String targetName = "base.apk";
            final File targetFile = new File(mResolvedStageDir, targetName);
            if (!addedFile.equals(targetFile)) {
                addedFile.renameTo(targetFile);
            }
            mResolvedBaseFile = targetFile;
            mResolvedStagedFiles.add(targetFile);
        }
    }
    if (mResolvedBaseFile == null) {
        throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
                "Full install must include a base package");
    }
}
 
Example 2
Project: atlas   File: ZipUtils.java   View Source Code Vote up 6 votes
private static String getAbsFileName(String baseDir, File realFileName) {
    File real = realFileName;
    File base = new File(baseDir);
    String ret = real.getName();
    while (true) {
        real = real.getParentFile();
        if (real == null) {
            break;
        }
        if (real.equals(base)) {
            break;
        } else {
            ret = real.getName() + "/" + ret;
        }
    }
    return ret;
}
 
Example 3
Project: mobile-store   File: AppUpdateStatusService.java   View Source Code Vote up 6 votes
/**
 * There could be multiple apks with the same hash, provided by different repositories.
 * This method looks for all matching records in the database. It then asks each of these
 * {@link Apk} instances where they expect to be downloaded. If they expect to be downloaded
 * to {@param apkPath} then that instance is returned.
 *
 * If no files have a matching hash, or only those which don't belong to the correct repo, then
 * this will return null.
 */
@Nullable
private Apk findApkMatchingHash(File apkPath) {

    // NOTE: This presumes SHA256 is the only supported hash. It seems like that is an assumption
    // in more than one place in the F-Droid client. If this becomes a problem in the future, we
    // can query the Apk table for `SELECT DISTINCT hashType FROM fdroid_apk` and then we can just
    // try each of the hash types that have been specified in the metadata. Seems a bit overkill
    // at the time of writing though.
    String hash = Utils.getBinaryHash(apkPath, "sha256");

    List<Apk> apksMatchingHash = ApkProvider.Helper.findApksByHash(this, hash);
    Utils.debugLog(TAG, "Found " + apksMatchingHash.size() + " apk(s) matching the hash " + hash);

    for (Apk apk : apksMatchingHash) {
        if (apkPath.equals(ApkCache.getApkDownloadPath(this, Uri.parse(apk.getUrl())))) {
            return apk;
        }
    }

    return null;
}
 
Example 4
Project: directory-ldap-api   File: DefaultSchemaLdifExtractor.java   View Source Code Vote up 5 votes
/**
 * Calculates the destination file.
 *
 * @param resource the source file
 * @return the destination file's parent directory
 */
private File getDestinationFile( File resource )
{
    File parent = resource.getParentFile();
    Deque<String> fileComponentStack = new ArrayDeque<>();
    fileComponentStack.push( resource.getName() );

    while ( parent != null )
    {
        if ( "schema".equals( parent.getName() ) )
        {
            // All LDIF files besides the schema.ldif are under the 
            // schema/schema base path. So we need to add one more 
            // schema component to all LDIF files minus this schema.ldif
            fileComponentStack.push( "schema" );

            return assembleDestinationFile( fileComponentStack );
        }

        fileComponentStack.push( parent.getName() );

        if ( parent.equals( parent.getParentFile() ) || parent.getParentFile() == null )
        {
            throw new IllegalStateException( I18n.err( I18n.ERR_08005 ) );
        }

        parent = parent.getParentFile();
    }

    throw new IllegalStateException( I18n.err( I18n.ERR_08006 ) );
}
 
Example 5
Project: openjdk-jdk10   File: bug6698013.java   View Source Code Vote up 5 votes
public File[] getFiles(File dir, boolean hide_hidden) {
    if (dir.equals(bug6698013.root)) {
        return new File[]{bug6698013.rootFile, bug6698013.subdir};
    }

    if (dir.equals(bug6698013.subdir)) {
        return new File[]{bug6698013.subdirFile};
    }

    return null;
}
 
Example 6
Project: incubator-netbeans   File: GitUtils.java   View Source Code Vote up 5 votes
public static String getRelativePath (File repo, final File file) {
    StringBuilder relativePath = new StringBuilder(""); //NOI18N
    File parent = file;
    if (!parent.equals(repo)) {
        while (parent != null && !parent.equals(repo)) {
            relativePath.insert(0, "/").insert(0, parent.getName()); //NOI18N
            parent = parent.getParentFile();
        }
        if (parent == null) {
            throw new IllegalArgumentException(file.getAbsolutePath() + " is not under " + repo.getAbsolutePath());
        }
        relativePath.deleteCharAt(relativePath.length() - 1);
    }
    return relativePath.toString();
}
 
Example 7
Project: javaide   File: ManifestMerger.java   View Source Code Vote up 5 votes
private static File insertSourceMarkers(@NonNull Node node, @Nullable File currentFile) {
    for (int i = 0; i < node.getChildNodes().getLength(); i++) {
        Node child = node.getChildNodes().item(i);
        short nodeType = child.getNodeType();
        if (nodeType == Node.ELEMENT_NODE
                || nodeType == Node.COMMENT_NODE
                || nodeType == Node.DOCUMENT_NODE
                || nodeType == Node.CDATA_SECTION_NODE) {
            File file = MergerXmlUtils.getFileFor(child);
            if (file != null && !file.equals(currentFile)) {
                i += insertSourceMarker(node, child, file, false);
                currentFile = file;
            }

            currentFile = insertSourceMarkers(child, currentFile);
        }
    }

    Node lastElement = node.getLastChild();
    while (lastElement != null && lastElement.getNodeType() == Node.TEXT_NODE) {
        lastElement = lastElement.getPreviousSibling();
    }
    if (lastElement != null && lastElement.getNodeType() == Node.ELEMENT_NODE) {
        File parentFile = MergerXmlUtils.getFileFor(node);
        File lastFile = MergerXmlUtils.getFileFor(lastElement);
        if (lastFile != null && parentFile != null && !parentFile.equals(lastFile)) {
            insertSourceMarker(node, lastElement, parentFile, true);
            currentFile = parentFile;
        }
    }

    return currentFile;
}
 
Example 8
Project: parabuild-ci   File: MyTableModel.java   View Source Code Vote up 5 votes
private Object[] getColumnNames() {
    MyTreeNode selectedTreeNode = FileExplorer.selectedTreeNode;

    if (selectedTreeNode == null) {
        return null;
    }

    File selectedDir = (File) selectedTreeNode.getUserObject();

    if (selectedDir.equals(new File(FileExplorer.MY_COMPUTER_FOLDER_PATH))) {
        return columnNamesMyComputer;
    } else {
        return columnNamesFile;
    }
}
 
Example 9
Project: vogar   File: LocalTarget.java   View Source Code Vote up 5 votes
@Override public void push(File local, File remote) {
    if (remote.equals(local)) {
        return;
    }
    // if the user dir exists, cp would copy the files to the wrong place
    if (remote.exists()) {
        throw new IllegalStateException();
    }
    new Command(run.log, "cp", "-r", local.toString(), remote.toString()).execute();
}
 
Example 10
Project: stynico   File: CmdRMD.java   View Source Code Vote up 5 votes
public void run() {
	//myLog.l(Log.INFO, "RMD executing");
	String param = getParameter(input);
	File toRemove;
	String errString = null;
	mainblock: {
		if(param.length() < 1) {
			errString = "550 Invalid argument\r\n";
			break mainblock;
		}
		toRemove = inputPathToChrootedFile(sessionThread.getWorkingDir(), param);
		if(violatesChroot(toRemove)) {
			errString = "550 Invalid name or chroot violation\r\n";
			break mainblock;
		}
		if(!toRemove.isDirectory()) {
			errString = "550 Can't RMD a non-directory\r\n";
			break mainblock;
		}
		if(toRemove.equals(new File("/"))) {
			errString = "550 Won't RMD the root directory\r\n";
			break mainblock;
		}
		if(!recursiveDelete(toRemove)) {
			errString = "550 Deletion error, possibly incomplete\r\n";
			break mainblock;
		}
	}
	if(errString != null) {
		sessionThread.writeString(errString);
		//myLog.l(Log.INFO, "RMD failed: " + errString.trim());
	} else {
		sessionThread.writeString("250 Removed directory\r\n");
	}
	//myLog.l(Log.DEBUG, "RMD finished");
}
 
Example 11
Project: lazycat   File: AccessLogValve.java   View Source Code Vote up 5 votes
/**
 * Move a current but rotated log file back to the unrotated one. Needed if
 * date stamp inclusion is deferred to rotation time.
 */
private void restore() {
	File newLogFile = getLogFile(false);
	File rotatedLogFile = getLogFile(true);
	if (rotatedLogFile.exists() && !newLogFile.exists() && !rotatedLogFile.equals(newLogFile)) {
		try {
			if (!rotatedLogFile.renameTo(newLogFile)) {
				log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile));
			}
		} catch (Throwable e) {
			ExceptionUtils.handleThrowable(e);
			log.error(sm.getString("accessLogValve.renameFail", rotatedLogFile, newLogFile), e);
		}
	}
}
 
Example 12
Project: incubator-netbeans   File: MavenBinaryForSourceQueryImpl.java   View Source Code Vote up 5 votes
private Res checkRoot(File root, File source, File test) {
    if (source != null && source.equals(root)) {
        return new Res(false, project.getLookup().lookup(NbMavenProjectImpl.class));
    }
    if (test != null && test.equals(root)) {
        return new Res(true, project.getLookup().lookup(NbMavenProjectImpl.class));
    }
    return null;
}
 
Example 13
Project: jbake-rtl-jalaali   File: Crawler.java   View Source Code Vote up 5 votes
public String getPathToRoot(File sourceFile) {
	File rootPath = new File(contentPath);
	File parentPath = sourceFile.getParentFile();
	int parentCount = 0;
	while (!parentPath.equals(rootPath)) {
		parentPath = parentPath.getParentFile();
		parentCount++;
	}
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < parentCount; i++) {
		sb.append("../");
	}
	return sb.toString();
}
 
Example 14
Project: Pogamut3   File: IncludeDir.java   View Source Code Vote up 5 votes
private boolean acceptDir(File pathToDir) {
	String absolute = RewriteUtils.makeUniform(pathToDir.getAbsolutePath());
	for (String exclude : excludeDirs) {
		if (absolute.endsWith(exclude)) return false;
	}
	if (subdirs) return true;
	return pathToDir.equals(dir);
}
 
Example 15
Project: incubator-netbeans   File: FXMLTemplateWizardIterator.java   View Source Code Vote up 5 votes
@Override
public boolean isRoot(File file) {
    for (File root : roots) {
        if (root.equals(file)) {
            return true;
        }
    }
    return false;
}
 
Example 16
Project: Logisim   File: Projects.java   View Source Code Vote up 5 votes
public static Project findProjectFor(File query) {
	for (Project proj : openProjects) {
		Loader loader = proj.getLogisimFile().getLoader();
		if (loader == null)
			continue;
		File f = loader.getMainFile();
		if (query.equals(f))
			return proj;
	}
	return null;
}
 
Example 17
Project: incubator-netbeans   File: DirectoryChooserUI.java   View Source Code Vote up 5 votes
private void updateCompletions() {
    if (showPopupCompletion) {
        final String name = normalizeFile(getFileName());
        int slash = name.lastIndexOf(File.separatorChar);
        if (slash != -1) {
            String prefix = name.substring(0, slash + 1);
            File dir = getFileChooser().getFileSystemView().createFileObject(prefix);
            File[] children;
            synchronized (listFilesWorker) {
                if (!dir.equals(lastDir)) {
                    if (completionPopup != null) {
                        completionPopup.setDataList(new Vector<File>(0));
                        completionPopup.detach();
                        completionPopup = null;
                    }
                    listFilesWorker.d = dir;
                    listFilesTask.schedule(0);
                    return;
                } else {
                    children = lastChildren;
                }
            }
            if (children != null) {
                Vector<File> list = buildList(name, children, 20);
                if(completionPopup == null) {
                    completionPopup = new FileCompletionPopup(fileChooser, filenameTextField, list);
                } else if (completionPopup.isShowing() ||
                        (showPopupCompletion && fileChooser.isShowing())) {
                    completionPopup.setDataList(list);
                }
                if (fileChooser.isShowing() && !completionPopup.isShowing()) {
                    java.awt.Point los = filenameTextField.getLocation();
                    int popX = los.x;
                    int popY = los.y + filenameTextField.getHeight() - 6;
                    completionPopup.showPopup(filenameTextField, popX, popY);
                }
            }
        }
    }
}
 
Example 18
Project: incubator-netbeans   File: RunToCursorActionProvider.java   View Source Code Vote up 4 votes
@Override
public void engineAdded (DebuggerEngine engine) {
    JPDADebugger debugger = engine.lookupFirst(null, JPDADebugger.class);
    if (debugger == null) {
        return;
    }
    Integer num;
    synchronized (debuggerEngines) {
        num = debuggerEngines.get(debugger);
        if (num != null) {
            debuggerEngines.put(debugger, num+1);
            return ;
        } else {
            debuggerEngines.put(debugger, 1);
        }
    }
    //Project p = debuggedProject;
    Map setupMap = engine.lookupFirst(null, Map.class);
    if (setupMap != null) {
        File baseDir = (File) setupMap.get("baseDir");
        if (baseDir != null) {
            Project prj = null;
            LineBreakpoint lb = null;
            synchronized (projectBreakpoints) {
                for (Project p : projectBreakpoints.keySet()) {
                    if (baseDir.equals(FileUtil.toFile(p.getProjectDirectory()))) {
                        prj = p;
                        lb = projectBreakpoints.get(p);
                        break;
                    }
                }
            }
            if (lb != null) {
                synchronized (debuggerBreakpoints) {
                    debuggerBreakpoints.put(debugger, Pair.of(lb, prj));
                }
            }
        }
    }
    //debuggingProjects.put(p, debugger);
    debugger.addPropertyChangeListener (
        JPDADebugger.PROP_STATE,
        this
    );
}
 
Example 19
Project: incubator-netbeans   File: CompareSnapshotsAction.java   View Source Code Vote up 4 votes
private void updateOKButton() {
            String s1f = getSnapshot1Filename();
            String s2f = getSnapshot2Filename();

            if ((s1f.length() > 0) && (s2f.length() > 0)) {
                // filenames not empty string
                final File s1 = new File(s1f);
                final File s2 = new File(s2f);

                if (s1.exists() && s1.isFile() && s2.exists() && s2.isFile()) {
                    // files exist
                    if (s1.equals(s2)) {
                        // comparing the same snapshot
                        hintLabel.setText(Bundle.CompareSnapshotsAction_ComparingSameSnapshotsMsg());
                        okButton.setEnabled(false);
                    } else {
                        // comparing different snapshots
                        new NBSwingWorker(true) {
                            private String hintStr;
                            private boolean enabledOk;
                            
                            @Override
                            protected void doInBackground() {
                                ResultsManager rm = ResultsManager.getDefault();
                                FileObject s1fo = FileUtil.toFileObject(s1);
                                FileObject s2fo = FileUtil.toFileObject(s2);
                                int s1t = rm.getSnapshotType(s1fo);
                                int s2t = rm.getSnapshotType(s2fo);

                                if (s1t == LoadedSnapshot.SNAPSHOT_TYPE_UNKNOWN ||
                                    s2t == LoadedSnapshot.SNAPSHOT_TYPE_UNKNOWN) {
                                    // Unknown snapshot types or not .nps snapshots
                                    hintStr = Bundle.CompareSnapshotsAction_InvalidFilesMsg();
                                    okButton.setEnabled(false);
                                } else if (s1t != s2t) {
                                    // snapshot types don't match
                                    hintStr = Bundle.CompareSnapshotsAction_DifferentSnapshotsTypeMsg();
                                    enabledOk = false;
//                                } else if ((s1t != LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_ALLOCATIONS)
//                                       && (s1t != LoadedSnapshot.SNAPSHOT_TYPE_MEMORY_LIVENESS)) {
//                                    // not a memory snapshot
//                                    hintStr = Bundle.CompareSnapshotsAction_OnlyMemorySnapshotsMsg();
//                                    enabledOk = false;
                                } else {
                                    ProfilingSettings s1s = rm.getSnapshotSettings(s1fo);
                                    ProfilingSettings s2s = rm.getSnapshotSettings(s2fo);
                                    if (s1s == null || s2s == null) {
                                        // Snapshot settings not available (should not happen)
                                        hintStr = Bundle.CompareSnapshotsAction_InvalidFilesMsg();
                                        okButton.setEnabled(false);
                                    } else if (s1s.getAllocTrackEvery() != s2s.getAllocTrackEvery()) {
                                        // memory snapshots have different track every N objects
                                        // TODO: is this branch OK for CPU snapshots? Seems to work fine.
                                        hintStr = Bundle.CompareSnapshotsAction_DifferentObjectsCountsMsg();
                                        enabledOk = false;
                                    } else {
                                        // comparable snapshots (from the hint point of view!)
                                        hintStr = " "; // NOI18N
                                        enabledOk = areComparableSnapshots(s1fo, s2fo);
                                    }
                                }
                            }

                            @Override
                            protected void done() {
                                hintLabel.setText(hintStr);
                                okButton.setEnabled(enabledOk);
                            }
                        }.execute();
                    }
                } else {
                    // files don't exist
                    hintLabel.setText(Bundle.CompareSnapshotsAction_InvalidFilesMsg());
                    okButton.setEnabled(false);
                }
            } else {
                // filenames are empty string
                hintLabel.setText(Bundle.CompareSnapshotsAction_SelectSnapshotsString());
                okButton.setEnabled(false);
            }
        }
 
Example 20
Project: incubator-netbeans   File: ModuleSelector.java   View Source Code Vote up 4 votes
private Boolean checkSelected(File dir, File file) throws BuildException {
    if (file.isDirectory()) {
        log("Skipping directory: " + file, Project.MSG_VERBOSE);
        return null;
    }
    
    String module = null;
    if (file.getName().endsWith(".jar")) {
        try (JarFile jar = new JarFile(file)) {
            Manifest m = jar.getManifest();
            if (m != null) {
                module = m.getMainAttributes().getValue("OpenIDE-Module"); // NOI18N
                if (module == null && !isExt(file)) {
                    module = m.getMainAttributes().getValue("Bundle-SymbolicName"); // NOI18N
                    int semicolon = module == null ? -1 : module.indexOf(';');
                    if (semicolon >= 0) {
                        module = module.substring(0, semicolon);
                    }
                }
            }
        } catch (IOException ex) {
            throw new BuildException("Problem with " + file + ": " + ex, ex, getLocation());
        }
    }

    String name = file.getName();
    File p = file.getParentFile();
    for(;;) {

        if (new File(p, "update_tracking").isDirectory()) { // else includeClusters does not work
            String cluster = p.getName();
            
            if (!includeClusters.isEmpty() && !clusterMatch(includeClusters, cluster)) {
                log("Not included cluster: " + cluster + " for " + file, Project.MSG_VERBOSE);
                return null;
            }

            if (includeClusters.isEmpty() && excludeClusters.contains(cluster)) {
                log("Excluded cluster: " + cluster + " for " + file, Project.MSG_VERBOSE);
                return null;
            }
        }
        
        if (module == null && fileToOwningModule != null) {
            module = fileToOwningModule.get(name);
        }
        
        if (dir.equals(p)) {
            break;
        }
        name = p.getName() + '/' + name;
        p = p.getParentFile();
    }
    
    if (module == null) {
        log("No module in: " + file, Project.MSG_VERBOSE);
        return null;
    }
    int slash = module.indexOf('/');
    if (slash >= 0) {
        module = module.substring(0, slash);
    }
    
    if (excludeModules.contains(module)) {
        log("Excluded module: " + file, Project.MSG_VERBOSE);
        return false;
    }

    log("Accepted file: " + file, Project.MSG_VERBOSE);
    return true;
}