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:com.thoughtworks.go.plugin.infra.monitor.DefaultPluginJarLocationMonitorTest.java

@Test
void shouldCreatePluginZipIfPluginJarIsUpdated() throws Exception {
    monitor.addPluginJarChangeListener(changeListener);
    monitor.start();/*from  w  w  w  .j ava 2  s  . c om*/

    copyPluginToThePluginDirectory(bundledPluginDir, "descriptor-aware-test-plugin-1.jar");
    waitUntilNextRun(monitor);
    PluginFileDetails orgFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1.jar", true);
    verify(changeListener).pluginJarAdded(orgFile);

    PluginFileDetails newFile = pluginFileDetails(bundledPluginDir, "descriptor-aware-test-plugin-1-new.jar",
            true);
    FileUtils.moveFile(orgFile.file(), newFile.file());
    waitUntilNextRun(monitor);
}

From source file:com.taobao.android.builder.tools.BuildHelper.java

public static void writeFileToApk(File destFile, File file, String path) throws IOException {
    File outPutFile = new File(file.getParent(), "temp.apk");
    ZipUtils.addFileToZipFile(file, outPutFile, destFile, path, true);
    FileUtils.deleteQuietly(file);//from   www. jav  a 2s.  c  o m
    FileUtils.moveFile(outPutFile, file);
    FileUtils.deleteQuietly(destFile);
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

/**
 * manifest???//from   ww w.ja v  a2  s  .  co  m
 *
 * @param mainManifest
 * @param libManifestMap
 * @param baseBunfleInfoFile
 * @param manifestOptions
 */
public static Result postProcessManifests(File mainManifest, Map<String, File> libManifestMap,
        Multimap<String, File> libDependenciesMaps, File baseBunfleInfoFile, ManifestOptions manifestOptions,
        boolean addMultiDex, boolean isInstantRun, Set<String> remoteBundles)
        throws IOException, DocumentException {

    Result result = new Result();

    File inputFile = new File(mainManifest.getParentFile(), "AndroidManifest-backup.xml");
    FileUtils.deleteQuietly(inputFile);
    FileUtils.moveFile(mainManifest, inputFile);

    Document document = XmlHelper.readXml(inputFile);

    if (null != baseBunfleInfoFile && baseBunfleInfoFile.exists()) {
        addApplicationMetaData(document, libManifestMap, baseBunfleInfoFile, manifestOptions, remoteBundles);
    }

    if (null != manifestOptions && manifestOptions.isAddAtlasProxyComponents()) {
        AtlasProxy.addAtlasProxyClazz(document, manifestOptions.getAtlasProxySkipChannels(), result);
    }

    if (null != manifestOptions && manifestOptions.isAddBundleLocation()) {
        addBundleLocationToDestManifest(document, libManifestMap, libDependenciesMaps, manifestOptions);
    }
    if (null != manifestOptions && manifestOptions.isReplaceApplication()) {
        replaceManifestApplicationName(document);
    }

    if ((null != manifestOptions && manifestOptions.isAddMultiDexMetaData()) || addMultiDex) {
        addMultiDexMetaData(document);
    }
    if (null != manifestOptions && manifestOptions.isRemoveProvider()) {
        removeProvider(document);
    }
    if (isInstantRun) {
        removeProcess(document);
    }
    removeCustomLaunches(document, manifestOptions);
    updatePermission(document, manifestOptions);
    removeComments(document);

    XmlHelper.saveDocument(document, mainManifest);

    return result;

}

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

public void deleteObject(String[] backup, String bucket, String object) throws IOException {
    if (backup == null || bucket == null || object == null)
        return;/*from  w w  w . j a  v  a 2 s  .  co  m*/

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

From source file:com.ephesoft.gxt.foldermanager.server.FolderManagerServiceImpl.java

@Override
public List<String> cutFiles(List<String> cutFilesList, String currentFolderPath) throws UIException {
    List<String> resultList = new ArrayList<String>();
    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);
                    }//from  w w w.j  ava  2 s  .c o  m
                } else {
                    resultList.add(fileName);
                    // throw new UIException(FolderManagementMessages.CANNOT_COMPLETE_CUT_PASTE_OPERATION_AS_THE_FILE_FOLDER
                    // + fileName + FolderManagementMessages.ALREADY_EXISTS);
                }
            } catch (IOException e) {
                throw new UIException(
                        FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_CUT_PASTE_OPERATION_COULD_NOT_COMPLETE_OPERATION);
            }
        } else {
            resultList.add(srcFile.getName());
            // throw new UIException(FolderManagementMessages.EXCEPTION_OCCURRED_WHILE_CUT_PASTE_OPERATION_FILE_NOT_FOUND
            // + FolderManagementConstants.QUOTES + srcFile.getName() + FolderManagementConstants.QUOTES);
        }
    }
    return resultList;
}

From source file:com.taobao.android.builder.tasks.awo.AwoFullApkBuildTask.java

@TaskAction
public void doTask() throws IOException, SigningException {

    baseApkFile = getBaseApkFile();//from   w ww . ja  va 2s.c o m
    destPath = getDestPath();
    awoFile = getAwoFile();
    zipAlign = getZipAlign();
    outApkFile = getOutApkFile();

    ZipUtils.addFileToZipFile(baseApkFile, outApkFile, awoFile, destPath, true);

    File signFile = new File(outApkFile.getParent(), outApkFile.getName().replace(".apk", "-signed.apk"));
    AtlasBuildContext.sBuilderAdapter.androidSigner.signFile(outApkFile, signFile, getSigningConfig());
    if (null != zipAlign && zipAlign) {
        File signAndZipAlignedFile = ZipAlignUtils.doZipAlign(androidBuilder, getProject(), signFile);
        FileUtils.deleteQuietly(outApkFile);
        FileUtils.moveFile(signAndZipAlignedFile, outApkFile);
    }

}

From source file:net.pms.configuration.DownloadPlugins.java

private boolean command(String cmd, String args) throws ConfigurationException {
    if (cmd.equalsIgnoreCase("move")) {
        // arg1 is src and arg2 is dst
        String[] tmp = args.split(",");
        try {//ww w. j  a  va 2s .c  om
            FileUtils.moveFile(new File(tmp[1]), new File(tmp[2]));
        } catch (IOException e) {
            // Ignore errors, just log it
            LOGGER.debug("couldn't move file " + tmp[1] + " to " + tmp[2]);
        }
        return true;
    }

    if (cmd.equalsIgnoreCase("touch")) {
        // arg1 is file to touch
        String[] tmp = args.split(",");
        try {
            FileUtils.touch(new File(tmp[1]));
        } catch (IOException e) {
            // Ignore errors, just log it
            LOGGER.debug("couldn't touch file " + tmp[1]);
        }

        return true;
    }

    if (cmd.equalsIgnoreCase("conf")) {
        String[] tmp = args.split(",", 2);
        tmp = tmp[1].split("=");
        configuration.setCustomProperty(tmp[1], tmp[2]);
        configuration.save();
        return true;
    }

    if (cmd.equalsIgnoreCase("exec")) {
        try {
            doExec(args);
        } catch (ConfigurationException | IOException | InterruptedException e) {
        }

        return true;
    }

    return false;
}

From source file:com.taobao.android.builder.tasks.library.publish.UpdatePomTask.java

private void updatePomXml(File xml) throws IOException, DocumentException {

    Map<String, DependencyExtraInfo> extraInfoMap = getExtraMap();

    File backupFile = new File(xml.getParentFile(), "pom-backup.xml");
    FileUtils.deleteQuietly(backupFile);

    FileUtils.moveFile(xml, backupFile);

    XMLWriter writer = null;// XML
    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");// XML??
    FileOutputStream fos = new FileOutputStream(xml);

    try {/*from ww  w . ja  v  a2  s  . c om*/
        Document document = reader.read(backupFile);// ?XML

        Element dependencies = document.getRootElement().element("dependencies");

        if ((null != dependencies) && null != dependencies.elements()) {
            List<Element> list = dependencies.elements();

            for (Element element : list) {

                List<Element> itemList = element.elements();

                String group = "";
                String name = "";
                String type;
                String scope;

                Element scopeEl = null;
                Element typeEl = null;

                for (Element element1 : itemList) {
                    if ("groupId".equals(element1.getQName().getName())) {
                        group = element1.getStringValue();
                    } else if ("artifactId".equals(element1.getQName().getName())) {
                        name = element1.getStringValue();
                    } else if ("scope".equals(element1.getQName().getName())) {
                        scope = element1.getStringValue();
                        scopeEl = element1;
                    } else if ("type".equals(element1.getQName().getName())) {
                        type = element1.getStringValue();
                        typeEl = element1;
                    }
                }

                DependencyExtraInfo dependencyExtraInfo = extraInfoMap.get(group + ":" + name);
                if (null == dependencyExtraInfo) {
                    continue;
                }

                //update scope
                if (StringUtils.isNotEmpty(dependencyExtraInfo.scope)) {
                    if (null != scopeEl) {
                        scopeEl.setText(dependencyExtraInfo.scope);
                    } else {
                        Element newEl = element.addElement("scope");
                        newEl.setText(dependencyExtraInfo.scope);
                    }
                }

                if (StringUtils.isNotEmpty(dependencyExtraInfo.type)) {
                    if (null != typeEl) {
                        typeEl.setText(dependencyExtraInfo.type);
                    } else {
                        Element newEl = element.addElement("type");
                        newEl.setText(dependencyExtraInfo.type);
                    }
                }

            }
        }

        writer = new XMLWriter(fos, format);
        writer.write(document);

    } finally {
        if (null != writer) {
            writer.close();
        }
        IOUtils.closeQuietly(fos);
    }

}

From source file:com.hangum.tadpole.rdb.core.dialog.dbconnect.composite.SQLiteLoginComposite.java

@Override
public boolean makeUserDBDao(boolean isTest) {
    if (!isValidateInput(isTest))
        return false;

    String strDBFile = "", strDBUrl = ""; //$NON-NLS-1$ //$NON-NLS-2$
    if (oldUserDB != null) {
        strDBFile = oldUserDB.getDb();/*from  w w w. j a  va2 s  .  c o  m*/
        strDBUrl = oldUserDB.getUrl();
    } else {
        if (chkBtnFileUpload.getSelection()) {
            File[] arryFiles = receiver.getTargetFiles();
            File userDBFile = arryFiles[arryFiles.length - 1];

            strDBFile = userDBFile.getName();
            if (isTest) {
                strDBUrl = userDBFile.getAbsolutePath();
            } else {
                strDBUrl = ROOT_RESOURCE_DIR + userDBFile.getName() + Utils.getUniqueID();

                try {
                    FileUtils.moveFile(userDBFile, new File(strDBUrl));
                } catch (IOException e) {
                    logger.error("File moveing", e); //$NON-NLS-1$
                    MessageDialog.openError(null, Messages.get().Error, Messages.get().SQLiteLoginComposite_29);

                    return false;
                }
            }
        } else if (chkBtnFileLocationDb.getSelection()) {
            strDBFile = textFileLocationDB.getText();
            strDBUrl = textFileLocationDB.getText();
            //   ?.
        } else {
            strDBFile = textCreationDB.getText();
            strDBUrl = ROOT_RESOURCE_DIR + textCreationDB.getText();
        }

        strDBUrl = String.format(getSelectDB().getDB_URL_INFO(), strDBUrl);
    }

    userDB = new UserDBDAO();
    userDB.setDbms_type(getSelectDB().getDBToString());
    userDB.setUrl(strDBUrl);
    userDB.setDb(strDBFile);
    //      userDB.setGroup_seq(SessionManager.getGroupSeq());
    userDB.setGroup_name(StringUtils.trimToEmpty(preDBInfo.getComboGroup().getText()));
    userDB.setDisplay_name(StringUtils.trimToEmpty(preDBInfo.getTextDisplayName().getText()));

    String dbOpType = PublicTadpoleDefine.DBOperationType
            .getNameToType(preDBInfo.getComboOperationType().getText()).name();
    userDB.setOperation_type(dbOpType);
    if (dbOpType.equals(PublicTadpoleDefine.DBOperationType.PRODUCTION.name())
            || dbOpType.equals(PublicTadpoleDefine.DBOperationType.BACKUP.name())) {
        userDB.setIs_lock(PublicTadpoleDefine.YES_NO.YES.name());
    }

    userDB.setUsers(""); //$NON-NLS-1$
    userDB.setPasswd(""); //$NON-NLS-1$

    // ? ?? ? .
    userDB.setRole_id(PublicTadpoleDefine.USER_ROLE_TYPE.ADMIN.toString());

    // others connection  .
    setOtherConnectionInfo();

    return true;
}

From source file:net.paissad.waqtsalat.utils.UncompressUtils.java

/**
 * Creates a file from an InputStream./*from w  w w  .jav a 2s . c  o  m*/
 * 
 * @param is
 *            InputStream to read from.
 * @param outputFile
 *            File to be created from the InputStream.
 * @param closeStream
 *            Whether or not to close the InputStream after the operation.
 *            If set to true, the InputStream will be closed.
 * @return File that has been created from the InputStream.
 * @throws IOException
 */
private File inputstreamToFile(InputStream is, File outputFile, boolean closeStream) throws IOException {

    if (source.getAbsolutePath().equals(outputFile.getAbsolutePath()))
        throw new IOException(
                outputFile.getAbsolutePath() + " must not have as the same absolute path as the source.");

    try {
        logger.trace("Saving inputstream to file '{}'.", outputFile.getAbsolutePath());
        File tempFile = File.createTempFile(outputFile.getName(), null, outputFile.getParentFile());

        try {
            if (outputFile.exists()) {
                tempFile.delete();
                FileUtils.moveFile(outputFile, tempFile);
            }
            FileUtils.copyInputStreamToFile(is, outputFile);
            return outputFile;
        } catch (IOException ioe) {
            if (tempFile.exists()) {
                if (outputFile.exists())
                    outputFile.delete();
                FileUtils.moveFile(tempFile, outputFile);
            }
            ioe.printStackTrace();
            throw new IOException();
        } finally {
            if (tempFile.exists())
                tempFile.delete();
            if (closeStream)
                if (is != null)
                    is.close();
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new IOException("Saving inputstream failed to file '" + outputFile + "'");
    }
}