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.linkedin.pinot.filesystem.LocalPinotFS.java

@Override
public boolean move(URI srcUri, URI dstUri) throws IOException {
    File srcFile = new File(srcUri);
    File dstFile = new File(dstUri);
    if (dstFile.exists()) {
        FileUtils.deleteQuietly(dstFile);
    }/* w w w.j ava 2s.c  o m*/
    if (!srcFile.isDirectory()) {
        dstFile.getParentFile().mkdirs();
        FileUtils.moveFile(srcFile, dstFile);
    }
    if (srcFile.isDirectory()) {
        Files.move(srcFile.toPath(), dstFile.toPath());
    }
    return true;
}

From source file:com.carolinarollergirls.scoreboard.xml.AutoSaveScoreBoard.java

public void run() {
    FileOutputStream fos = null;/*  w  w w.j  a  v a 2 s.c o  m*/
    try {
        int n = AUTOSAVE_FILES;
        getFile(n).delete();
        while (n > 0) {
            File to = getFile(n);
            File from = getFile(--n);
            if (from.exists())
                FileUtils.moveFile(from, to);
        }
        fos = FileUtils.openOutputStream(getFile(0));
        xmlOutputter.output(editor.filterNoSavePI(xmlScoreBoard.getDocument()), fos);
    } catch (Exception e) {
        ScoreBoardManager.printMessage("WARNING: Unable to auto-save scoreboard : " + e.getMessage());
    } finally {
        if (null != fos)
            try {
                fos.close();
            } catch (IOException ioE) {
            }
    }
}

From source file:es.uvigo.ei.sing.adops.operations.running.mrbayes.MrBayes3_2ProcessManager.java

@Override
public void buildSummary(MrBayesOutput output) throws OperationException {
    try {//from  w  ww .j a  v  a 2 s.com
        FileUtils.moveFile(new File(output.getConFile().getAbsolutePath() + ".tre"), output.getConFile());

        final List<String> lines = FileUtils.readLines(output.getConFile());
        final ListIterator<String> itLines = lines.listIterator();
        while (itLines.hasNext()) {
            final String line = itLines.next();

            if (line.contains("tree con_50_majrule")) {
                final String[] lineSplit = line.split("=");
                final String tree = lineSplit[1].trim();

                itLines.set(lineSplit[0] + "= " + Newick.parse(tree.trim()));
            }
        }

        FileUtils.writeLines(output.getConFile(), lines);

        super.buildSummary(output);
    } catch (Exception e) {
        throw new OperationException("Error while working with consensus tree", e);
    }
}

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

@Override
public DepositReceipt doDeposit(PID destination, Deposit deposit, PackagingType type, SwordConfiguration config,
        String depositor, String owner) throws Exception {
    log.debug("Preparing to perform a Simple Object deposit to " + destination.getPid());

    PID depositPID = null;/*  w ww .ja v  a  2s . c  o  m*/
    UUID depositUUID = UUID.randomUUID();
    depositPID = new PID("uuid:" + depositUUID.toString());
    File dir = makeNewDepositDirectory(depositPID.getUUID());
    dir.mkdir();

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

    // Skip deposit record for this tiny ingest
    Map<String, String> options = new HashMap<String, String>();
    options.put(DepositField.excludeDepositRecord.name(), "true");

    registerDeposit(depositPID, destination, deposit, type, depositor, owner, options);
    return buildReceipt(depositPID, config);
}

From source file:com.hs.mail.imap.message.MailMessage.java

public void save(boolean deleteSrc) throws IOException {
    File dest = Config.getDataFile(getInternalDate(), getPhysMessageID());
    if (deleteSrc) {
        FileUtils.moveFile(file, dest);
    } else {/*w  ww  .  ja va 2  s.co m*/
        FileUtils.copyFile(file, dest);
    }
}

From source file:de.qucosa.webapi.v1.FileHandlingService.java

public URI renameFileInTargetFileSpace(String filename, String newname, String qid) throws IOException {
    File sourceFile = new File(new File(documentsPath, qid), filename);
    File targetFile = new File(new File(documentsPath, qid), newname);
    if (!sourceFile.equals(targetFile)) {
        FileUtils.moveFile(sourceFile, targetFile);
    }//  w ww  .  j  av  a 2 s .c  om
    return targetFile.toURI().normalize();
}

From source file:com.jaeksoft.searchlib.replication.ReplicationMerge.java

@Override
public void file(File file) throws SearchLibException {
    File dest = new File(destRoot, file.getAbsolutePath().substring(prefixSize));
    if (dest.exists()) {
        if (!dest.delete())
            throw new SearchLibException("Unable to delete the file: " + dest.getAbsolutePath());
    } else {//from www .ja v  a2  s  . co  m
        File parent = dest.getParentFile();
        if (!parent.exists())
            if (!parent.mkdirs())
                throw new SearchLibException("Unable to create the directory: " + parent.getAbsolutePath());
    }
    if (!file.isFile())
        throw new SearchLibException("Unsupported file type: " + file.getAbsolutePath());
    try {
        FileUtils.moveFile(file, dest);
    } catch (IOException e) {
        throw new SearchLibException("File move failed on " + file.getAbsolutePath());
    }
}

From source file:kaljurand_at_gmail_dot_com.diktofon.MyFileUtils.java

public static File moveFileToRecordingsDir(File file) throws IOException {
    String ext = getExtension(file.getName());
    String newFileName = String.valueOf(System.currentTimeMillis()) + ext;
    String newPath = Dirs.getRecordingsDir().getAbsolutePath() + "/" + newFileName;
    File newFile = new File(newPath);
    if (newFile.exists()) {
        throw new IOException("Not overwriting existing file: " + newFileName);
    }//from  w  w  w.  ja v a  2  s . c  o m
    FileUtils.moveFile(file, newFile);
    return newFile;
}

From source file:net.landora.video.info.file.FileManager.java

public boolean moveFile(File srcFile, File destFile, boolean deleteSourceIfEmpty) {
    FileInfo info = infoManager.getFileInfo(srcFile);
    info = info.clone();//  w w w . ja  v a 2 s  . c  o  m

    try {
        FileUtils.moveFile(srcFile, destFile);
    } catch (Exception e) {
        log.warn(String.format("Error moving file \"%s\" to \"%s\".", srcFile.getPath(), destFile.getPath()),
                e);
        return false;
    }
    infoManager.removeFileInfo(srcFile);
    info.setFilename(destFile.getName());
    infoManager.setFileInfo(destFile, info);

    if (deleteSourceIfEmpty) {
        File srcDir = srcFile.getParentFile();
        File[] children = srcDir.listFiles();
        boolean empty = true;
        if (children == null) {
            for (File file : children) {
                if (!file.getName().equals(".") && !file.getName().equals("..")) {
                    empty = false;
                    break;
                }
            }
        }
        if (empty) {
            srcDir.delete();
        }
    }

    VideoManagerApp.getInstance().getEventBus().fireEvent(new FileMovedEvent(this, srcFile, destFile));

    return true;
}

From source file:net.landora.video.info.file.FileHasher.java

public static void checkDirectory(File dir) throws IOException {
    for (File file : dir.listFiles()) {
        if (file.isHidden()) {
            continue;
        }/*from ww w.ja v  a2  s .  c o  m*/

        if (file.isDirectory()) {
            checkDirectory(file);
        } else {

            String extension = ExtensionUtils.getExtension(file);
            if (!ExtensionUtils.isVideoExtension(extension)) {
                continue;
            }

            FileInfo info = FileInfoManager.getInstance().getFileInfo(file);
            VideoMetadata md = MetadataProvidersManager.getInstance().getMetadata(info);

            if (md == null) {
                continue;
            }

            file = file.getCanonicalFile();

            String filename = getOutputFilename(md) + "." + extension;

            File outputFile = new File(getOutputFolder(md), filename);
            outputFile.getParentFile().mkdirs();
            outputFile = outputFile.getCanonicalFile();

            if (!outputFile.equals(file)) {
                if (outputFile.exists()) {
                } else {
                    FileUtils.moveFile(file, outputFile);
                }

            }

        }
    }
}