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.blogspot.skam94.main.datatypes.FileItem.java

/**
 * newPath must contain the last /// ww  w .  ja va2 s . c  om
 * @param newPath
 * @return
 */
public boolean move(String newPath) {
    if (newPath.equals(filePath)) {
        return true;
    }
    File newFile = new File(newPath.concat(fileName).concat(getExtWithDot()));
    try {
        FileUtils.moveFile(getFile(), newFile);
        filePath = newPath;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:ie.programmer.catcher.browser.AsyncTasks.AsyncMoveTask.java

@Override
protected Boolean doInBackground(String... params) {
    if (mMoveInterface != null)
        mMoveInterface.preMoveStartAsync();
    if (mSourceFile == null || mDestDirFile == null) {
        if (mMoveInterface != null)
            mMoveInterface.onMoveCompleteAsync(false);
        return false;
    }//w  w w. jav  a  2s.  c om
    if (mSourceFile.isDirectory()) {
        try {
            FileUtils.moveDirectory(mSourceFile, mDestDirFile);
        } catch (Exception e) {
            if (mMoveInterface != null)
                mMoveInterface.onMoveCompleteAsync(false);
            return false;
        }
    } else {
        try {
            FileUtils.moveFile(mSourceFile, mDestDirFile);
        } catch (Exception e) {
            if (mMoveInterface != null)
                mMoveInterface.onMoveCompleteAsync(false);
            return false;
        }
    }
    if (mMoveInterface != null)
        mMoveInterface.onMoveCompleteAsync(true);
    return true;
}

From source file:de.uzk.hki.da.service.CSVQueryHandler.java

@SuppressWarnings("serial")
public void generateReportBasedOnFile(File csvFile, File outCsvFile) {
    logger.info("generating Report file on " + csvFile + " to " + outCsvFile);
    try {// www . j  av a 2 s  .  c  o m
        csvFileHandler.parseFile(csvFile);
        evalStates();
        csvFileHandler.persistStates(csvFile);
        FolderUtils.deleteQuietlySafe(outCsvFile);
        FileUtils.moveFile(csvFile, outCsvFile);
    } catch (IOException e) {
        logger.error("catched " + e.toString() + " while working with " + csvFile.getAbsolutePath());
        throw new RuntimeException("CSV File operations not possible " + csvFile.getAbsolutePath(), e) {
        };
    }
}

From source file:com.mobileman.projecth.business.impl.ImageServiceImpl.java

/** 
 * {@inheritDoc}// w ww  . j  a v a2 s  .c o  m
 * @see com.mobileman.projecth.business.ImageService#copyImage(java.lang.String, java.lang.String)
 */
@Override
public String copyImage(String sourceFileFullPath, String relativePath) {
    if (sourceFileFullPath == null) {
        throw new IllegalArgumentException("sourceFileFullPath must not be null");
    }

    if (sourceFileFullPath.trim().length() == 0) {
        throw new IllegalArgumentException("sourceFileFullPath must not be empty");
    }

    if (relativePath == null) {
        throw new IllegalArgumentException("relativePath must not be null");
    }

    if (sourceFileFullPath.trim().length() == 0) {
        throw new IllegalArgumentException("relativePath must not be empty");
    }

    DateFormat dirNameDateFormat = new SimpleDateFormat("yyyy_MM");
    DateFormat fileNameDateFormat = new SimpleDateFormat("hh_mm_ss");

    String result = "";
    try {
        File sourceFile = new File(sourceFileFullPath);
        String[] fileNameComponents = sourceFile.getName().split("[.]");
        String postfix = fileNameComponents[fileNameComponents.length - 1];

        String targetFileDir = configurationService.getImagesRootDirectoryPath() + File.separator + relativePath
                + File.separator + dirNameDateFormat.format(new Date());
        File dir = new File(targetFileDir);
        dir.mkdirs();
        if (!dir.exists()) {
            throw new RuntimeException("could not create directories: " + dir.getAbsolutePath());
        }

        File newFile = new File(
                targetFileDir + File.separator + fileNameDateFormat.format(new Date()) + "." + postfix);
        try {
            FileUtils.moveFile(sourceFile, newFile);
            result = relativePath + File.separator + dirNameDateFormat.format(new Date()) + File.separator
                    + newFile.getName();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    } finally {

    }

    return result;
}

From source file:com.psaravan.filebrowserview.lib.AsyncTasks.AsyncMoveTask.java

@Override
protected Boolean doInBackground(String... params) {

    if (mMoveInterface != null)
        mMoveInterface.preMoveStartAsync();

    if (mSourceFile == null || mDestDirFile == null) {
        if (mMoveInterface != null)
            mMoveInterface.onMoveCompleteAsync(false);

        return false;
    }//from w w w  .ja  va2s .com

    if (mSourceFile.isDirectory()) {
        try {
            FileUtils.moveDirectory(mSourceFile, mDestDirFile);
        } catch (Exception e) {
            if (mMoveInterface != null)
                mMoveInterface.onMoveCompleteAsync(false);

            return false;
        }

    } else {
        try {
            FileUtils.moveFile(mSourceFile, mDestDirFile);
        } catch (Exception e) {
            if (mMoveInterface != null)
                mMoveInterface.onMoveCompleteAsync(false);

            return false;
        }

    }

    if (mMoveInterface != null)
        mMoveInterface.onMoveCompleteAsync(true);

    return true;
}

From source file:com.diffplug.gradle.CmdLine.java

/** Removes the given file or directory. */
public void mv(File src, File dst) {
    run(() -> {/*from www . j a  v  a 2s  .  c o  m*/
        if (!src.exists()) {
            throw new IllegalArgumentException("mv failed: " + src.getAbsolutePath() + " does not exist.");
        }

        if (src.isDirectory()) {
            FileUtils.moveDirectory(src, dst);
        } else {
            FileUtils.moveFile(src, dst);
        }
    });
}

From source file:com.gs.obevo.util.FileUtilsCobra.java

public static void moveFile(File srcFile, File destFile) {
    try {//  w w  w.  jav a  2s.com
        FileUtils.moveFile(srcFile, destFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.alibaba.jstorm.yarn.utils.PathUtils.java

public static void mv(String src, String dest) {
    try {//from  www.  ja va2 s.co m
        FileUtils.moveFile(new File(src), new File(dest));
    } catch (IOException ignored) {
    }
}

From source file:com.flowpowered.cerealization.config.migration.ConfigurationMigrator.java

/**
 * Perform migration of the configuration this object was constructed with If migration was not necessary ({@link #shouldMigrate()} returned false), the method invocation will be considered
 * successful. If {@link #configuration} is a {@link com.flowpowered.cerealization.config.FileConfiguration}, the file the configuration vas previously stored in will be moved to (file name).old as a backup of
 * the data before migration/* w w  w .ja v  a 2 s. c o m*/
 *
 * @throws MigrationException if the configuration could not be successfully migrated
 */
public void migrate() throws MigrationException {
    if (!shouldMigrate()) {
        return;
    }

    if (configuration instanceof FileConfiguration) {
        File oldFile = ((FileConfiguration) configuration).getFile();
        try {
            FileUtils.moveFile(oldFile, new File(oldFile.getAbsolutePath() + ".old"));
        } catch (IOException e) {
            throw new MigrationException(e);
        }
    }

    for (Map.Entry<String[], MigrationAction> entry : getMigrationActions().entrySet()) {
        final ConfigurationNode existingNode = configuration.getNode(entry.getKey());
        final Object existing = existingNode.getValue();
        existingNode.remove();
        if (existing == null || entry.getValue() == null) {
            continue;
        }
        final String[] newKey = entry.getValue().convertKey(entry.getKey());
        final Object newValue = entry.getValue().convertValue(existing);
        configuration.getNode(newKey).setValue(newValue);
    }
    try {
        configuration.save();
    } catch (ConfigurationException e) {
        throw new MigrationException(e);
    }
}

From source file:edu.unc.lib.dl.cdr.sword.server.deposit.AtomPubEntryDepositHandler.java

@Override
public DepositReceipt doDeposit(PID destination, Deposit deposit, PackagingType type, SwordConfiguration config,
        String depositor, String owner) throws SwordError {
    log.debug("Preparing to perform an Atom Pub entry metadata only deposit to " + destination.getPid());

    if (deposit.getSwordEntry() == null || deposit.getSwordEntry().getEntry() == null)
        throw new SwordError(UriRegistry.ERROR_CONTENT, 415, "No AtomPub entry was included in the submission");

    if (log.isDebugEnabled()) {
        Abdera abdera = new Abdera();
        Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
        try {// w  w  w  .  j  av a2 s. co m
            writer.writeTo(deposit.getSwordEntry().getEntry(), System.out);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    PID depositPID = null;
    UUID depositUUID = UUID.randomUUID();
    depositPID = new PID("uuid:" + depositUUID.toString());
    File dir = makeNewDepositDirectory(depositPID.getUUID());
    dir.mkdir();

    // write SWORD Atom entry to file
    File atomFile = new File(dir, "atom.xml");
    Abdera abdera = new Abdera();

    try (FileOutputStream fos = new FileOutputStream(atomFile)) {
        Writer writer = abdera.getWriterFactory().getWriter("prettyxml");
        writer.writeTo(deposit.getSwordEntry().getEntry(), fos);
    } catch (IOException e) {
        throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 400,
                "Unable to unpack your deposit: " + deposit.getFilename(), e);
    }

    // write deposit file to data directory
    if (deposit.getFile() != null) {
        File dataDir = new File(dir, "data");
        dataDir.mkdirs();
        File depositFile = new File(dataDir, deposit.getFilename());
        try {
            FileUtils.moveFile(deposit.getFile(), depositFile);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    registerDeposit(depositPID, destination, deposit, type, depositor, owner,
            Collections.<String, String>emptyMap());
    return buildReceipt(depositPID, config);
}