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.bigbluebutton.api.RecordingService.java
public static void publishRecording(File destDir, String recordingId, File recordingDir) { File metadataXml = RecordingMetadataReaderHelper.getMetadataXmlLocation(recordingDir.getPath()); RecordingMetadata r = RecordingMetadataReaderHelper.getRecordingMetadata(metadataXml); if (r != null) { if (!destDir.exists()) destDir.mkdirs();/* w w w .j av a2 s .c o m*/ try { FileUtils.moveDirectory(recordingDir, new File(destDir.getPath() + File.separatorChar + recordingId)); r.setState(Recording.STATE_PUBLISHED); r.setPublished(true); File medataXmlFile = RecordingMetadataReaderHelper .getMetadataXmlLocation(destDir.getAbsolutePath() + File.separatorChar + recordingId); // Process the changes by saving the recording into metadata.xml RecordingMetadataReaderHelper.saveRecordingMetadata(medataXmlFile, r); } catch (IOException e) { log.error("Failed to publish recording : " + recordingId, e); } } }
From source file:org.bigbluebutton.api.RecordingService.java
public static void unpublishRecording(File destDir, String recordingId, File recordingDir) { File metadataXml = RecordingMetadataReaderHelper.getMetadataXmlLocation(recordingDir.getPath()); RecordingMetadata r = RecordingMetadataReaderHelper.getRecordingMetadata(metadataXml); if (r != null) { if (!destDir.exists()) destDir.mkdirs();/* w ww.j a va 2s. c om*/ try { FileUtils.moveDirectory(recordingDir, new File(destDir.getPath() + File.separatorChar + recordingId)); r.setState(Recording.STATE_UNPUBLISHED); r.setPublished(false); File medataXmlFile = RecordingMetadataReaderHelper .getMetadataXmlLocation(destDir.getAbsolutePath() + File.separatorChar + recordingId); // Process the changes by saving the recording into metadata.xml RecordingMetadataReaderHelper.saveRecordingMetadata(medataXmlFile, r); } catch (IOException e) { log.error("Failed to unpublish recording : " + recordingId, e); } } }
From source file:org.bigbluebutton.api.RecordingService.java
public static void deleteRecording(File destDir, String recordingId, File recordingDir) { File metadataXml = RecordingMetadataReaderHelper.getMetadataXmlLocation(recordingDir.getPath()); RecordingMetadata r = RecordingMetadataReaderHelper.getRecordingMetadata(metadataXml); if (r != null) { if (!destDir.exists()) destDir.mkdirs();// w w w . j a v a 2 s .c om try { FileUtils.moveDirectory(recordingDir, new File(destDir.getPath() + File.separatorChar + recordingId)); r.setState(Recording.STATE_DELETED); r.setPublished(false); File medataXmlFile = RecordingMetadataReaderHelper .getMetadataXmlLocation(destDir.getAbsolutePath() + File.separatorChar + recordingId); // Process the changes by saving the recording into metadata.xml RecordingMetadataReaderHelper.saveRecordingMetadata(medataXmlFile, r); } catch (IOException e) { log.error("Failed to delete recording : " + recordingId, e); } } }
From source file:org.commonjava.indy.filer.def.migrate.PackageTypedStorageMigrationAction.java
private boolean doMigrate() throws IndyLifecycleException { Set<ArtifactStore> stores; try {/*from w ww . j a v a 2 s .c o m*/ stores = storeDataManager.getAllArtifactStores(); } catch (IndyDataException e) { throw new IndyLifecycleException( "Cannot retrieve list of repositories and groups in order to review storage locations. Reason: %s", e, e.getMessage()); } File storageRoot = config.getStorageRootDirectory(); File nfsStorageRoot = config.getNFSStorageRootDirectory(); int migrations = 0; Map<File, File> unmigratedNfs = new HashMap<>(); for (ArtifactStore store : stores) { File old = deprecatedStoragePath(storageRoot, store); File migrated = packageTypedStoragePath(storageRoot, store); if (old.exists()) { logger.info("Attempting to migrate existing storage from old directory structure: {} " + "to package-typed structure: {}", old, migrated); try { if (migrated.exists()) { FileUtils.copyDirectory(old, migrated); FileUtils.forceDelete(old); } else { FileUtils.moveDirectory(old, migrated); } migrations++; } catch (IOException e) { throw new IndyLifecycleException("Failed to migrate: %s to: %s. Reason: %s", e, old, migrated); } } if (nfsStorageRoot != null) { File oldNfs = deprecatedStoragePath(nfsStorageRoot, store); File migratedNfs = packageTypedStoragePath(nfsStorageRoot, store); if (oldNfs.exists() && !migratedNfs.exists()) { unmigratedNfs.put(oldNfs, migratedNfs); } } } if (!unmigratedNfs.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append("ERROR: Un-migrated directories detected on NFS storage!!!!"); sb.append("\n\nThese directories still use the old <type>/<name> directory format. Indy now supports"); sb.append( "\nmultiple package types, and the storage format has changed accordingly. The new format is:"); sb.append("\n\n <package-type>/<type>/<name>"); sb.append("\n\nPlease migrate these NFS directories manually. For Maven repositories:"); sb.append("\n\n maven/<type>/<name>"); sb.append("\n\nFor HTTProx repositories (httprox_*):"); sb.append("\n\n generic-http/<type>/<name>"); sb.append("\n\nThe following directories were detected:\n"); unmigratedNfs.forEach((o, n) -> sb.append("\n ").append(o).append(" => ").append(n)); sb.append("\n\n"); logger.error(sb.toString()); throw new IndyLifecycleException( "Un-migrated NFS directories detected. Indy cannot start until this has been resolved."); } return migrations > 0; }
From source file:org.dspace.app.itemimport.ItemImportServiceImpl.java
/** * /*from w w w. j a v a2s .c o m*/ * Given a local file or public URL to a zip file that has the Simple Archive Format, this method imports the contents to DSpace * @param filepath The filepath to local file or the public URL of the zip file * @param owningCollection The owning collection the items will belong to * @param otherCollections The collections the created items will be inserted to, apart from the owning one * @param resumeDir In case of a resume request, the directory that containsthe old mapfile and data * @param inputType The input type of the data (bibtex, csv, etc.), in case of local file * @param context The context * @param template whether to use template item * @throws Exception if error */ @Override public void processUIImport(String filepath, Collection owningCollection, String[] otherCollections, String resumeDir, String inputType, Context context, final boolean template) throws Exception { final EPerson oldEPerson = context.getCurrentUser(); final String[] theOtherCollections = otherCollections; final Collection theOwningCollection = owningCollection; final String theFilePath = filepath; final String theInputType = inputType; final String theResumeDir = resumeDir; final boolean useTemplateItem = template; Thread go = new Thread() { @Override public void run() { Context context = null; String importDir = null; EPerson eperson = null; try { // create a new dspace context context = new Context(); eperson = ePersonService.find(context, oldEPerson.getID()); context.setCurrentUser(eperson); context.turnOffAuthorisationSystem(); boolean isResume = theResumeDir != null; List<Collection> collectionList = new ArrayList<>(); if (theOtherCollections != null) { for (String colID : theOtherCollections) { UUID colId = UUID.fromString(colID); if (!theOwningCollection.getID().equals(colId)) { Collection col = collectionService.find(context, colId); if (col != null) { collectionList.add(col); } } } } importDir = ConfigurationManager.getProperty("org.dspace.app.batchitemimport.work.dir") + File.separator + "batchuploads" + File.separator + context.getCurrentUser().getID() + File.separator + (isResume ? theResumeDir : (new GregorianCalendar()).getTimeInMillis()); File importDirFile = new File(importDir); if (!importDirFile.exists()) { boolean success = importDirFile.mkdirs(); if (!success) { log.info("Cannot create batch import directory!"); throw new Exception("Cannot create batch import directory!"); } } String dataPath = null; String dataDir = null; if (theInputType.equals("saf")) { //In case of Simple Archive Format import (from remote url) dataPath = importDirFile + File.separator + "data.zip"; dataDir = importDirFile + File.separator + "data_unzipped2" + File.separator; } else if (theInputType.equals("safupload")) { //In case of Simple Archive Format import (from upload file) FileUtils.copyFileToDirectory(new File(theFilePath), importDirFile); dataPath = importDirFile + File.separator + (new File(theFilePath)).getName(); dataDir = importDirFile + File.separator + "data_unzipped2" + File.separator; } else { // For all other imports dataPath = importDirFile + File.separator + (new File(theFilePath)).getName(); dataDir = importDirFile + File.separator + "data" + File.separator; } //Clear these files, if a resume if (isResume) { if (!theInputType.equals("safupload")) { (new File(dataPath)).delete(); } (new File(importDirFile + File.separator + "error.txt")).delete(); FileDeleteStrategy.FORCE.delete(new File(dataDir)); FileDeleteStrategy.FORCE.delete( new File(importDirFile + File.separator + "data_unzipped" + File.separator)); } //In case of Simple Archive Format import we need an extra effort to download the zip file and unzip it String sourcePath = null; if (theInputType.equals("saf")) { OutputStream os = new FileOutputStream(dataPath); byte[] b = new byte[2048]; int length; InputStream is = new URL(theFilePath).openStream(); while ((length = is.read(b)) != -1) { os.write(b, 0, length); } is.close(); os.close(); sourcePath = unzip(new File(dataPath), dataDir); //Move files to the required folder FileUtils.moveDirectory(new File(sourcePath), new File(importDirFile + File.separator + "data_unzipped" + File.separator)); FileDeleteStrategy.FORCE.delete(new File(dataDir)); dataDir = importDirFile + File.separator + "data_unzipped" + File.separator; } else if (theInputType.equals("safupload")) { sourcePath = unzip(new File(dataPath), dataDir); //Move files to the required folder FileUtils.moveDirectory(new File(sourcePath), new File(importDirFile + File.separator + "data_unzipped" + File.separator)); FileDeleteStrategy.FORCE.delete(new File(dataDir)); dataDir = importDirFile + File.separator + "data_unzipped" + File.separator; } //Create mapfile path String mapFilePath = importDirFile + File.separator + "mapfile"; List<Collection> finalCollections = null; if (theOwningCollection != null) { finalCollections = new ArrayList<>(); finalCollections.add(theOwningCollection); finalCollections.addAll(collectionList); } setResume(isResume); if (theInputType.equals("saf") || theInputType.equals("safupload")) { //In case of Simple Archive Format import addItems(context, finalCollections, dataDir, mapFilePath, template); } else { // For all other imports (via BTE) addBTEItems(context, finalCollections, theFilePath, mapFilePath, useTemplateItem, theInputType, dataDir); } // email message letting user know the file is ready for // download emailSuccessMessage(context, eperson, mapFilePath); context.complete(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); String exceptionString = ExceptionUtils.getStackTrace(e); try { File importDirFile = new File(importDir + File.separator + "error.txt"); PrintWriter errorWriter = new PrintWriter(importDirFile); errorWriter.print(exceptionString); errorWriter.close(); emailErrorMessage(eperson, exceptionString); throw new Exception(e.getMessage()); } catch (Exception e2) { // wont throw here } } finally { // Make sure the database connection gets closed in all conditions. try { context.complete(); } catch (SQLException sqle) { context.abort(); } } } }; go.isDaemon(); go.start(); }
From source file:org.eclipse.che.api.fs.server.impl.FsOperations.java
void move(Path srcFsPath, Path dstFsPath) throws ServerException { try {/*from w w w.j a va 2s . c o m*/ if (Files.isDirectory(srcFsPath)) { FileUtils.moveDirectory(srcFsPath.toFile(), dstFsPath.toFile()); } else { FileUtils.moveFile(srcFsPath.toFile(), dstFsPath.toFile()); } } catch (IOException e) { throw new ServerException("Failed to move item " + srcFsPath + " to " + dstFsPath, e); } }
From source file:org.eclipse.che.api.fs.server.impl.FsOperations.java
void moveWithParents(Path srcFsPath, Path dstFsPath) throws ServerException { try {/*from w w w . ja v a2 s . co m*/ Files.createDirectories(dstFsPath.getParent()); if (Files.isDirectory(srcFsPath)) { FileUtils.moveDirectory(srcFsPath.toFile(), dstFsPath.toFile()); } else { FileUtils.moveFile(srcFsPath.toFile(), dstFsPath.toFile()); } } catch (IOException e) { throw new ServerException("Failed to move item " + srcFsPath + " to " + dstFsPath, e); } }
From source file:org.eclipse.smila.search.lucene.index.IndexAdmin.java
/** * {@inheritDoc}//from w w w.j av a 2s .c om * * @see org.eclipse.smila.search.index.IndexAdmin#renameIndex(java.lang.String, java.lang.String) */ @Override protected void renameIndex(final String indexName, final String newIndexName) throws IndexException { try { final File dataFolder = WorkspaceHelper.createWorkingDir(LuceneService.BUNDLE_NAME, indexName); final File newDataFolder = new File(dataFolder.getParentFile(), newIndexName); FileUtils.moveDirectory(dataFolder, newDataFolder); } catch (final IOException e) { throw new IndexException(e); } }
From source file:org.eclipse.wb.tests.utils.ProjectClassLoaderTest.java
/** * Move existing {@link IProject} into "subFolder" in workspace. * // w ww .j av a 2 s. c om * @return the new absolute location of project. */ public static String moveProjectIntoWorkspaceSubFolder() throws Exception { String newProjectLocation = workspaceLocation + "/subFolder/Test"; // move project content FileUtils.moveDirectory(new File(m_project.getLocation().toPortableString()), new File(newProjectLocation)); // delete old project m_project.delete(true, null); // create new project, in workspace sub-folder { IProjectDescription projectDescription = workspace.newProjectDescription("Test"); projectDescription.setLocation(new Path(newProjectLocation)); m_project = workspaceRoot.getProject("Test"); m_project.create(projectDescription, null); m_project.open(null); // update Java project m_testProject = new TestProject(m_project); m_javaProject = m_testProject.getJavaProject(); } return newProjectLocation; }
From source file:org.exist.repo.ExistRepository.java
private static void moveOldRepo(File home, File newRepo) { File repo_dir = null;//w w w . java 2 s .co m if (home != null) { if ("WEB-INF".equals(home.getName())) { repo_dir = new File(home, EXPATH_REPO_DIR); } else { repo_dir = new File(home, EXPATH_REPO_DEFAULT); } } else { repo_dir = new File(System.getProperty("java.io.tmpdir"), EXPATH_REPO_DIR); } if (repo_dir.exists() && repo_dir.canRead()) { LOG.info( "Found old expathrepo directory. Moving to new default location: " + newRepo.getAbsolutePath()); try { FileUtils.moveDirectory(repo_dir, newRepo); } catch (final IOException e) { LOG.error("Failed to move old expathrepo directory to new default location. Keeping it.", e); } } }