List of usage examples for org.apache.commons.io FileUtils moveDirectory
public static void moveDirectory(File srcDir, File destDir) throws IOException
From source file:org.silverpeas.attachment.repository.DocumentRepository.java
public void moveMultilangContent(SimpleDocument origin, SimpleDocument copy) throws IOException { String originDir = origin.getDirectoryPath(null); File source = new File(originDir).getParentFile(); String targetDir = copy.getDirectoryPath(null); targetDir = targetDir.replace('/', File.separatorChar); File target = new File(targetDir).getParentFile(); if (!source.exists() || !source.isDirectory() || source.listFiles() == null) { return;/*from w w w. j av a2 s .c om*/ } if (!target.getParentFile().getName().equals(source.getParentFile().getName())) { source = source.getParentFile(); target = target.getParentFile(); } if (!source.equals(target)) { FileUtils.moveDirectory(source, target); FileUtil.deleteEmptyDir(source.getParentFile()); } }
From source file:org.silverpeas.attachment.repository.DocumentRepository.java
public void moveFullContent(SimpleDocument origin, SimpleDocument copy) throws IOException { String originDir = origin.getDirectoryPath(null); File source = new File(originDir).getParentFile().getParentFile(); String targetDir = copy.getDirectoryPath(null); targetDir = targetDir.replace('/', File.separatorChar); File target = new File(targetDir).getParentFile().getParentFile(); if (!source.exists() || !source.isDirectory() || source.listFiles() == null) { return;// www . j a va 2 s . c o m } if (!source.equals(target)) { FileUtils.moveDirectory(source, target); FileUtil.deleteEmptyDir(source.getParentFile()); } }
From source file:org.silverpeas.components.silvercrawler.control.SilverCrawlerSessionController.java
public void renameFolder(String folderName, String newName) throws SilverCrawlerFolderRenameException, IOException { // looks for weird characters in new file name (security) if (containsWeirdCharacters(newName)) { throw new SilverCrawlerFolderRenameException(getString("silverCrawler.nameIncorrect")); }/*ww w.j av a 2s . com*/ // Get Full Path File after = FileUtils.getFile(getFullPath(newName)); if (after.exists()) { throw new SilverCrawlerFolderRenameException(getString("silverCrawler.folderNameAlreadyExists")); } // Rename file File before = FileUtils.getFile(getFullPath(folderName)); if (before.isDirectory()) { FileUtils.moveDirectory(before, after); } else { FileUtils.moveFile(before, after); } }
From source file:org.silverpeas.components.silvercrawler.servlets.DragAndDrop.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) { HttpRequest request = HttpRequest.decorate(req); try {//from www . jav a 2s. c o m request.setCharacterEncoding("UTF-8"); } catch (UnsupportedEncodingException e) { SilverLogger.getLogger(this).error(e); try { res.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } catch (IOException e1) { SilverLogger.getLogger(this).error(e1); } } UploadSession uploadSession = UploadSession.from(request); try { String componentId = request.getParameter("ComponentId"); boolean ignoreFolders = request.getParameterAsBoolean("IgnoreFolders"); if (!uploadSession.isUserAuthorized(componentId)) { throwHttpForbiddenError(); } SilverCrawlerSessionController sessionController = getSessionInfo(request) .getAttribute("Silverpeas_SilverCrawler_" + componentId); // build report UploadReport report = sessionController.getLastUploadReport(); if (report == null) { report = new UploadReport(); sessionController.setLastUploadReport(report); } File rootUploadFolder = new File(uploadSession.getRootFolder().getParentFile(), "SilverCrawler_" + uploadSession.getRootFolder().getName()); int rootUploadFolderPathLength = rootUploadFolder.getPath().length(); FileUtils.moveDirectory(uploadSession.getRootFolder(), rootUploadFolder); // Setting into report instance the path into which the files have been uploaded report.setRepositoryPath(rootUploadFolder); if (ignoreFolders) { // Verifying that is does not exist folders File[] folders = rootUploadFolder.listFiles((FileFilter) FileFilterUtils.directoryFileFilter()); if (folders != null && folders.length > 0) { report.setFailed(true); report.setForbiddenFolderDetected(true); return; } } // Loop items for (File file : FileUtils.listFiles(rootUploadFolder, FileFilterUtils.fileFileFilter(), FileFilterUtils.trueFileFilter())) { // Get the file path and name File fileName = new File(file.getPath().substring(rootUploadFolderPathLength)); // Logging the name of the file // Save info into report UploadItem uploadItem = new UploadItem(); uploadItem.setFileName(fileName.getName()); uploadItem.setParentRelativePath(fileName.getParentFile()); report.addItem(uploadItem); } } catch (Exception e) { SilverLogger.getLogger(this).error(e); try { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } catch (IOException e1) { SilverLogger.getLogger(this).error(e1); } } finally { uploadSession.clear(); } }
From source file:org.silverpeas.migration.jcr.service.repository.DocumentRepository.java
public void moveMultilangContent(SimpleDocument origin, SimpleDocument copy) throws IOException { String originDir = origin.getDirectoryPath(null); String targetDir = copy.getDirectoryPath(null); targetDir = targetDir.replace('/', File.separatorChar); File target = new File(targetDir).getParentFile(); File source = new File(originDir).getParentFile(); if (!source.exists() || !source.isDirectory() || source.listFiles() == null) { return;/*from w ww . j a v a 2s. c om*/ } if (!target.getParentFile().getName().equals(source.getParentFile().getName())) { source = source.getParentFile(); target = target.getParentFile(); } FileUtils.moveDirectory(source, target); }
From source file:org.sipfoundry.sipxconfig.vm.MailboxManagerImpl.java
public void renameMailbox(String oldUserId, String newUserId) { Mailbox oldMailbox = getMailbox(oldUserId); Mailbox newMailbox = getMailbox(newUserId); File oldUserDir = oldMailbox.getUserDirectory(); File newUserDir = newMailbox.getUserDirectory(); newMailbox.deleteUserDirectory();/* w ww.ja v a 2 s. c om*/ if (oldUserDir.exists()) { try { FileUtils.moveDirectory(oldUserDir, newUserDir); } catch (IOException e) { throw new MailstoreMisconfigured("Cannot rename mailbox directory " + oldUserDir.getAbsolutePath(), e); } } }
From source file:org.sonar.batch.bootstrap.BatchPluginExploder.java
private File unzipFile(File cachedFile) throws IOException { String filename = cachedFile.getName(); File destDir = new File(cachedFile.getParentFile(), filename + "_unzip"); File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock"); if (!destDir.exists()) { FileOutputStream out = new FileOutputStream(lockFile); try {//from w w w. j a v a 2s . com java.nio.channels.FileLock lock = out.getChannel().lock(); try { // Recheck in case of concurrent processes if (!destDir.exists()) { File tempDir = fileCache.createTempDir(); ZipUtils.unzip(cachedFile, tempDir, newLibFilter()); FileUtils.moveDirectory(tempDir, destDir); } } finally { lock.release(); } } finally { out.close(); FileUtils.deleteQuietly(lockFile); } } return destDir; }
From source file:org.sonar.batch.bootstrap.BatchPluginJarExploder.java
private File unzipFile(File cachedFile) throws IOException { String filename = cachedFile.getName(); File destDir = new File(cachedFile.getParentFile(), filename + "_unzip"); File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock"); if (!destDir.exists()) { FileOutputStream out = new FileOutputStream(lockFile); try {//from w ww .j a v a 2 s .com java.nio.channels.FileLock lock = out.getChannel().lock(); try { // Recheck in case of concurrent processes if (!destDir.exists()) { File tempDir = fileCache.createTempDir(); ZipUtils.unzip(cachedFile, tempDir, newLibFilter()); FileUtils.moveDirectory(tempDir, destDir); } } finally { lock.release(); } } finally { out.close(); deleteQuietly(lockFile); } } return destDir; }
From source file:org.sonarsource.sonarlint.core.plugin.DefaultPluginJarExploder.java
private File unzipFile(File cachedFile) throws IOException { String filename = cachedFile.getName(); File destDir = new File(cachedFile.getParentFile(), filename + "_unzip"); if (!destDir.exists()) { File lockFile = new File(cachedFile.getParentFile(), filename + "_unzip.lock"); FileOutputStream out = new FileOutputStream(lockFile); try {//from w w w. jav a 2 s . co m FileLock lock = out.getChannel().lock(); try { // Recheck in case of concurrent processes if (!destDir.exists()) { Path tempDir = fileCache.createTempDir(); ZipUtils.unzip(cachedFile, tempDir.toFile(), newLibFilter()); FileUtils.moveDirectory(tempDir.toFile(), destDir); } } finally { lock.release(); } } finally { out.close(); FileUtils.deleteQuietly(lockFile); } } return destDir; }
From source file:org.specrunner.htmlunit.result.WritablePage.java
/** * Move files/directory.// w w w.ja v a 2 s . com * * @param from * The original file/directory. * @param to * The target file/directory. * @throws IOException * On move errors. * @throws ResultException * On action errors. */ protected void move(File from, File to) throws IOException, ResultException { if (!from.exists()) { if (UtilLog.LOG.isInfoEnabled()) { UtilLog.LOG.debug("File/Dir " + from + " not exists."); } return; } if (to.exists()) { if (!to.delete()) { throw new ResultException("Could not remove resources '" + to + "'."); } } if (UtilLog.LOG.isDebugEnabled()) { UtilLog.LOG.debug("Moving " + from + " to " + to + "."); } if (from.isDirectory()) { FileUtils.moveDirectory(from, to); } else { FileUtils.moveFile(from, to); } }