List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:com.ephesoft.gxt.foldermanager.server.FolderManagerServiceImpl.java
@Override public List<String> copyFiles(List<String> copyFilesList, String currentFolderPath) throws UIException { List<String> resultList = new ArrayList<String>(); for (String filePath : copyFilesList) { try {// w ww. ja v a 2 s .com File srcFile = new File(filePath); if (srcFile.exists()) { String fileName = srcFile.getName(); File copyFile = new File(currentFolderPath + File.separator + fileName); if (copyFile.exists()) { if (copyFile.equals(srcFile)) { int counter = 0; while (copyFile.exists()) { String newFileName; if (counter == 0) { newFileName = FolderManagementConstants.COPY + FolderManagementConstants.SPACE + FolderManagementConstants.OF + FolderManagementConstants.SPACE + fileName; } else { newFileName = FolderManagementConstants.COPY + FolderManagementConstants.SPACE + FolderManagementConstants.OPENING_BRACKET + counter + FolderManagementConstants.CLOSING_BRACKET + FolderManagementConstants.SPACE + FolderManagementConstants.OF + FolderManagementConstants.SPACE + fileName; } counter++; copyFile = new File(currentFolderPath + File.separator + newFileName); } } else { resultList.add(fileName); } } if (srcFile.isFile()) { FileUtils.copyFile(srcFile, copyFile, false); } else { FileUtils.forceMkdir(copyFile); FileUtils.copyDirectory(srcFile, copyFile, false); } } else { resultList.add(srcFile.getName()); } } catch (IOException e) { throw new UIException( FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_COPY_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION); } } return resultList; }
From source file:org.opencastproject.util.FileSupport.java
private static File determineDestination(File targetLocation, File sourceLocation, boolean overwrite) throws IOException { File dest = null;/*from w ww . ja v a 2s .c o m*/ // Source location exists if (sourceLocation.exists()) { // Is the source file/directory readable if (sourceLocation.canRead()) { // If a directory... if (targetLocation.isDirectory()) // Create a destination file within it, with the same name of the source target dest = new File(targetLocation, sourceLocation.getName()); else // targetLocation is either a normal file or doesn't exist dest = targetLocation; // Source and target locations can not be the same if (sourceLocation.equals(dest)) throw new IOException("Source and target locations must be different"); // Search the first existing parent of the target file, to check if it can be written // getParentFile can return null even though there *is* a parent file, if the file is not absolute // That's the reason why getAbsoluteFile is used here for (File iter = dest.getAbsoluteFile(); iter != null; iter = iter.getParentFile()) if (iter.exists()) { if (iter.canWrite()) break; else throw new IOException("Destination " + dest + "cannot be written/modified"); } // Check the target file can be overwritten if (dest.exists() && !dest.isDirectory() && !overwrite) throw new IOException("Destination " + dest + " already exists"); } else throw new IOException(sourceLocation + " cannot be read"); } else throw new IOException("Source " + sourceLocation + " does not exist"); return dest; }
From source file:com.vaadin.tests.tb3.ScreenshotTB3Test.java
protected void compareScreen(WebElement element, String identifier) throws IOException { if (identifier == null || identifier.isEmpty()) { throw new IllegalArgumentException("Empty identifier not supported"); }/*ww w .ja va 2s .c o m*/ File mainReference = getScreenshotReferenceFile(identifier); List<File> referenceFiles = findReferenceAndAlternatives(mainReference); List<File> failedReferenceFiles = new ArrayList<>(); for (File referenceFile : referenceFiles) { boolean match = false; if (element == null) { // Full screen match = testBench(driver).compareScreen(referenceFile); } else { // Only the element match = customTestBench(driver).compareScreen(element, referenceFile); } if (match) { // There might be failure files because of retries in TestBench. deleteFailureFiles(getErrorFileFromReference(referenceFile)); break; } else { failedReferenceFiles.add(referenceFile); } } File referenceToKeep = null; if (failedReferenceFiles.size() == referenceFiles.size()) { // Ensure we use the correct browser version (e.g. if running IE11 // and only an IE 10 reference was available, then mainReference // will be for IE 10, not 11) String originalName = getScreenshotReferenceName(identifier); File exactVersionFile = new File(originalName); if (!exactVersionFile.equals(mainReference)) { // Rename png+html to have the correct version File correctPng = getErrorFileFromReference(exactVersionFile); File producedPng = getErrorFileFromReference(mainReference); File correctHtml = htmlFromPng(correctPng); File producedHtml = htmlFromPng(producedPng); producedPng.renameTo(correctPng); producedHtml.renameTo(correctHtml); referenceToKeep = exactVersionFile; screenshotFailures.add(exactVersionFile.getName()); } else { // All comparisons failed, keep the main error image + HTML screenshotFailures.add(mainReference.getName()); referenceToKeep = mainReference; } } // Remove all PNG/HTML files we no longer need (failed alternative // references or all error files (PNG/HTML) if comparison succeeded) for (File failedAlternative : failedReferenceFiles) { File failurePng = getErrorFileFromReference(failedAlternative); if (failedAlternative != referenceToKeep) { // Delete png + HTML deleteFailureFiles(failurePng); } } if (referenceToKeep != null) { File errorPng = getErrorFileFromReference(referenceToKeep); enableAutoswitch(new File(errorPng.getParentFile(), errorPng.getName() + ".html")); } }
From source file:com.ning.maven.plugins.duplicatefinder.ClasspathDescriptor.java
private void addDirectory(File element, String parentPackageName, File directory) { if (addCached(element)) { return;//from ww w . j a va 2 s. c om } List classes = new ArrayList(); List resources = new ArrayList(); File[] files = directory.listFiles(); String pckgName = (element.equals(directory) ? null : (parentPackageName == null ? "" : parentPackageName + ".") + directory.getName()); if ((files != null) && (files.length > 0)) { for (int idx = 0; idx < files.length; idx++) { if (files[idx].isDirectory() && !IGNORED_LOCAL_DIRECTORIES.contains(files[idx].getName().toUpperCase())) { addDirectory(element, pckgName, files[idx]); } else if (files[idx].isFile()) { if ("class".equals(FilenameUtils.getExtension(files[idx].getName()))) { String className = (pckgName == null ? "" : pckgName + ".") + FilenameUtils.getBaseName(files[idx].getName()); classes.add(className); addClass(className, element); } else { String resourcePath = (pckgName == null ? "" : pckgName.replace('.', '/') + "/") + files[idx].getName(); resources.add(resourcePath); addResource(resourcePath, element); } } } } CACHED_BY_ELEMENT.put(element, new Cached(classes, resources)); }
From source file:mergedoc.core.MergeManager.java
/** * ??????//from w w w . j a va2 s . c o m * @throws MergeDocException ????? * @throws IOException ???? * @throws ExecutionException * @throws InterruptedException */ public void validate() throws MergeDocException, IOException, InterruptedException, ExecutionException { // API ?? File docDir = pref.getDocDirectory(); if (docDir != null && docDir.getPath().length() > 0) { File rootFile = new File(docDir, "allclasses-frame.html"); if (!rootFile.exists()) { throw new MergeDocException( "?? API ???????\n" + "??? allclasses-frame.html ?\n" + "?????????"); } } // ?? File inFile = pref.getInputArchive(); if (inFile == null || inFile.getPath().equals("")) { throw new MergeDocException("???????"); } if (entrySize() == 0) { throw new MergeDocException( "?????????"); } // ?? File outFile = pref.getOutputArchive(); if (outFile == null || outFile.getPath().equals("")) { throw new MergeDocException("???????"); } if (outFile.equals(inFile)) { throw new MergeDocException( "??????????\n" + "?????????"); } if (pref.getOutputArchive().exists()) { if (!outFile.canWrite()) { throw new MergeDocException( "??????????\n" + "?????????"); } } else { try { outFile.createNewFile(); outFile.delete(); } catch (IOException e) { throw new MergeDocException( "?????????", e); } } }
From source file:com.mortardata.project.EmbeddedMortarProject.java
String syncEmbeddedProjectWithMirror(Git gitMirror, CredentialsProvider cp, String targetBranch, String committer) throws GitAPIException, IOException { // checkout the target branch gitUtil.checkout(gitMirror, targetBranch); // clear out the mirror directory contents (except .git and .gitkeep) File localBackingGitRepoPath = gitMirror.getRepository().getWorkTree(); for (File f : FileUtils.listFilesAndDirs(localBackingGitRepoPath, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".gitkeep")), FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".git")))) { if (!f.equals(localBackingGitRepoPath)) { logger.debug("Deleting existing mirror file" + f.getAbsolutePath()); FileUtils.deleteQuietly(f);/*from ww w .ja va 2 s . c o m*/ } } // copy everything from the embedded project List<File> manifestFiles = getFilesAndDirsInManifest(); for (File fileToCopy : manifestFiles) { if (!fileToCopy.exists()) { logger.warn("Can't find file or directory " + fileToCopy.getCanonicalPath() + " referenced in manifest file. Ignoring."); } else if (fileToCopy.isDirectory()) { FileUtils.copyDirectoryToDirectory(fileToCopy, localBackingGitRepoPath); } else { FileUtils.copyFileToDirectory(fileToCopy, localBackingGitRepoPath); } } // add everything logger.debug("git add ."); gitMirror.add().addFilepattern(".").call(); // remove missing files (deletes) logger.debug("git add -u ."); gitMirror.add().setUpdate(true).addFilepattern(".").call(); // commit it logger.debug("git commit"); RevCommit revCommit = gitMirror.commit().setCommitter(committer, committer) .setMessage("mortar development snapshot commit").call(); return ObjectId.toString(revCommit); }
From source file:org.apache.flink.test.util.AbstractTestBase.java
public File createAndRegisterTempFile(String fileName) throws IOException { File baseDir = new File(System.getProperty("java.io.tmpdir")); File f = new File(baseDir, this.getClass().getName() + "-" + fileName); if (f.exists()) { deleteRecursively(f);//from w w w .jav a 2 s . c o m } 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:org.dcm4che2.tool.dcmdir.DcmDir.java
public int addFile(File f) throws IOException { f = f.getCanonicalFile();//from w w w . j ava 2 s. com // skip adding DICOMDIR if (f.equals(file)) return 0; int n = 0; if (f.isDirectory()) { File[] fs = f.listFiles(); for (int i = 0; i < fs.length; i++) { n += addFile(fs[i]); } return n; } DicomInputStream in = new DicomInputStream(f); in.setHandler(new StopTagInputHandler(Tag.PixelData)); DicomObject dcmobj = in.readDicomObject(); DicomObject patrec = ap.makePatientDirectoryRecord(dcmobj); DicomObject styrec = ap.makeStudyDirectoryRecord(dcmobj); DicomObject serrec = ap.makeSeriesDirectoryRecord(dcmobj); DicomObject instrec = ap.makeInstanceDirectoryRecord(dcmobj, dicomdir.toFileID(f)); DicomObject rec = writer().addPatientRecord(patrec); if (rec == patrec) { ++n; } rec = writer().addStudyRecord(rec, styrec); if (rec == styrec) { ++n; } rec = writer().addSeriesRecord(rec, serrec); if (rec == serrec) { ++n; } if (n == 0 && checkDuplicate) { String iuid = dcmobj.getString(Tag.MediaStorageSOPInstanceUID); if (dicomdir.findInstanceRecord(rec, iuid) != null) { System.out.print('D'); return 0; } } writer().addChildRecord(rec, instrec); System.out.print('.'); return n + 1; }
From source file:org.apache.druid.segment.loading.LocalDataSegmentPusher.java
@Override public DataSegment push(final File dataSegmentFile, final DataSegment segment, final boolean useUniquePath) throws IOException { final File baseStorageDir = config.getStorageDirectory(); final File outDir = new File(baseStorageDir, this.getStorageDir(segment, useUniquePath)); log.info("Copying segment[%s] to local filesystem at location[%s]", segment.getIdentifier(), outDir.toString());/*from w ww . j ava 2s . co m*/ if (dataSegmentFile.equals(outDir)) { long size = 0; for (File file : dataSegmentFile.listFiles()) { size += file.length(); } return createDescriptorFile(segment.withLoadSpec(makeLoadSpec(outDir.toURI())).withSize(size) .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)), outDir); } final File tmpOutDir = new File(baseStorageDir, makeIntermediateDir()); log.info("Creating intermediate directory[%s] for segment[%s]", tmpOutDir.toString(), segment.getIdentifier()); FileUtils.forceMkdir(tmpOutDir); try { final File tmpIndexFile = new File(tmpOutDir, INDEX_FILENAME); final long size = compressSegment(dataSegmentFile, tmpIndexFile); final File tmpDescriptorFile = new File(tmpOutDir, DESCRIPTOR_FILENAME); DataSegment dataSegment = createDescriptorFile( segment.withLoadSpec(makeLoadSpec(new File(outDir, INDEX_FILENAME).toURI())).withSize(size) .withBinaryVersion(SegmentUtils.getVersionFromDir(dataSegmentFile)), tmpDescriptorFile); FileUtils.forceMkdir(outDir); final File indexFileTarget = new File(outDir, tmpIndexFile.getName()); final File descriptorFileTarget = new File(outDir, tmpDescriptorFile.getName()); if (!tmpIndexFile.renameTo(indexFileTarget)) { throw new IOE("Failed to rename [%s] to [%s]", tmpIndexFile, indexFileTarget); } if (!tmpDescriptorFile.renameTo(descriptorFileTarget)) { throw new IOE("Failed to rename [%s] to [%s]", tmpDescriptorFile, descriptorFileTarget); } return dataSegment; } finally { FileUtils.deleteDirectory(tmpOutDir); } }
From source file:nl.toolforge.karma.core.cmd.impl.AbstractBuildCommand.java
public void executeDelete(File dir) throws CommandException { if (project == null) { project = getProjectInstance();// w w w. ja va 2 s . co m } try { // <delete> // Delete delete = new Delete(); delete.setProject(project); if (dir.equals(new File("."))) { throw new KarmaRuntimeException("We don't do that stuff here ..."); } delete.setDir(dir); delete.execute(); } catch (RuntimeException r) { throw new CommandException(CommandException.BUILD_FAILED, new Object[] { r.getMessage() }); } }