List of usage examples for org.apache.commons.io FileUtils moveDirectory
public static void moveDirectory(File srcDir, File destDir) throws IOException
From source file:com.turn.griffin.GriffinLibCacheUtil.java
public void moveFromTempCacheToLibCache(FileInfo fileInfo) throws IOException { FileUtils.moveDirectory(new File(getTempCacheDirectory(fileInfo)), new File(getLibCacheDirectory(fileInfo))); }
From source file:com.linkedin.pinot.core.data.manager.realtime.LLRealtimeSegmentDataManager.java
/** * * @param buildTgz true if you want the method to also build tgz file * @return true if all succeeds.//from w w w . j av a 2 s . c o m */ protected boolean buildSegment(boolean buildTgz) { // Build a segment from in-memory rows.If buildTgz is true, then build the tar.gz file as well // TODO Use an auto-closeable object to delete temp resources. File tempSegmentFolder = new File(_resourceTmpDir, "tmp-" + _segmentNameStr + "-" + String.valueOf(now())); // lets convert the segment now RealtimeSegmentConverter converter = new RealtimeSegmentConverter(_realtimeSegment, tempSegmentFolder.getAbsolutePath(), _schema, _segmentZKMetadata.getTableName(), _segmentZKMetadata.getSegmentName(), _sortedColumn, _invertedIndexColumns); logStatistics(); segmentLogger.info("Trying to build segment"); final long buildStartTime = now(); try { converter.build(_segmentVersion); } catch (Exception e) { segmentLogger.error("Could not build segment", e); FileUtils.deleteQuietly(tempSegmentFolder); return false; } final long buildEndTime = now(); segmentLogger.info("Successfully built segment in {} ms", (buildEndTime - buildStartTime)); File destDir = makeSegmentDirPath(); FileUtils.deleteQuietly(destDir); try { FileUtils.moveDirectory(tempSegmentFolder.listFiles()[0], destDir); if (buildTgz) { TarGzCompressionUtils.createTarGzOfDirectory(destDir.getAbsolutePath()); } } catch (IOException e) { segmentLogger.error("Exception during move/tar segment", e); FileUtils.deleteQuietly(tempSegmentFolder); return false; } FileUtils.deleteQuietly(tempSegmentFolder); return true; }
From source file:com.linkedin.pinot.core.segment.creator.impl.SegmentIndexCreationDriverImpl.java
private void handlePostCreation() throws Exception { // Build the segment name, if necessary final String timeColumn = config.getTimeColumnName(); if (config.getSegmentName() != null) { segmentName = config.getSegmentName(); } else {// www . j av a 2 s.co m if (timeColumn != null && timeColumn.length() > 0) { final Object minTimeValue = statsCollector.getColumnProfileFor(timeColumn).getMinValue(); final Object maxTimeValue = statsCollector.getColumnProfileFor(timeColumn).getMaxValue(); segmentName = SegmentNameBuilder.buildBasic(config.getTableName(), minTimeValue, maxTimeValue, config.getSegmentNamePostfix()); } else { segmentName = SegmentNameBuilder.buildBasic(config.getTableName(), config.getSegmentNamePostfix()); } } // Write the index files to disk indexCreator.setSegmentName(segmentName); indexCreator.seal(); LOGGER.info("Finished segment seal!"); // Delete the directory named after the segment name, if it exists final File outputDir = new File(config.getOutDir()); final File segmentOutputDir = new File(outputDir, segmentName); if (segmentOutputDir.exists()) { FileUtils.deleteDirectory(segmentOutputDir); } // Move the temporary directory into its final location FileUtils.moveDirectory(tempIndexDir, segmentOutputDir); // Delete the temporary directory FileUtils.deleteQuietly(tempIndexDir); // Compute CRC final long crc = CrcUtils.forAllFilesInFolder(segmentOutputDir).computeCrc(); // Persist creation metadata to disk persistCreationMeta(segmentOutputDir, crc); Map<String, MutableLong> nullCountMap = recordReader.getNullCountMap(); if (nullCountMap != null) { for (Map.Entry<String, MutableLong> entry : nullCountMap.entrySet()) { AbstractColumnStatisticsCollector columnStatisticsCollector = statsCollector .getColumnProfileFor(entry.getKey()); columnStatisticsCollector.setNumInputNullValues(entry.getValue().intValue()); } } LOGGER.info("Driver, record read time : {}", totalRecordReadTime); LOGGER.info("Driver, stats collector time : {}", totalStatsCollectorTime); LOGGER.info("Driver, indexing time : {}", totalIndexTime); }
From source file:ddf.test.itests.platform.TestConfiguration.java
/** * Tests that when ws-security directory is missing, export fails *//*from w w w. j ava 2 s .c o m*/ @Test public void testExportFailureWithoutWSSecurityDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveDirectory(WS_SECURITY.toFile(), WS_SECURITY_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat(String.format("Should not have been able to export to %s.", getDefaultExportDirectory()), response, containsString("An error was encountered while executing this command.")); }
From source file:ddf.test.itests.platform.TestConfiguration.java
/** * Tests that when system properties file is missing, export fails * * @throws Exception/*from www . ja va 2s. c o m*/ */ @Test public void testExportFailureWithoutPDPDirectory() throws Exception { closeFileHandlesInEtc(); resetInitialState(); FileUtils.moveDirectory(PDP.toFile(), PDP_COPY.toFile()); String response = console.runCommand(EXPORT_COMMAND); assertThat( String.format("Warning should have been returned when exporting to %s.", getDefaultExportDirectory()), response, containsString("Path [etc" + FILE_SEPARATOR + "pdp] does not exist or cannot be read; therefore, it will not be included in the export.")); }
From source file:com.alibaba.jstorm.blobstore.BlobStoreUtils.java
/** * no need to synchronize, since EventManager will execute sequentially *///from ww w.j a v a 2s .c o m public static void downloadDistributeStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException { String tmpToot = null; try { // STORM_LOCAL_DIR/supervisor/tmp/(UUID) tmpToot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString(); // STORM_LOCAL_DIR/supervisor/stormdist/topologyId String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId); // JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true); JStormServerUtils.downloadCodeFromBlobStore(conf, tmpToot, topologyId); // tmproot/stormjar.jar String localFileJarTmp = StormConfig.stormjar_path(tmpToot); // extract dir from jar JStormUtils.extractDirFromJar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmpToot); File srcDir = new File(tmpToot); File destDir = new File(stormRoot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } } finally { if (tmpToot != null) { File srcDir = new File(tmpToot); FileUtils.deleteQuietly(srcDir); } } }
From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java
/** * Displays a "Rename" dialog and renames the specified file/folder. * * @param path The path of the folder/file that needs to be renamed. *///from ww w .j av a 2 s.co m public void rename(String path) { final File renameFile = new File(path); final AlertDialog renameAlertDialog = new AlertDialog.Builder(getActivity()).create(); final EditText fileEditText = new EditText(getActivity()); fileEditText.setHint(R.string.file_name); fileEditText.setSingleLine(true); fileEditText.setText(renameFile.getName()); renameAlertDialog.setView(fileEditText); renameAlertDialog.setTitle(R.string.rename); renameAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { renameAlertDialog.dismiss(); } }); renameAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE, mContext.getResources().getString(R.string.rename), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Check if the new file name is empty. if (fileEditText.getText().toString().isEmpty()) { Toast.makeText(getActivity(), R.string.enter_a_name_for_folder, Toast.LENGTH_LONG) .show(); } else { File newNameFile = null; try { newNameFile = new File(renameFile.getParentFile().getCanonicalPath() + "/" + fileEditText.getText().toString()); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed, Toast.LENGTH_LONG).show(); return; } try { if (renameFile.isDirectory()) FileUtils.moveDirectory(renameFile, newNameFile); else FileUtils.moveFile(renameFile, newNameFile); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed, Toast.LENGTH_LONG).show(); return; } Toast.makeText(getActivity(), R.string.folder_renamed, Toast.LENGTH_SHORT).show(); renameAlertDialog.dismiss(); refreshListView(); } } }); renameAlertDialog.show(); }
From source file:hudson.model.Job.java
@Override public void movedTo(DirectlyModifiableTopLevelItemGroup destination, AbstractItem newItem, File destDir) throws IOException { Job newJob = (Job) newItem; // Missing covariant parameters type here. File oldBuildDir = getBuildDir(); super.movedTo(destination, newItem, destDir); File newBuildDir = getBuildDir(); if (oldBuildDir.isDirectory()) { FileUtils.moveDirectory(oldBuildDir, newBuildDir); }//from w ww . j a v a2 s . c om }
From source file:com.manydesigns.portofino.actions.admin.page.PageAdminAction.java
protected Resolution copyPage(String destinationPagePath, String newName, boolean deleteOriginal) { if (StringUtils.isEmpty(destinationPagePath)) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.must.select.a.destination")); return new RedirectResolution(originalPath); }//from w w w .j a va 2s . co m PageInstance pageInstance = getPageInstance(); PageInstance oldParent = pageInstance.getParent(); if (oldParent == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.copy.or.move.the.root.page")); return new RedirectResolution(originalPath); } if (deleteOriginal) { logger.debug("Checking if we've been asked to move the landing page..."); Dispatcher dispatcher = DispatcherUtil.get(context.getRequest()); String contextPath = context.getRequest().getContextPath(); String landingPagePath = portofinoConfiguration.getString(PortofinoProperties.LANDING_PAGE); Dispatch landingPageDispatch = dispatcher.getDispatch(landingPagePath); if (landingPageDispatch != null && landingPageDispatch.getLastPageInstance().getDirectory() .equals(pageInstance.getDirectory())) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.move.the.landing.page")); return new RedirectResolution(originalPath); } } PageInstance newParent; if ("/".equals(destinationPagePath)) { File dir = pagesDir; try { newParent = new PageInstance(null, dir, DispatcherLogic.getPage(dir), null); } catch (Exception e) { throw new Error("Couldn't load root page", e); } } else { Dispatcher dispatcher = DispatcherUtil.get(context.getRequest()); Dispatch destinationDispatch = dispatcher.getDispatch(destinationPagePath); //TODO gestione eccezioni newParent = destinationDispatch.getLastPageInstance(); } if (newParent.getDirectory().equals(oldParent.getDirectory())) { List<String> params = newParent.getParameters(); newParent = new PageInstance(newParent.getParent(), newParent.getDirectory(), oldParent.getPage(), null); newParent.getParameters().addAll(params); } //Check permissions on target parent page Subject subject = SecurityUtils.getSubject(); if (!SecurityLogic.hasPermissions(portofinoConfiguration, newParent, subject, AccessLevel.EDIT)) { SessionMessages.addErrorMessage( ElementsThreadLocals.getText("you.dont.have.edit.access.level.on.the.destination.page")); return new RedirectResolution(originalPath); } if (newParent != null) { //TODO vedi sopra newName = StringUtils.isEmpty(newName) ? pageInstance.getName() : newName; File newDirectory = newParent.getChildPageDirectory(newName); File newParentDirectory = newDirectory.getParentFile(); logger.debug("Ensuring that new parent directory {} exists", newParentDirectory); ElementsFileUtils.safeMkdirs(newParentDirectory); if (!newDirectory.exists()) { try { Iterator<ChildPage> it = oldParent.getLayout().getChildPages().iterator(); ChildPage oldChildPage = null; String oldName = pageInstance.getName(); while (it.hasNext()) { oldChildPage = it.next(); if (oldChildPage.getName().equals(oldName)) { if (deleteOriginal) { it.remove(); } break; } } if (deleteOriginal) { logger.debug("Removing from old parent"); DispatcherLogic.savePage(oldParent.getDirectory(), oldParent.getPage()); logger.debug("Moving directory"); FileUtils.moveDirectory(pageInstance.getDirectory(), newDirectory); } else { logger.debug("Copying directory"); FileUtils.copyDirectory(pageInstance.getDirectory(), newDirectory); logger.debug("Generating a new Id for the new page"); Page newPage = DispatcherLogic.getPage(newDirectory); String pageId = RandomUtil.createRandomId(); newPage.setId(pageId); DispatcherLogic.savePage(newDirectory, newPage); } logger.debug("Registering the new child page in parent page (directory: {})", newDirectory); ChildPage newChildPage = new ChildPage(); newChildPage.setName(newName); if (oldChildPage != null) { newChildPage.setShowInNavigation(oldChildPage.isShowInNavigation()); } else { newChildPage.setShowInNavigation(true); } newParent.getLayout().getChildPages().add(newChildPage); DispatcherLogic.savePage(newParent.getDirectory(), newParent.getPage()); } catch (Exception e) { logger.error("Couldn't copy/move page", e); String msg = ElementsThreadLocals.getText("page.copyOrMove.failed", destinationPagePath); SessionMessages.addErrorMessage(msg); } } else { String msg = ElementsThreadLocals.getText("destination.is.an.existing.file/directory._", newDirectory.getAbsolutePath()); SessionMessages.addErrorMessage(msg); return new RedirectResolution(originalPath); } if (newParent.getParameters().isEmpty()) { return new RedirectResolution( destinationPagePath + (destinationPagePath.endsWith("/") ? "" : "/") + newName); } else { //Detail newParent.getParameters().clear(); return new RedirectResolution(newParent.getPath()); } } else { String msg = ElementsThreadLocals.getText("invalid.destination._", destinationPagePath); SessionMessages.addErrorMessage(msg); return new RedirectResolution(originalPath); } }
From source file:com.alibaba.jstorm.blobstore.BlobStoreUtils.java
public static void downloadLocalStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException { // STORM_LOCAL_DIR/supervisor/tmp/(UUID) String tmpRoot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString(); // STORM-LOCAL-DIR/supervisor/stormdist/storm-id String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId); BlobStore blobStore = null;//from ww w . j a v a 2s . c om try { blobStore = BlobStoreUtils.getNimbusBlobStore(conf, masterCodeDir, null); FileUtils.forceMkdir(new File(tmpRoot)); blobStore.readBlobTo(StormConfig.master_stormcode_key(topologyId), new FileOutputStream(StormConfig.stormcode_path(tmpRoot))); blobStore.readBlobTo(StormConfig.master_stormconf_key(topologyId), new FileOutputStream(StormConfig.stormconf_path(tmpRoot))); } finally { if (blobStore != null) blobStore.shutdown(); } File srcDir = new File(tmpRoot); File destDir = new File(stormRoot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); String resourcesJar = resourcesJar(); URL url = classloader.getResource(StormConfig.RESOURCES_SUBDIR); String targetDir = stormRoot + '/' + StormConfig.RESOURCES_SUBDIR; if (resourcesJar != null) { LOG.info("Extracting resources from jar at " + resourcesJar + " to " + targetDir); JStormUtils.extractDirFromJar(resourcesJar, StormConfig.RESOURCES_SUBDIR, stormRoot); } else if (url != null) { LOG.info("Copying resources at " + url.toString() + " to " + targetDir); FileUtils.copyDirectory(new File(url.getFile()), (new File(targetDir))); } }