List of usage examples for org.apache.commons.io FileUtils moveToDirectory
public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException
From source file:com.docd.purefm.utils.PFMFileUtils.java
public static void moveToDirectory(@NonNull final GenericFile source, @NonNull final GenericFile target, final boolean useCommandLine, final boolean createDestDir) throws IOException { if (useCommandLine) { if (!source.exists()) { throw new FileNotFoundException("Source '" + source + "' does not exist"); }/*w w w . j a v a2s .c o m*/ if (target.exists()) { if (!target.isDirectory()) { throw new IOException("Target is not a directory"); } } else { if (createDestDir) { if (!target.mkdirs()) { throw new IOException("Failed to create target directory"); } } else { throw new FileNotFoundException("Target directory doesn't exist"); } } final boolean result = CommandLine.execute(new CommandMove(source, target)); if (!result) { throw new IOException("Moving failed"); } } else { FileUtils.moveToDirectory(source.toFile(), target.toFile(), createDestDir); } }
From source file:com.edgenius.wiki.service.impl.BackupServiceImpl.java
public void moveBackupFileToRestoreList(File srcFile) { try {//from w ww.ja va 2 s.c o m FileUtils.moveToDirectory(srcFile, restoreLocation.getFile(), false); } catch (IOException e) { log.error("Failed move backup file to restore directory", e); } }
From source file:org.fao.geonet.services.metadata.format.Register.java
private void removeTopDir(File dir) throws IOException { File[] files = dir.listFiles(new FileFilter() { @Override/* w w w. j a v a 2s. c o m*/ public boolean accept(File file) { if (file.isDirectory() && !file.getName().startsWith(".") && !FileUtils.listFiles(file, new String[] { "xsl" }, false).isEmpty()) { return true; } return false; } }); if (files.length == 1) { for (File f : files[0].listFiles()) { FileUtils.moveToDirectory(f, dir, true); } FileUtils.deleteDirectory(files[0]); } }
From source file:org.kuali.kfs.module.tem.batch.service.impl.AgencyDataImportServiceImpl.java
public void moveErrorFile(String dataFileName, String agencyDataFileErrordirectory) { File dataFile = new File(dataFileName); if (!dataFile.exists() || !dataFile.canRead()) { LOG.error("Cannot find/read data file " + dataFileName); } else {//from w ww .ja va 2 s .c o m try { FileUtils.moveToDirectory(dataFile, new File(agencyDataFileErrordirectory), true); } catch (IOException ex) { LOG.error("Cannot move the file:" + dataFile + " to the directory: " + agencyDataFileErrordirectory, ex); } } }
From source file:org.kuali.kfs.module.tem.batch.service.impl.CreditCardDataImportServiceImpl.java
public void moveErrorFile(String dataFileName, String creditCardDataFileErrorDirectory) { File dataFile = new File(dataFileName); if (!dataFile.exists() || !dataFile.canRead()) { LOG.error("Cannot find/read data file " + dataFileName); } else {/*www.j a v a 2 s . c o m*/ try { FileUtils.moveToDirectory(dataFile, new File(creditCardDataFileErrorDirectory), true); } catch (IOException ex) { LOG.error("Cannot move the file:" + dataFile + " to the directory: " + creditCardDataFileErrorDirectory, ex); } } }
From source file:org.kuali.kfs.module.tem.batch.service.impl.PerDiemLoadServiceImpl.java
/** * move the given file to the specified directory * * @param fileName the given file name/*from w ww . j a v a 2 s . c o m*/ * @param directory the specified directory */ protected void moveErrorFile(String fileName, String directory) { File dataFile = this.getFileByAbsolutePath(fileName); if (dataFile != null && dataFile.exists()) { File errorDirectory = this.getFileByAbsolutePath(directory); try { FileUtils.moveToDirectory(dataFile, errorDirectory, true); } catch (IOException ex) { LOG.error("Cannot move the file:" + fileName + " to the directory: " + perDiemFileErrorDirectory, ex); } } }
From source file:org.nuxeo.runtime.deployment.preprocessor.PackZip.java
protected void moveNonEjbsToLib(File wd) throws ParserConfigurationException, SAXException, IOException { File file = new File(wd, "META-INF" + File.separator + "application.xml"); if (!file.isFile()) { log.error("You should run this tool from a preprocessed nuxeo.ear folder"); }//from w w w . j av a 2 s . c o m DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); FileInputStream in = new FileInputStream(file); Document doc = docBuilder.parse(in); Element root = doc.getDocumentElement(); NodeList list = root.getElementsByTagName("module"); Collection<String> paths = new ArrayList<String>(); for (int i = 0; i < list.getLength(); i++) { Element el = (Element) list.item(i); Node n = el.getFirstChild(); while (n != null) { if (n.getNodeType() == Node.ELEMENT_NODE) { Element mtype = ((Element) n); String type = n.getNodeName().toLowerCase(); if (!"web".equals(type)) { String path = mtype.getTextContent().trim(); paths.add(path); } } n = n.getNextSibling(); } } File ejbs = new File(wd, "tmp-ejbs"); ejbs.mkdirs(); for (String path : paths) { log.info("Move EAR module " + path + " to " + ejbs.getName()); File f = new File(wd, path); if (f.getName().endsWith(".txt")) { continue; } FileUtils.moveToDirectory(f, ejbs, false); } File lib = new File(wd, "lib"); File[] files = new File(wd, "bundles").listFiles(); if (files != null) { for (File f : files) { if (f.getName().endsWith(".txt")) { continue; } log.info("Move POJO bundle " + f.getName() + " to lib"); FileUtils.moveToDirectory(f, lib, false); } } File bundles = new File(wd, "bundles"); files = ejbs.listFiles(); if (files != null) { for (File f : files) { if (f.getName().endsWith(".txt")) { continue; } log.info("Move back EAR module " + f.getName() + " to bundles"); FileUtils.moveToDirectory(f, bundles, false); } } }
From source file:org.objectpocket.storage.blob.MultiZipBlobStore.java
@Override public void cleanup(Set<Blob> referencedBlobs) throws IOException { if (referencedBlobs == null) { return;// www. ja va 2 s .c o m } // preload blobs for (Blob blob : referencedBlobs) { blob.getBytes(); } String tmpdir = directory + "/.tmp"; MultiZipBlobStore newZip = new MultiZipBlobStore(tmpdir); newZip.writeBlobs(referencedBlobs); newZip.close(); this.close(); // delete old Collection<File> blobContainers = FileUtils.listFiles(new File(directory), FileFilterUtils.prefixFileFilter(BLOB_STORE_DEFAULT_FILENAME), null); for (File file : blobContainers) { file.delete(); } // move new blobContainers = FileUtils.listFiles(new File(tmpdir), FileFilterUtils.prefixFileFilter(BLOB_STORE_DEFAULT_FILENAME), null); File destination = new File(directory); for (File file : blobContainers) { FileUtils.moveToDirectory(file, destination, false); } // delete temp FileUtils.deleteDirectory(new File(tmpdir)); blobContainerIndex.clear(); readFileSystems.clear(); initIndexAndReadFileSystems(); }
From source file:org.orbisgis.view.components.fstree.TreeNodeFolder.java
private void transferTreeNodePath(List<TreeNodePath> nodePath) { // Moved paths set Set<String> paths = new HashSet<String>(); for (TreeNodePath treeNode : nodePath) { File treeFilePath = treeNode.getFilePath(); paths.add(treeFilePath.getAbsolutePath()); }/*from ww w. j av a 2 s.c o m*/ // Process folder and files moves for (TreeNodePath treeNode : nodePath) { // Ignore if a parent path is already on the list // or if this folder node is the child of a transfered path File treeFilePath = treeNode.getFilePath(); if (!hasAParentInPathList(treeFilePath, paths) && !hasAParent(getFilePath(), treeFilePath.getAbsolutePath())) { try { File dest = new File(getFilePath(), treeFilePath.getName()); if (!dest.exists()) { // Move the folder FileUtils.moveToDirectory(treeFilePath, getFilePath(), false); } else { LOGGER.warn(I18N.tr("Destination file {0} already exists, cannot move {1}", dest, treeFilePath)); } } catch (IOException ex) { LOGGER.error(ex.getLocalizedMessage(), ex); return; } } } }
From source file:org.oscarehr.billing.CA.ON.web.MoveMOHFilesAction.java
private boolean moveFile(File file) { File archiveDir = new File(EDTFolder.ARCHIVE.getPath()); try {/* w w w .j a v a 2s.c o m*/ FileUtils.moveToDirectory(file, archiveDir, true); } catch (IOException e) { logger.error("Unable to move", e); return false; } return true; }