List of usage examples for org.apache.commons.io FileUtils moveDirectory
public static void moveDirectory(File srcDir, File destDir) throws IOException
From source file:guru.nidi.webjars.UseWebjarsMojo.java
private void move(File from, File to) throws IOException { getLog().debug("Moving " + from + " to " + to); final File[] roots = from.listFiles(); if (roots != null) { for (final File root : roots) { if (root.isDirectory()) { final File target = new File(to, root.getName()); getLog().debug("Moving directory" + root + " to " + target); FileUtils.moveDirectory(root, target); } else { getLog().debug("Moving file" + root + " to " + to); FileUtils.moveFileToDirectory(root, to, true); }/*from w ww .ja va 2 s .c o m*/ } } }
From source file:hd3gtv.mydmam.useraction.fileoperation.UAFileOperationTrash.java
public void process(JobProgression progression, UserProfile userprofile, UAConfigurator user_configuration, HashMap<String, SourcePathIndexerElement> source_elements) throws Exception { String user_base_directory_name = userprofile.getBaseFileName_BasedOnEMail(); if (trash_directory_name == null) { trash_directory_name = "Trash"; }//from w ww . jav a 2 s . c om Log2Dump dump = new Log2Dump(); dump.add("user", userprofile.key); dump.add("trash_directory_name", trash_directory_name); dump.add("user_base_directory_name", user_base_directory_name); dump.add("source_elements", source_elements.values()); Log2.log.debug("Prepare trash", dump); progression.update("Prepare trashs directories"); File current_user_trash_dir; HashMap<String, File> trashs_dirs = new HashMap<String, File>(); for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) { String storagename = entry.getValue().storagename; if (trashs_dirs.containsKey(storagename)) { continue; } File storage_dir = Explorer .getLocalBridgedElement(SourcePathIndexerElement.prepareStorageElement(storagename)); current_user_trash_dir = new File(storage_dir.getPath() + File.separator + trash_directory_name + File.separator + user_base_directory_name); if (current_user_trash_dir.exists() == false) { FileUtils.forceMkdir(current_user_trash_dir); } else { CopyMove.checkExistsCanRead(current_user_trash_dir); CopyMove.checkIsWritable(current_user_trash_dir); CopyMove.checkIsDirectory(current_user_trash_dir); } trashs_dirs.put(storagename, current_user_trash_dir); if (stop) { return; } } progression.update("Move item(s) to trash(s) directorie(s)"); progression.updateStep(1, source_elements.size()); Date now = new Date(); for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) { progression.incrStep(); File current_element = Explorer.getLocalBridgedElement(entry.getValue()); CopyMove.checkExistsCanRead(current_element); CopyMove.checkIsWritable(current_element); current_user_trash_dir = trashs_dirs.get(entry.getValue().storagename); File f_destination = new File(current_user_trash_dir.getPath() + File.separator + simpledateformat.format(now) + "_" + current_element.getName()); if (current_element.isDirectory()) { FileUtils.moveDirectory(current_element, f_destination); } else { FileUtils.moveFile(current_element, f_destination); } if (stop) { return; } ContainerOperations.copyMoveMetadatas(entry.getValue(), entry.getValue().storagename, "/" + trash_directory_name + "/" + user_base_directory_name, false, this); ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk(); explorer.deleteStoragePath(bulk, Arrays.asList(entry.getValue())); bulk.terminateBulk(); if (stop) { return; } } ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk(); ArrayList<SourcePathIndexerElement> spie_trashs_dirs = new ArrayList<SourcePathIndexerElement>(); for (String storage_name : trashs_dirs.keySet()) { SourcePathIndexerElement root_trash_directory = SourcePathIndexerElement .prepareStorageElement(storage_name); root_trash_directory.parentpath = root_trash_directory.prepare_key(); root_trash_directory.directory = true; root_trash_directory.currentpath = "/" + trash_directory_name; spie_trashs_dirs.add(root_trash_directory); } explorer.refreshStoragePath(bulk, spie_trashs_dirs, false); bulk.terminateBulk(); }
From source file:de.uzk.hki.da.cb.FetchPIPsActionTest.java
private void simulateImpl() throws IOException { FolderUtils.deleteDirectorySafe(makePIPFolder(WorkArea.PUBLIC)); FolderUtils.deleteDirectorySafe(makePIPFolder(WorkArea.WA_INSTITUTION)); FileUtils.moveDirectory(makePIPSourceFolder(WorkArea.PUBLIC), makePIPFolder(WorkArea.PUBLIC)); FileUtils.moveDirectory(makePIPSourceFolder(WorkArea.WA_INSTITUTION), makePIPFolder(WorkArea.WA_INSTITUTION)); FolderUtils.deleteDirectorySafe(makePIPSourceFolder(WorkArea.PUBLIC)); FolderUtils.deleteDirectorySafe(makePIPSourceFolder(WorkArea.WA_INSTITUTION)); }
From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetUtil.java
public static void backupOldWidgetset(String originalWidgetset) throws IOException { File srcDir = new File(originalWidgetset); File destDir = new File(originalWidgetset + ".0.bak"); if (srcDir.exists() || srcDir.isDirectory()) { FileUtils.deleteDirectory(destDir); FileUtils.moveDirectory(srcDir, destDir); }// w w w . j a v a 2s.co m }
From source file:de.uzk.hki.da.at.AcceptanceTestHelper.java
/** * Retrieves a package and unpacks it to a target folder. * <br>//w w w . ja v a2 s. c o m * <strong>!</strong> Make sure to delete targetFolder at tearDown in acceptance tests. * * @param originalName of the object. * @param targetFolder to extract the DIP to. * @param packageName number of the package of the object. * @return a new instance that represents the object. fetched from the from the database. * @throws IOException if cannot fetch file from grid. * */ void retrieveAIP(Object o, File targetFolder, String packageName) throws IOException { final String packSuffix = ".pack_"; Object object = getObject(o.getOrig_name()); if (object == null) throw new RuntimeException("cannot find object"); System.out.println("object: " + object.getIdentifier()); Path.makeFile(TEMP_FOLDER, object.getIdentifier() + packSuffix + packageName + C.FILE_EXTENSION_TAR) .delete(); // if exists gridFacade.get( Path.makeFile(TEMP_FOLDER, object.getIdentifier() + packSuffix + packageName + C.FILE_EXTENSION_TAR), testContractor.getShort_name() + "/" + object.getIdentifier() + "/" + object.getIdentifier() + packSuffix + packageName + C.FILE_EXTENSION_TAR); try { new NativeJavaTarArchiveBuilder().unarchiveFolder( Path.makeFile(TEMP_FOLDER, object.getIdentifier() + packSuffix + packageName + C.FILE_EXTENSION_TAR), Path.makeFile(TEMP_FOLDER)); } catch (Exception e) { fail("could not find source file or unarchive source file to tmp"); } if (targetFolder.exists()) FolderUtils.deleteDirectorySafe(targetFolder); FileUtils.moveDirectory(Path.makeFile(TEMP_FOLDER, object.getIdentifier() + packSuffix + packageName), targetFolder); Path.makeFile(TEMP_FOLDER, object.getIdentifier() + packSuffix + packageName + C.FILE_EXTENSION_TAR) .delete(); }
From source file:com.enonic.cms.core.resource.FileResourceServiceImpl.java
private boolean doMoveDirectory(final File fromFile, final File toFile) { if (isSubFolderOf(fromFile, toFile)) { return false; }/*from ww w . jav a2 s .c om*/ try { FileUtils.moveDirectory(fromFile, toFile); return true; } catch (IOException e) { throw new RuntimeException( "Not able to move folder " + fromFile.getAbsolutePath() + " to " + toFile.getAbsolutePath(), e); } }
From source file:com.arcusys.liferay.vaadinplugin.util.WidgetsetUtil.java
public static void rotateWidgetsetBackups(String originalWidgetset) throws IOException { for (int i = MAX_NUMBER_OF_WIDGETSET_BACKUPS - 1; i > 0; i--) { File srcDir = new File(originalWidgetset + "." + (i - 1) + ".bak"); File destDir = new File(originalWidgetset + "." + i + ".bak"); if (srcDir.exists() || srcDir.isDirectory()) { FileUtils.deleteDirectory(destDir); FileUtils.moveDirectory(srcDir, destDir); }// w w w.j av a2s . c om } }
From source file:de.bitinsomnia.webdav.server.MiltonFolderResource.java
@Override public void moveTo(CollectionResource rDest, String name) throws ConflictException, NotAuthorizedException, BadRequestException { LOGGER.debug("Moving {} to {}/{}", this.file, rDest.getName(), name); File newRootDir = new File(resourceFactory.getRootFolder(), rDest.getName()); File newDir = new File(newRootDir, name); try {// www .jav a 2s . c o m FileUtils.moveDirectory(this.file, newDir); } catch (IOException e) { LOGGER.error("Error moving {} to {}", this.file, newDir); throw new RuntimeIoException(e); } }
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void moveDirectory(@NonNull final GenericFile source, @NonNull final GenericFile target, final boolean useCommandLine) throws IOException { if (useCommandLine) { if (target.exists()) { throw new FileExistsException("Target exists"); }/*from ww w . java2 s .c o m*/ final boolean result = CommandLine.execute(new CommandMove(source, target)); if (!result) { throw new IOException("Move failed"); } } else { FileUtils.moveDirectory(source.toFile(), target.toFile()); } }
From source file:com.xiaomi.linden.core.search.HotSwapLindenCoreImpl.java
@Override public synchronized Response swapIndex(String indexName) throws IOException { if (Strings.isNullOrEmpty(indexName)) { throw new IOException("Index name is empty in swap index request."); }// w ww . j a v a2 s . c om if (!indexName.startsWith(NEXT_INDEX_NAME_PREFIX)) { throw new IOException("Invalid index name: " + indexName); } // May receive swap request more than one times String nextIndexVersion = indexName.substring(NEXT_INDEX_NAME_PREFIX.length()); if (!currentIndexVersion.equals(nextIndexVersion)) { LOGGER.info("Begin swapping index " + indexName); if (!lindenCoreMap.containsKey(indexName)) { LOGGER.error("No index found for: " + indexName); return ResponseUtils.buildFailedResponse("No index found for: " + indexName); } if (lindenConfig.getIndexType() != LindenConfig.IndexType.RAM) { LindenCore nextCore = lindenCoreMap.remove(indexName); nextCore.close(); String dir = FilenameUtils.concat(baseIndexDir, indexName); String newIndexName = indexName.replaceFirst(NEXT_INDEX_NAME_PREFIX, CURRENT_INDEX_NAME_PREFIX); String destDir = FilenameUtils.concat(baseIndexDir, newIndexName); FileUtils.moveDirectory(new File(dir), new File(destDir)); LOGGER.info("Move " + dir + " directory to " + destDir); nextCore = getLindenCore(newIndexName); // swap String lastIndexName = currentIndexName; String lastIndexVersion = currentIndexVersion; currentLindenCore = nextCore; currentIndexName = newIndexName; currentIndexVersion = nextIndexVersion; // remove last core from map LindenCore lastCore = lindenCoreMap.remove(lastIndexName); // close last core lastCore.close(); // mark last core expired dir = FilenameUtils.concat(baseIndexDir, lastIndexName); destDir = FilenameUtils.concat(baseIndexDir, EXPIRED_INDEX_NAME_PREFIX + lastIndexVersion); FileUtils.moveDirectory(new File(dir), new File(destDir)); LOGGER.info("Expire index: " + lastIndexName); File[] files = getIndexDirectories(EXPIRED_INDEX_NAME_PREFIX); if (files != null && files.length > MAX_EXPIRED_INDEX_NUM) { File oldestExpiredIndexDir = files[files.length - 1]; FileUtils.deleteQuietly(oldestExpiredIndexDir); LOGGER.info("Delete expired index: " + oldestExpiredIndexDir.getName()); } } else { // RAM type // swap String lastIndexName = currentIndexName; currentLindenCore = lindenCoreMap.get(indexName); currentIndexName = indexName; // remove last core from map LindenCore lastCore = lindenCoreMap.remove(lastIndexName); // close last core lastCore.close(); } LOGGER.info("Swapping index " + indexName + " done"); } return ResponseUtils.SUCCESS; }