List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:com.docdoku.server.storage.filesystem.FileStorageProvider.java
@Override public void renameData(File src, String pNewName) throws StorageException { if (src.exists()) { src.renameTo(new File(new StringBuilder().append(src.getParentFile().getAbsolutePath()).append("/") .append(Tools.unAccent(pNewName)).toString())); } else {/* w w w. j av a 2 s . c o m*/ throw new StorageException(new StringBuilder().append("Error in renaming file : ") .append(src.getAbsolutePath()).toString()); } }
From source file:eu.stratosphere.core.fs.local.LocalFileSystem.java
@Override public boolean rename(final Path src, final Path dst) throws IOException { final File srcFile = pathToFile(src); final File dstFile = pathToFile(dst); return srcFile.renameTo(dstFile); }
From source file:com.seitenbau.jenkins.plugins.dynamicparameter.config.DynamicParameterManagement.java
/** * Rename a file or a directory./*from w w w. j a v a 2s. c o m*/ * @param oldName old name * @param newName new name * @return redirect to {@code index} */ public HttpResponse doRenameFile(@QueryParameter("oldName") String oldName, @QueryParameter("newName") String newName) throws IOException { checkWritePermission(); File oldFile = getRebasedFile(oldName); File newFile = getRebasedFile(newName); oldFile.renameTo(newFile); return redirectToIndex(); }
From source file:gov.redhawk.core.filemanager.filesystem.JavaFileSystem.java
@Override public void move(final String sourceFileName, final String destinationFileName) throws InvalidFileName, FileException { if ("".equals(sourceFileName) || "".equals(destinationFileName)) { throw new InvalidFileName(ErrorNumberType.CF_EIO, ""); }// w w w.jav a 2 s. c o m if (sourceFileName.equals(destinationFileName)) { throw new InvalidFileName(ErrorNumberType.CF_EINVAL, "Source file must be different from destination file."); } final File sourceFile = new File(this.root, sourceFileName); if (!sourceFile.renameTo(new File(this.root, destinationFileName))) { throw new FileException(ErrorNumberType.CF_EIO, "Failed to rename file: " + sourceFileName + " to " + destinationFileName); } }
From source file:eionet.cr.staging.FileDownloader.java
@Override public void run() { try {/*from w w w. ja v a 2s. c o m*/ File file = execute(); // Remove the SUFFIX from the file name, now that it's downloaded. file.renameTo(new File(FILES_DIR, StringUtils.substringBeforeLast(file.getName(), FILE_SUFFIX))); } catch (IOException e) { LOGGER.error("Failed to download from the given URL: " + url, e); } }
From source file:com.bskyb.cg.environments.hash.PersistentHash.java
private synchronized void refreshStore() throws IOException { String refreshedDirName = dirname + TEMPFILEPOSTFIX; writeHash(refreshedDirName);/* w ww. j a va 2s . c om*/ File refreshedDir = new File(refreshedDirName); File originalDir = new File(dirname); FileUtils.deleteDirectory(originalDir); if (!refreshedDir.renameTo(originalDir)) { throw new IOException("Unable to rename " + refreshedDir + " to " + dirname); } }
From source file:net.ripe.rpki.validator.commands.TopDownCertificateRepositoryValidator.java
public void prepare() { File oldValidatedDirectory = new File(new File(outputDirectory, BASE_DIRECTORY_NAME), OLD_VALIDATED_DIRECTORY_NAME); try {/*from w ww . ja v a2s .c om*/ if (oldValidatedDirectory.exists()) { FileUtils.deleteDirectory(oldValidatedDirectory); } } catch (IOException e) { throw new ValidatorIOException( "Could not delete existing output directory (" + oldValidatedDirectory.getAbsolutePath() + ")", e); } File validatedDirectory = getValidatedOutputDirectory(); if (validatedDirectory.exists()) { validatedDirectory.renameTo(oldValidatedDirectory); } validatedDirectory.mkdirs(); File unvalidatedDirectory = getUnvalidatedOutputDirectory(); unvalidatedDirectory.mkdirs(); if (!unvalidatedDirectory.isDirectory()) { throw new ValidatorIOException( "directory " + unvalidatedDirectory + " could not be created. Is there a file in the way?"); } }
From source file:com.alibaba.jstorm.daemon.supervisor.SandBoxMaker.java
/** * Generate command string/*w w w.j a va 2s . c o m*/ * * @param workerId * @return * @throws IOException */ public String sandboxPolicy(String workerId, Map<String, String> replaceMap) throws IOException { if (isEnable == false) { return ""; } replaceMap.putAll(replaceBaseMap); String tmpPolicy = generatePolicyFile(replaceMap); File file = new File(tmpPolicy); String policyPath = StormConfig.worker_root(conf, workerId) + File.separator + SANBOX_TEMPLATE_NAME; File dest = new File(policyPath); file.renameTo(dest); StringBuilder sb = new StringBuilder(); sb.append(" -Djava.security.manager -Djava.security.policy="); sb.append(policyPath); return sb.toString(); }
From source file:com.inkubator.hrm.service.impl.OhsaIncidentDocumentServiceImpl.java
@Override @Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void save(OhsaIncidentDocument entity, UploadedFile documentFile) throws Exception { entity.setId(Integer.valueOf(RandomNumberUtil.getRandomNumber(6))); OhsaIncident ohsaIncident = ohsaIncidentDao.getEntiyByPK(entity.getOhsaIncident().getId()); entity.setOhsaIncident(ohsaIncident); entity.setCreatedBy(UserInfoUtil.getUserName()); entity.setCreatedOn(new Date()); ohsaIncidentDocumentDao.save(entity); if (documentFile != null) { String uploadPath = getUploadPath(entity.getId(), documentFile); facesIO.transferFile(documentFile); File file = new File(facesIO.getPathUpload() + documentFile.getFileName()); file.renameTo(new File(uploadPath)); //documentFile.getSize(); entity.setUploadedPath(uploadPath); ohsaIncidentDocumentDao.update(entity); }/* w ww . jav a2 s . c o m*/ }
From source file:edu.stanford.epad.epadws.service.UserProjectService.java
private static Collection<File> listDICOMFiles(File dir) { log.info("Checking upload directory:" + dir.getAbsolutePath()); Set<File> files = new HashSet<File>(); if (!dir.isDirectory()) { log.info("Not a directory:" + dir.getAbsolutePath()); return files; }// w w w .ja v a2 s . c o m if (dir.listFiles() != null) { for (File entry : dir.listFiles()) { //skip if this is a jpg file if (entry.getName().endsWith(".jpg") || entry.getName().endsWith(".jpeg")) continue; if (isDicomFile(entry)) { files.add(entry); } else if (!entry.isDirectory() && entry.getName().indexOf(".") == -1) { try { File newFile = new File(entry.getParentFile(), entry.getName() + ".dcm"); entry.renameTo(newFile); files.add(newFile); } catch (Exception x) { log.warning("Error renaming", x); } } else if (!entry.isDirectory() && entry.getName().startsWith("1.") && (entry.getName().lastIndexOf(".") != entry.getName().length() - 3)) { try { File newFile = new File(entry.getParentFile(), entry.getName() + ".dcm"); entry.renameTo(newFile); files.add(newFile); } catch (Exception x) { log.warning("Error renaming", x); } } else if (entry.isDirectory()) { files.addAll(listDICOMFiles(entry)); } else { files.add(entry); // try { // log.warning("Deleting non-dicom file:" + entry.getName()); // entry.delete(); // } catch (Exception x) {log.warning("Error deleting", x);} } } } else if (!dir.getName().endsWith(".zip")) { try { log.warning("Deleting non-dicom file:" + dir.getName()); dir.delete(); } catch (Exception x) { log.warning("Error deleting", x); } } return files; }