Example usage for org.apache.commons.io FileUtils moveDirectory

List of usage examples for org.apache.commons.io FileUtils moveDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils moveDirectory.

Prototype

public static void moveDirectory(File srcDir, File destDir) throws IOException 

Source Link

Document

Moves a directory.

Usage

From source file:eu.udig.catalog.jgrass.operations.RenameMapAction.java

/**
 * Given the mapsetpath and the old and new mapname, the map is renamed with all its accessor files
 * //from w  w  w  .ja va  2  s. co m
 * @param mapsetPath the mapset path.
 * @param oldMapName the old map name.
 * @param newMapName the new map name.
 * @throws IOException
 */
private void renameGrassRasterMap(String mapsetPath, String oldMapName, String newMapName) throws IOException {
    // list of files to remove
    String mappaths[] = JGrassCatalogUtilities.filesOfRasterMap(mapsetPath, oldMapName);

    // first delete the list above, which are just files
    for (int j = 0; j < mappaths.length; j++) {
        File filetorename = new File(mappaths[j]);
        if (filetorename.exists()) {
            File parentFile = filetorename.getParentFile();
            File renamedFile = new File(parentFile, newMapName);

            if (filetorename.isDirectory()) {
                FileUtils.moveDirectory(filetorename, renamedFile);
            } else if (filetorename.isFile()) {
                FileUtils.moveFile(filetorename, renamedFile);
            } else {
                throw new IOException("File type not defined");
            }

        }
    }
}

From source file:com.enonic.cms.web.webdav.DavResourceImpl.java

@Override
public void move(final DavResource target) throws DavException {
    if (!exists()) {
        throw new DavException(DavServletResponse.SC_NOT_FOUND);
    }/*from ww w  .j  av a 2s. c om*/

    final File targetFile = ((DavResourceImpl) target).file;

    try {
        if (isCollection()) {
            FileUtils.moveDirectory(this.file, targetFile);
        } else {
            FileUtils.moveFile(this.file, targetFile);
        }
    } catch (final IOException e) {
        throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}

From source file:com.linkedin.pinot.core.data.manager.realtime.RealtimeTableDataManager.java

public void downloadAndReplaceSegment(final String segmentNameStr,
        LLCRealtimeSegmentZKMetadata llcSegmentMetadata) {
    final String uri = llcSegmentMetadata.getDownloadUrl();
    File tempSegmentFolder = new File(_indexDir, "tmp-" + String.valueOf(System.currentTimeMillis()));
    File tempFile = new File(_indexDir, segmentNameStr + ".tar.gz");
    try {/*from   www  .  j a v  a  2s  . co  m*/
        SegmentFetcherFactory.getSegmentFetcherBasedOnURI(uri).fetchSegmentToLocal(uri, tempFile);
        LOGGER.info("Downloaded file from {} to {}; Length of downloaded file: {}", uri, tempFile,
                tempFile.length());
        TarGzCompressionUtils.unTar(tempFile, tempSegmentFolder);
        FileUtils.deleteQuietly(tempFile);
        FileUtils.moveDirectory(tempSegmentFolder.listFiles()[0], new File(_indexDir, segmentNameStr));
        LOGGER.info("Replacing LLC Segment {}", segmentNameStr);
        replaceLLSegment(segmentNameStr);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        FileUtils.deleteQuietly(tempSegmentFolder);
    }
    return;
}

From source file:com.alibaba.jstorm.daemon.supervisor.SyncSupervisorEvent.java

/**
 * Don't need synchronize, due to EventManager will execute serially
 * /*from w w  w.  j a va2 s .c o  m*/
 * @param conf
 * @param topologyId
 * @param masterCodeDir
 * @throws IOException
 * @throws TException
 */
private void downloadDistributeStormCode(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/topologyId
    String stormroot = StormConfig.supervisor_stormdist_root(conf, topologyId);

    JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true);

    // tmproot/stormjar.jar
    String localFileJarTmp = StormConfig.stormjar_path(tmproot);

    // extract dir from jar
    JStormUtils.extract_dir_from_jar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmproot);

    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);
    }
}

From source file:com.ephesoft.dcma.gwt.foldermanager.server.FolderManagerServiceImpl.java

@Override
public Boolean cutFiles(List<String> cutFilesList, String currentFolderPath) throws GWTException {
    for (String filePath : cutFilesList) {
        File srcFile = new File(filePath);
        String fileName = srcFile.getName();
        if (srcFile.exists()) {
            try {
                String newPathName = currentFolderPath + File.separator + srcFile.getName();
                File newFile = new File(newPathName);
                if (!newFile.exists()) {
                    if (srcFile.isFile()) {
                        FileUtils.moveFile(srcFile, newFile);
                    } else {
                        FileUtils.moveDirectory(srcFile, newFile);
                    }//www. j  a va  2s  . c  o m
                } else {
                    throw new GWTException(
                            FolderManagementMessages.CANNOT_COMPLETE_CUT_PASTE_OPERATION_AS_THE_FILE_FOLDER
                                    + fileName + FolderManagementMessages.ALREADY_EXISTS);
                }
            } catch (IOException e) {
                LOGGER.error(
                        FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_CUT_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION
                                + e.getMessage());
                throw new GWTException(
                        FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_CUT_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION,
                        e);
            }
        } else {
            throw new GWTException(
                    FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_CUT_PASTE_OPERATION_FILE_NOT_FOUND
                            + FolderManagementConstants.QUOTES + srcFile.getName()
                            + FolderManagementConstants.QUOTES);
        }
    }
    return true;
}

From source file:com.alibaba.jstorm.schedule.FollowerRunnable.java

private void downloadCodeFromMaster(Assignment assignment, String topologyId) throws IOException, TException {
    try {//from   w  w  w.ja  v a  2  s.c o m
        String localRoot = StormConfig.masterStormdistRoot(data.getConf(), topologyId);
        String tmpDir = StormConfig.masterInbox(data.getConf()) + "/" + UUID.randomUUID().toString();
        String masterCodeDir = assignment.getMasterCodeDir();
        JStormServerUtils.downloadCodeFromMaster(data.getConf(), tmpDir, masterCodeDir, topologyId, false);

        File srcDir = new File(tmpDir);
        File destDir = new File(localRoot);
        try {
            FileUtils.moveDirectory(srcDir, destDir);
        } catch (FileExistsException e) {
            FileUtils.copyDirectory(srcDir, destDir);
            FileUtils.deleteQuietly(srcDir);
        }
        // Update downloadCode timeStamp
        StormConfig.write_nimbus_topology_timestamp(data.getConf(), topologyId, System.currentTimeMillis());
    } catch (TException e) {
        // TODO Auto-generated catch block
        LOG.error(e + " downloadStormCode failed " + "topologyId:" + topologyId + "masterCodeDir:"
                + assignment.getMasterCodeDir());
        throw e;
    }
    LOG.info("Finished downloading code for topology id " + topologyId + " from "
            + assignment.getMasterCodeDir());
}

From source file:edu.isi.wings.portal.controllers.ComponentController.java

public boolean renameComponentItem(String cid, String path, String newname) {
    try {//from w ww. j a v  a 2s.com
        String loc = cc.getComponentLocation(cid);
        if (loc != null && path != null) {
            loc = loc + "/" + path;
            File f = new File(loc);
            File newf = new File(f.getParent() + newname);
            if (!newf.exists()) {
                if (f.isDirectory())
                    FileUtils.moveDirectory(f, newf);
                else if (f.isFile())
                    FileUtils.moveFile(f, newf);
                return true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        cc.end();
        dc.end();
        prov.end();
    }
    return false;
}

From source file:com.xiaomi.linden.core.search.MultiLindenCoreImpl.java

public synchronized LindenCore getLindenCore(String indexName) throws IOException {
    LindenCore lindenCore = lindenCoreMap.get(indexName);
    if (lindenCore == null) {
        lindenCore = new LindenCoreImpl(config, indexName);
        lindenCoreMap.put(indexName, lindenCore);
        if (config.getMultiIndexMaxLiveIndexNum() != -1
                && config.getMultiIndexMaxLiveIndexNum() < lindenCoreMap.size()) {
            List<String> keys = new ArrayList<>(lindenCoreMap.keySet());
            Collections.sort(keys, new Comparator<String>() {
                @Override// ww  w.  j a  va 2  s  . c om
                public int compare(String o1, String o2) {
                    return o1.compareTo(o2);
                }
            });
            String oldestIndexName = keys.get(0);
            LindenCore core = lindenCoreMap.remove(oldestIndexName);
            core.close();

            if (config.getIndexType() != LindenConfig.IndexType.RAM) {
                String dir = FilenameUtils.concat(baseIndexDir, oldestIndexName);
                String destDir = FilenameUtils.concat(baseIndexDir,
                        EXPIRED_INDEX_NAME_PREFIX + oldestIndexName);
                if (new File(dir).exists()) {
                    FileUtils.moveDirectory(new File(dir), new File(destDir));
                }
            }
        }
    }
    return lindenCore;
}

From source file:aurelienribon.gdxsetupui.ProjectSetup.java

/**
 * Launchers and packages are set up according to the user choices.
 * @throws IOException/*  www.  j  av  a  2  s.  co m*/
 */
public void postProcess() throws IOException {
    {
        File src = new File(tmpDst, "prj-common");
        File dst = new File(tmpDst, cfg.projectName + cfg.suffixCommon);
        move(src, "src/MyGame.java",
                "src/" + cfg.packageName.replace('.', '/') + "/" + cfg.mainClassName + ".java");
        move(src, "src/MyGame.gwt.xml", "src/" + cfg.mainClassName + ".gwt.xml");
        templateDir(src);
        FileUtils.moveDirectory(src, dst);
    }

    if (cfg.isDesktopIncluded) {
        File src = new File(tmpDst, "prj-desktop");
        File dst = new File(tmpDst, cfg.projectName + cfg.suffixDesktop);
        move(src, "src/Main.java", "src/" + cfg.packageName.replace('.', '/') + "/Main.java");
        templateDir(src);
        FileUtils.moveDirectory(src, dst);
    }

    if (cfg.isAndroidIncluded) {
        File src = new File(tmpDst, "prj-android");
        File dst = new File(tmpDst, cfg.projectName + cfg.suffixAndroid);
        move(src, "src/MainActivity.java", "src/" + cfg.packageName.replace('.', '/') + "/MainActivity.java");
        templateDir(src);
        FileUtils.moveDirectory(src, dst);
    }

    if (cfg.isHtmlIncluded) {
        File src = new File(tmpDst, "prj-html");
        File dst = new File(tmpDst, cfg.projectName + cfg.suffixHtml);
        move(src, "src/GwtDefinition.gwt.xml",
                "src/" + cfg.packageName.replace('.', '/') + "/GwtDefinition.gwt.xml");
        move(src, "src/client", "src/" + cfg.packageName.replace('.', '/') + "/client");
        templateDir(src);
        FileUtils.moveDirectory(src, dst);
    }

    if (cfg.isIosIncluded) {
        File src = new File(tmpDst, "prj-ios");
        File dst = new File(tmpDst, cfg.projectName + cfg.suffixIos);
        move(src, "my-gdx-game-ios.csproj", cfg.projectName + cfg.suffixIos + ".csproj");
        move(src, "my-gdx-game-ios.sln", cfg.projectName + cfg.suffixIos + ".sln");
        templateDir(src);
        FileUtils.moveDirectory(src, dst);
    }
}

From source file:de.uzk.hki.da.cb.RestructureAction.java

static void revertToSIPContent(Path objectPath, Path dataPath, String repName) throws IOException {
    final String A = "a";
    final String DATA_TMP = WorkArea.DATA + UNDERSCORE;
    if (isNotSet(repName))
        throw new IllegalArgumentException("rep name not set");
    if (isNotSet(dataPath))
        throw new IllegalArgumentException("data path not set");
    if (isNotSet(objectPath))
        throw new IllegalArgumentException("object path not set");

    FileUtils.moveDirectory(Path.makeFile(dataPath, repName + A), Path.makeFile(objectPath, DATA_TMP));

    FolderUtils.deleteDirectorySafe(dataPath.toFile());

    FileUtils.moveDirectory(Path.makeFile(objectPath, DATA_TMP), Path.makeFile(dataPath));
}