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

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

Introduction

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

Prototype

public static void moveFile(File srcFile, File destFile) throws IOException 

Source Link

Document

Moves a file.

Usage

From source file:aurelienribon.gdxsetupui.ui.panels.LibrarySelectionPanel.java

private void getFile(final String input, final String output, final String libraryName, String tag) {
    OutputStream tempOutput;//  w w w .java  2s. c  o  m
    try {
        tempOutput = new BufferedOutputStream(new FileOutputStream(output + ".tmp"));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

    DownloadTask task = HttpUtils.downloadAsync(input, tempOutput, tag);

    task.addListener(new DownloadListener() {
        @Override
        public void onComplete() {
            try {
                FileUtils.deleteQuietly(new File(output));
                FileUtils.moveFile(new File(output + ".tmp"), new File(output));
            } catch (IOException ex) {
                String msg = "Could not rename \"" + output + ".tmp" + "\" into \"" + output + "\"";
                JOptionPane.showMessageDialog(SwingUtils.getJFrame(LibrarySelectionPanel.this), msg);
            }
            select(libraryName, new File(output));
        }
    });
}

From source file:com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor.java

private void patchEmulator() throws IOException {
    Logger.info("Verifying the emulator binary.");
    Properties config = new Properties();
    config.loadFromXML(new FileInputStream(new File(mOutputDir, "/config/config.xml")));
    String emulatorName = config.getProperty("emulator_name", "libjava-activity.so");
    File origEmulator = new File(mOutputDir, "/lib/armeabi/" + emulatorName);
    String emulatorCRC32 = Long.toHexString(FileUtils.checksumCRC32(origEmulator));
    if (!emulatorCRC32.equalsIgnoreCase(config.getProperty("emulator_crc32")))
        throw new UnsupportedOperationException(
                "The emulator checksum is invalid. Cannot patch. CRC32: " + emulatorCRC32);
    File newEmulator = new File(mOutputDir, "/lib/armeabi/libjava-activity-patched.so");
    File emulatorPatch = new File(mOutputDir, "/config/" + config.getProperty("emulator_patch", ""));
    if (emulatorPatch.equals("")) {
        Logger.info("No patch needed.");
        FileUtils.moveFile(origEmulator, newEmulator);
    } else {/*from  w  w w. ja  v  a  2  s . com*/
        Logger.info("Patching emulator.");
        newEmulator.createNewFile();
        JBPatch.bspatch(origEmulator, newEmulator, emulatorPatch);
        emulatorPatch.delete();
    }
    FileUtils.copyInputStreamToFile(
            PSXperiaTool.class.getResourceAsStream("/resources/libjava-activity-wrapper.so"), origEmulator);
}

From source file:com.fota.commMgt.controller.FirmCTR.java

@RequestMapping(value = "/upload/submitCreateDdfPkg")
@ResponseBody/*from ww  w.ja v  a  2s. c o  m*/
public ModelAndView createDdfFiles(HttpServletRequest request, HttpServletResponse response, ModelMap model)
        throws Exception {
    //      logger.warn("CreateDdfFileCTR - createDdfFiles() start \r\n");
    String resultMsg = "";

    // root ?? ?  ? ?
    File rootDir = new File(gSaveFilePath);
    if (!rootDir.exists() || !rootDir.isDirectory()) {
        rootDir.mkdirs();
    }

    // ? ??
    String dirPath = gSaveFilePath + "ddfPkg/";
    File dir = new File(dirPath);
    if (!dir.exists() || !dir.isDirectory()) {
        dir.mkdirs();
    }

    String userId = ((UserLoginVO) request.getSession().getAttribute("userInfo")).getUserId();

    //  ??
    String dirTempPath = gSaveFilePath + "ddfPkgTmp/" + userId + "/";
    File dirTemp = new File(dirTempPath);
    if (!dirTemp.exists() || !dirTemp.isDirectory()) {
        dirTemp.mkdirs();
    }
    //  ??? ??   
    if (dirTemp.exists() && dirTemp.isDirectory()) {
        String[] tempFiles = dirTemp.list();
        if (tempFiles != null) {
            for (int i = 0; i < tempFiles.length; i++) {
                String tempFileName = tempFiles[i];
                File tempFile = new File(dirTempPath + tempFileName);
                if (tempFile.exists()) {
                    tempFile.delete();
                }
            }
        }
    }

    ///////// Diffgen ?   ? start //////////
    String diffGemPath = gSaveFilePath + "ddfPkg/" + "ori";
    File diffGemDir = new File(diffGemPath);
    if (!diffGemDir.exists() || !diffGemDir.isDirectory()) {
        diffGemDir.mkdirs();
    }
    diffGemPath = gSaveFilePath + "ddfPkg/" + "dest";
    diffGemDir = new File(diffGemPath);
    if (!diffGemDir.exists() || !diffGemDir.isDirectory()) {
        diffGemDir.mkdirs();
    }
    diffGemPath = gSaveFilePath + "ddfPkg/" + "diff";
    diffGemDir = new File(diffGemPath);
    if (!diffGemDir.exists() || !diffGemDir.isDirectory()) {
        diffGemDir.mkdirs();
    }
    diffGemPath = gSaveFilePath + "ddfPkg/" + "temp";
    diffGemDir = new File(diffGemPath);
    if (!diffGemDir.exists() || !diffGemDir.isDirectory()) {
        diffGemDir.mkdirs();
    }
    ///////// Diffgen ?   ? end //////////

    MultipartRequest multi = null;
    List<File> getCurrentVerFirmList = new ArrayList<File>();
    List<File> getUpdateVerFirmList = new ArrayList<File>();

    try {
        multi = new MultipartRequest(request, dirTempPath, MAX_FILE_SIZE, "utf-8");

        String modelName = multi.getParameter("model");
        int imgCnt = Integer.parseInt(multi.getParameter("imgCnt"));

        //         logger.warn(" >>>>> Create Diff Pkg Vo Info 1 <<<<<\r\n"
        //               + "model : " + modelName + ", imgCnt : " + imgCnt);

        ArrayList<CreateDdfFileInfoVo> ddfList = new ArrayList<CreateDdfFileInfoVo>();

        CreateDdfFileInfoVo tempDdfVo = null;
        File currentTempFile = null;
        File updateTempFile = null;
        for (int i = 1; i <= imgCnt; i++) {
            tempDdfVo = new CreateDdfFileInfoVo();

            tempDdfVo.setImageType(multi.getParameter("imageType" + i));
            tempDdfVo.setCurrentVer(multi.getParameter("currentVer" + i));
            tempDdfVo.setCurrentVerFirm(multi.getParameter("currentVerFirm" + i));
            tempDdfVo.setCurrentVerFirmSize(multi.getParameter("currentVerFirm" + i + "Size"));
            tempDdfVo.setCurrentVerFirmPath(dirPath + tempDdfVo.getCurrentVerFirm());
            tempDdfVo.setUpdateVer(multi.getParameter("updateVer" + i));
            tempDdfVo.setUpdateVerFirm(multi.getParameter("updateVerFirm" + i));
            tempDdfVo.setUpdateVerFirmSize(multi.getParameter("updateVerFirm" + i + "Size"));
            tempDdfVo.setUpdateVerFirmPath(dirPath + tempDdfVo.getUpdateVerFirm());
            tempDdfVo.setDiffName(multi.getParameter("diffName" + i));

            ddfList.add(tempDdfVo);

            //  ???  
            currentTempFile = new File(dirTempPath + multi.getFilesystemName("currentVerFirm" + i + "File"));
            getCurrentVerFirmList.add(currentTempFile);

            updateTempFile = new File(dirTempPath + multi.getFilesystemName("updateVerFirm" + i + "File"));
            getUpdateVerFirmList.add(updateTempFile);

            //  ?? ?    ? ?
            //            currentTempFile = new File(dirPath + multi.getFilesystemName("currentVerFirm" + i + "File"));
            //            updateTempFile = new File(dirPath + multi.getFilesystemName("updateVerFirm" + i + "File"));

            //            logger.warn(">>>>> Image Info [" + i + "]\r\n"
            //                  + "imageType : " + tempDdfVo.getImageType() + "\r\n"
            //                  + "currentVer : " + tempDdfVo.getCurrentVer() + "\r\n"
            //                  + "currentVerFirm : " + tempDdfVo.getCurrentVerFirm() + "\r\n"
            //                  + "currentVerFirmSize : " + tempDdfVo.getCurrentVerFirmSize() + "\r\n"
            //                  + "currentVerFirmPath : " + tempDdfVo.getCurrentVerFirmPath() + "\r\n"
            //                  + "updateVer : " + tempDdfVo.getUpdateVer() + "\r\n"
            //                  + "updateVerFirm : " + tempDdfVo.getUpdateVerFirm() + "\r\n"
            //                  + "updateVerFirmSize : " + tempDdfVo.getUpdateVerFirmSize() + "\r\n"
            //                  + "updateVerFirmPath : " + tempDdfVo.getUpdateVerFirmPath() + "\r\n"
            //                  + "diffName : " + tempDdfVo.getDiffName() + "\r\n"
            //                  + "------------------------------------------------------"
            //                  );
        }

        destCurrentVerFirmList.clear();
        destUpdateVerFirmList.clear();

        //   ???
        for (int i = 0; i < imgCnt; i++) {
            currentTempFile = new File(dirPath + getCurrentVerFirmList.get(i).getName());
            FileUtils.moveFile(getCurrentVerFirmList.get(i), currentTempFile);
            destCurrentVerFirmList.add(currentTempFile);

            updateTempFile = new File(dirPath + getUpdateVerFirmList.get(i).getName());
            FileUtils.moveFile(getUpdateVerFirmList.get(i), updateTempFile);
            destUpdateVerFirmList.add(updateTempFile);
        }

        resultMsg = "1";

        ////////////////////////////////////////////////////////////////////////////////////////////
        //   ? DM ?   ?? ...
        ddfPkgVo.setModel(modelName);
        if (ddfPkgVo.getImages() != null && ddfPkgVo.getImages().size() > 0) {
            ddfPkgVo.getImages().clear();
        }
        ddfPkgVo.setImages(ddfList);

        //  ? ?? ?
        // /jboss/lib/libJniDiffgen.so ??  
        PackageGenerator pkg = new PackageGenerator();
        String diffDownPath = pkg.makeDiffPackage(ddfPkgVo);
        //         String diffDownPath = "/firmwareDiff/ddfPkg/Download_TEST.txt"; 

        String[] diffDownPathSplit = diffDownPath.split("\\/");
        String diffDownFileName = diffDownPathSplit[diffDownPathSplit.length - 1];
        String diffDownFilePath = "";
        for (int i = 0; i < diffDownPathSplit.length - 1; i++) {
            diffDownFilePath += diffDownPathSplit[i] + "/";
        }

        //         logger.warn("file down..... name : " + diffDownFileName + ", path : " + diffDownFilePath + ", total : " + diffDownPath);

        //   ??  ?  
        for (int i = 0; i < destCurrentVerFirmList.size(); i++) {
            if (destCurrentVerFirmList.get(i) != null && destCurrentVerFirmList.get(i).exists()) {
                destCurrentVerFirmList.get(i).delete();
            }
        }
        for (int i = 0; i < destUpdateVerFirmList.size(); i++) {
            if (destUpdateVerFirmList.get(i) != null && destUpdateVerFirmList.get(i).exists()) {
                destUpdateVerFirmList.get(i).delete();
            }
        }

        //         logger.warn("diff pkg process completed... so files delete");

        model.addAttribute("diffDownPath", diffDownPath);
    } catch (Exception e) { //  ?? 
        // ??? ? ?          
        if (getCurrentVerFirmList.size() > 0) {
            for (int i = 0; i < getCurrentVerFirmList.size(); i++) {
                if (getCurrentVerFirmList.get(i) != null && getCurrentVerFirmList.get(i).exists()) {
                    getCurrentVerFirmList.get(i).delete();
                }
            }
        }
        if (getUpdateVerFirmList.size() > 0) {
            for (int i = 0; i < getUpdateVerFirmList.size(); i++) {
                if (getUpdateVerFirmList.get(i) != null && getUpdateVerFirmList.get(i).exists()) {
                    getUpdateVerFirmList.get(i).delete();
                }
            }
        }

        logger.error("createDdfFiles() exception : " + e.getMessage());

        //         resultMsg = e.getMessage();
        //         if(resultMsg.indexOf("exceeds") != 0){
        //            model.addAttribute("resultMsg", resultMsg );   
        //         }

        //         resultMsg = "? .";
        resultMsg = "0";

        //         logger.info("File update error : " + errorMSG);
        response.setStatus(500);
    }

    model.addAttribute("resultMsg", resultMsg);

    return new ModelAndView(ajaxMainView, model);
}

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void renameObject(String[] backup, String bucket, String oldName, String newName) throws IOException {
    if (backup == null || bucket == null || oldName == null || newName == null)
        return;//from   w  w  w. jav a 2 s .c  o m

    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + oldName);
    File newObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + newName);

    if (oldObjectFile.exists()) {
        if (newObjectFile.exists()) {
            backup[0] = new String(
                    rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + newName + ".backup");
            File backupFile = new File(backup[0]);
            if (backupFile.exists()) {
                FileUtils.forceDelete(backupFile);
            }
            FileUtils.moveFile(newObjectFile, backupFile);
        }
        FileUtils.moveFile(oldObjectFile, newObjectFile);
    }
}

From source file:de.uzk.hki.da.sb.SIPFactory.java

private Feedback moveFile(File tmpArchiveFile, File archiveFile) {
    try {//from   www .  j  a  v  a2  s .  c  o  m
        try {
            FileUtils.moveFile(tmpArchiveFile, archiveFile);
        } catch (FileExistsException e) {
            archiveFile.delete();
            FileUtils.moveFile(tmpArchiveFile, archiveFile);
        }
    } catch (IOException e) {
        logger.error("Failed to copy " + tmpArchiveFile + " to " + archiveFile);
        return Feedback.ARCHIVE_ERROR;
    }
    return Feedback.SUCCESS;
}

From source file:mesclasses.view.RootLayoutController.java

@FXML
public void onExport() {
    File archive;/*from w  ww  . j a va 2  s.c o  m*/
    try {
        archive = FileSaveUtil.archive();
    } catch (IOException e) {
        notif(e);
        return;
    }
    FileChooser chooser = new FileChooser();
    chooser.setTitle("Sauvegardez les donnes");
    chooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Archive MesClasses", "*.zip"));
    LOG.info("archiving in " + archive.getPath());
    chooser.setInitialFileName(FilenameUtils.getName(archive.getPath()));
    File file = chooser.showSaveDialog(primaryStage);
    if (file != null) {
        try {
            FileUtils.moveFile(archive, file);
        } catch (IOException ex) {
            notif(ex);
        }
        displayNotification(MessageEvent.SUCCESS, "Donnes sauvegardes");
    }

}

From source file:com.enioka.jqm.tools.JobManagerHandler.java

private Integer addDeliverable(String path, String fileLabel) throws IOException {
    Deliverable d = null;//  w w  w  .  ja  v a  2 s. com
    EntityManager em = Helpers.getNewEm();
    try {
        this.ji = em.find(JobInstance.class, ji.getId());

        String outputRoot = this.ji.getNode().getDlRepo();
        String ext = FilenameUtils.getExtension(path);
        String relDestPath = "" + ji.getJd().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID()
                + "." + ext;
        String absDestPath = FilenameUtils.concat(outputRoot, relDestPath);
        String fileName = FilenameUtils.getName(path);
        FileUtils.moveFile(new File(path), new File(absDestPath));
        jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName);

        em.getTransaction().begin();
        d = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), em);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
    return d.getId();
}

From source file:com.atlassian.theplugin.idea.config.ProjectConfigurationComponent.java

private void migrateFileFromProjectRootToIdeaDirectory() {
    boolean migrationHappened = false;

    final File cfgFileInProjectRoot = new File(getCfgFilePathInProjectRootDirectory());
    final File newCfgFile = new File(getCfgFilePath());

    // note that this will always be false when using file-based project configuration, as both paths are equal
    if (cfgFileInProjectRoot.exists() && !newCfgFile.exists()) {
        try {/*from w ww. j a  v a 2s .c o m*/
            FileUtils.moveFile(cfgFileInProjectRoot, newCfgFile);
            migrationHappened = true;
        } catch (IOException e) {
            handleServerCfgFactoryException(project, e);
        }
    }

    if (migrationHappened) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            public void run() {
                Messages.showInfoMessage(project,
                        "The Atlassian IDE Connector configuration file has been moved from "
                                + getCfgFilePathInProjectRootDirectory() + " to " + getCfgFilePath()
                                + ". If it was under version control, please make "
                                + "the appropriate changes to reflect this.",
                        PluginUtil.PRODUCT_NAME + " upgrade process");
            }
        });
    }
}

From source file:com.edgenius.wiki.service.impl.ThemeServiceImpl.java

public void installSkin(File skinFile) throws ThemeInvalidException, ThemeInvalidVersionException {

    try {/*ww w  . j  av a  2  s. c  om*/
        String name = explodeSkin(skinFile, true);

        //put install file to resource directory, replace old one if existing.
        File installFile = new File(skinResourcesRoot.getFile(), name + INSTALL_EXT_NAME);
        if (installFile.exists()) {
            installFile.delete();
        }
        FileUtils.moveFile(skinFile, installFile);
    } catch (ThemeInvalidException e) {
        log.error("Unable to install skin.", e);
        throw e;
    } catch (IOException e) {
        log.error("Unable to install skin.", e);
        throw new ThemeInvalidException(e);
    }
}

From source file:edu.ucsb.eucalyptus.storage.fs.FileSystemStorageManager.java

public void renameObjectRollback(String[] backup, String bucket, String oldName, String newName)
        throws IOException {
    if (backup == null || backup[0] == null || bucket == null || oldName == null || newName == null)
        return;/*  w w w.jav a  2s.  c  o  m*/

    File oldObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + oldName);
    File newObjectFile = new File(rootDirectory + FILE_SEPARATOR + bucket + FILE_SEPARATOR + newName);
    File backupFile = new File(backup[0]);

    if (backupFile.exists()) {
        if (oldObjectFile.exists()) {
            FileUtils.forceDelete(backupFile);
        }
        if (newObjectFile.exists()) {
            FileUtils.moveFile(newObjectFile, oldObjectFile);
        }
        FileUtils.moveFile(backupFile, newObjectFile);
    }
}