List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:gov.redhawk.sca.efs.server.tests.FileSystemImplTest.java
/** * Test method for//from ww w.j a v a 2 s. c om * {@link gov.redhawk.efs.sca.server.internal.FileSystemImpl#list(java.lang.String)} * . */ @Test public void testList() { try { Assert.assertEquals(0, this.fileSystem.list("empty").length); FileInformationType[] result = this.fileSystem.list("*"); Assert.assertEquals(FileSystemImplTest.root.list().length, result.length); for (final FileInformationType type : result) { final File subFile = new File(FileSystemImplTest.root, type.name); if (subFile.isDirectory()) { Assert.assertEquals(FileType.DIRECTORY, type.kind); } else { Assert.assertEquals(FileType.PLAIN, type.kind); } } result = this.fileSystem.list("subFolder/test*"); final File subRoot = new File(FileSystemImplTest.root, "subFolder"); Assert.assertEquals(subRoot.list(new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { if (!dir.equals(subRoot)) { return false; } return FilenameUtils.wildcardMatch(name, "test*"); } }).length, result.length); for (final FileInformationType type : result) { final File subFile = new File(subRoot, type.name); if (subFile.isDirectory()) { Assert.assertEquals(FileType.DIRECTORY, type.kind); } else { Assert.assertEquals(FileType.PLAIN, type.kind); } } result = this.fileSystem.list("testFile.t??"); Assert.assertEquals(1, result.length); Assert.assertEquals(FileType.PLAIN, result[0].kind); } catch (final FileException e) { Assert.fail(e.getMessage() + ": " + e.msg); } catch (final InvalidFileName e) { Assert.fail(e.getMessage() + ": " + e.msg); } }
From source file:edu.mayo.qdm.webapp.rest.store.Md5HashFileSystemResolver.java
private void deleteDirectory(File directory) { if (this.isDirEmpty(directory)) { File parent = directory.getParentFile(); directory.delete();//w ww . java 2 s .com if (!parent.equals(this.getDataDir())) { this.deleteDirectory(parent); } } }
From source file:com.ephesoft.dcma.gwt.foldermanager.server.FolderManagerServiceImpl.java
@Override public Boolean copyFiles(List<String> copyFilesList, String currentFolderPath) throws GWTException { for (String filePath : copyFilesList) { try {//from w w w .j av a 2 s .c om File srcFile = new File(filePath); if (srcFile.exists()) { srcFile.getName(); 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_OF + fileName; } else { newFileName = FolderManagementConstants.COPY_OF + FolderManagementConstants.OPENING_BRACKET + counter + FolderManagementConstants.CLOSING_BRACKET + FolderManagementConstants.SPACE + fileName; } counter++; copyFile = new File(currentFolderPath + File.separator + newFileName); } } else { throw new GWTException( FolderManagementMessages.CANNOT_COMPLETE_COPY_PASTE_OPERATION_AS_THE_FILE_FOLDER + fileName + FolderManagementMessages.ALREADY_EXISTS); } } if (srcFile.isFile()) { FileUtils.copyFile(srcFile, copyFile, false); } else { FileUtils.forceMkdir(copyFile); FileUtils.copyDirectory(srcFile, copyFile, false); } } else { throw new GWTException( FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_COPY_PASTE_OPERATION_FILE_NOT_FOUND + FolderManagementConstants.QUOTES + srcFile.getName() + FolderManagementConstants.QUOTES); } } catch (IOException e) { LOGGER.error( FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_COPY_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION + e.getMessage()); throw new GWTException( FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_COPY_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION, e); } } return true; }
From source file:net.gsantner.opoc.ui.FilesystemDialogAdapter.java
@Override public void onBindViewHolder(@NonNull UiFilesystemDialogViewHolder holder, int position) { final File file = _adapterDataFiltered.get(position); final File fileParent = file.getParentFile() == null ? new File("/") : file.getParentFile(); holder.title.setText(fileParent.equals(_currentFolder) ? file.getName() : ".."); holder.title.setTextColor(ContextCompat.getColor(_context, _dopt.primaryTextColor)); holder.description/* www.j a va 2 s.co m*/ .setText(fileParent.equals(_currentFolder) ? fileParent.getAbsolutePath() : file.getAbsolutePath()); holder.description.setTextColor(ContextCompat.getColor(_context, _dopt.secondaryTextColor)); holder.image.setImageResource(file.isDirectory() ? _dopt.folderImage : _dopt.fileImage); if (_currentSelection.contains(file)) { holder.image.setImageResource(_dopt.selectedItemImage); } holder.image.setColorFilter( ContextCompat.getColor(_context, _currentSelection.contains(file) ? _dopt.accentColor : _dopt.secondaryTextColor), android.graphics.PorterDuff.Mode.SRC_ATOP); //holder.itemRoot.setBackgroundColor(ContextCompat.getColor(_context, // _currentSelection.contains(file) ? _dopt.primaryColor : _dopt.backgroundColor)); holder.image.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { Toast.makeText(_context, file.getAbsolutePath(), Toast.LENGTH_SHORT).show(); return true; } }); holder.itemRoot.setTag(new TagContainer(file, position)); holder.itemRoot.setOnClickListener(this); holder.itemRoot.setOnLongClickListener(this); }
From source file:com.xtructure.xnet.demos.art.TwoNodeSimulation.java
/** * Creates a new Main simulation object and starts the simulation. A gui is * generated. The network and inputs used in the simulation are specified by * the given networkFile and inputFile./* w ww. j a va 2 s . c o m*/ * * @param networkFile * xml file specifying the network this simulation will use. * @param inputFile * xml file specifying the input this simulation will use. * @throws XMLStreamException * the xML stream exception * @throws IOException * Signals that an I/O exception has occurred. */ public TwoNodeSimulation(File networkFile, File inputFile) throws XMLStreamException, IOException { super(SIM_ID); File networkDir = networkFile.getParentFile(); File inputDir = inputFile.getParentFile(); if (!networkDir.equals(RESOURCE_DIR)) { loadConfigFiles(networkDir, inputFile, networkFile); } if (!inputDir.equals(RESOURCE_DIR) && !inputDir.equals(networkDir)) { loadConfigFiles(inputDir, inputFile, networkFile); } network = XmlReader.read(networkFile, NetworkImpl.XML_BINDING); networkNodeViz = network.getNodeVisualization(); networkLinkViz = network.getLinkVisualization(); inputs = XmlReader.read(inputFile, NetworkImpl.XML_BINDING); inputsNodeViz = inputs.getNodeVisualization(); addComponent(network); addComponent(networkNodeViz); addComponent(networkLinkViz); addComponent(inputs); addComponent(inputsNodeViz); XId[] outputSourceIds = inputs.getSourceIds().toArray(new XId[0]); XId[] inputTargetIds = network.getTargetIds().toArray(new XId[0]); Map<XId, XId> outputInputMap = new HashMap<XId, XId>(); for (int i = 0; i < outputSourceIds.length; i++) { outputInputMap.put(outputSourceIds[i], inputTargetIds[i]); } new Border(inputs, network, outputInputMap); gui = new SimGui(this); gui.setTitle("Two Node Simulation"); gui.pack(); gui.setVisible(true); }
From source file:org.photovault.imginfo.VolumeBase.java
/** Maps a file path into a name that should be used for the file in the volume. <p>//from w ww .ja v a 2s.c o m THis is the reverse operation of mapFileName(), i.e. for al volume implementations it is required that f.equals( mapFileName( mapFileToVolmeRelativeName( f ) ) is true for all possible files that are stored in the volume. @param f The file to map @return Volume relative name for the file or null if the file is outside volume */ public String mapFileToVolumeRelativeName(File f) { File absVolBaseDir = getBaseDir().getAbsoluteFile(); File absImageFile = f.getAbsoluteFile(); Vector pathElems = new Vector(); File p = absImageFile; boolean found = false; while (p != null) { if (p.equals(absVolBaseDir)) { found = true; break; } pathElems.add(p.getName()); p = p.getParentFile(); } String relPath = null; if (found) { StringBuilder sb = new StringBuilder(); for (int n = pathElems.size() - 1; n >= 0; n--) { sb.append(pathElems.get(n)); if (n > 0) { sb.append("/"); } } relPath = sb.toString(); } return relPath; }
From source file:org.openflexo.foundation.fml.rm.ViewPointResourceImpl.java
public static void convertViewPoint(ViewPointResource viewPointResource) { File viewPointDirectory = ResourceLocator.retrieveResourceAsFile(viewPointResource.getDirectory()); File xmlFile = (File) viewPointResource.getFlexoIODelegate().getSerializationArtefact();// getFile(); logger.info("Converting " + viewPointDirectory.getAbsolutePath()); File diagramSpecificationDir = new File(viewPointDirectory, "DiagramSpecification"); diagramSpecificationDir.mkdir();// ww w . j a v a 2 s. c om logger.fine("Creating directory " + diagramSpecificationDir.getAbsolutePath()); try { Document viewPointDocument = XMLUtils.readXMLFile(xmlFile); Document diagramSpecificationDocument = XMLUtils.readXMLFile(xmlFile); for (File f : viewPointDirectory.listFiles()) { if (!f.equals(xmlFile) && !f.equals(diagramSpecificationDir) && !f.getName().endsWith("~")) { if (f.getName().endsWith(".shema")) { try { File renamedExampleDiagramFile = new File(f.getParentFile(), f.getName().substring(0, f.getName().length() - 6) + ".diagram"); FileUtils.rename(f, renamedExampleDiagramFile); f = renamedExampleDiagramFile; } catch (IOException e) { e.printStackTrace(); } } File destFile = new File(diagramSpecificationDir, f.getName()); FileUtils.rename(f, destFile); logger.fine("Moving file " + f.getAbsolutePath() + " to " + destFile.getAbsolutePath()); } if (f.getName().endsWith("~")) { f.delete(); } } Element diagramSpecification = XMLUtils.getElement(diagramSpecificationDocument, "ViewPoint"); diagramSpecification.setName("DiagramSpecification"); FileOutputStream fos = new FileOutputStream( new File(diagramSpecificationDir, "DiagramSpecification.xml")); Format prettyFormat = Format.getPrettyFormat(); prettyFormat.setLineSeparator(LineSeparator.SYSTEM); XMLOutputter outputter = new XMLOutputter(prettyFormat); try { outputter.output(diagramSpecificationDocument, fos); } catch (IOException e) { e.printStackTrace(); } fos.flush(); fos.close(); } catch (JDOMException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ((ViewPointResourceImpl) viewPointResource).exploreVirtualModels(viewPointResource.getDirectory()); }
From source file:org.pepstock.jem.node.DataPathsManager.java
@Override public void onFileChange(File file) { if (file.equals(datasetRulesFile)) { try {//from ww w. ja v a 2 s. c om loadRules(datasetRulesFile); } catch (MessageException e) { LogAppl.getInstance().emit(e.getMessageInterface(), e, e.getObjects()); } } }
From source file:org.cosmo.common.util.Util.java
public static void trimDirToSize(File dir, int size) { final java.io.FileFilter filter = new java.io.FileFilter() { public boolean accept(File f) { return f != null && f.exists() && !f.isDirectory(); }// w w w .j a v a2s . c o m }; final java.util.Comparator comp = new java.util.Comparator<File>() { public int compare(File f1, File f2) { return f1.lastModified() < f2.lastModified() ? 1 : f1.lastModified() == f2.lastModified() ? 1 : -1; } public boolean equals(File obj) { return obj.equals(this); } }; if (dir == null) { throw new IllegalArgumentException("param [dir] can not be null"); } if (!dir.exists()) { throw new IllegalArgumentException(dir + " do not exist"); } if (!dir.isDirectory()) { throw new IllegalArgumentException(dir + " is not a directory"); } File[] files = dir.listFiles(filter); Arrays.sort(files, comp); for (int i = size; i < files.length; i++) { for (int c = 0; c < 10 && files[i].exists() && !files[i].delete(); c++) { try { Thread.sleep(1000); } catch (Exception e) { } } if (files[i].exists()) { Assert.that(false, "Unable to delete file [" + files[i] + "]"); } } }
From source file:com.digitalpebble.stormcrawler.protocol.file.FileResponse.java
public FileResponse(String u, Metadata md, FileProtocol fp) throws MalformedURLException, IOException { fileProtocol = fp;/*from w w w .ja va 2 s . c o m*/ metadata = md; URL url = new URL(u); if (!url.getPath().equals(url.getFile())) { LOG.warn("url.getPath() != url.getFile(): {}.", url); } String path = "".equals(url.getPath()) ? "/" : url.getPath(); File file = new File(URLDecoder.decode(path, fileProtocol.getEncoding())); if (!file.exists()) { statusCode = HttpStatus.SC_NOT_FOUND; return; } if (!file.canRead()) { statusCode = HttpStatus.SC_UNAUTHORIZED; return; } if (!file.equals(file.getCanonicalFile())) { metadata.setValue(HttpHeaders.LOCATION, file.getCanonicalFile().toURI().toURL().toString()); statusCode = HttpStatus.SC_MULTIPLE_CHOICES; return; } if (file.isDirectory()) { getDirAsHttpResponse(file); } else if (file.isFile()) { getFileAsHttpResponse(file); } else { statusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; return; } if (content == null) { content = new byte[0]; } }