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:edu.ucsd.crbs.cws.cluster.SyncWorkspaceFileToFileSystemImpl.java

@Override
public void sync(WorkspaceFile wsf) throws Exception {

    if (wsf == null) {
        throw new IllegalArgumentException("WorkspaceFile cannot be null");
    }/*from w w w.  j a v  a2  s  .c om*/

    if (doesWorkspaceFileExistOnFileSystem(wsf) == true) {
        return;
    }

    File wFile = _fileDownloader.downloadFile(_getURL + "/workspacefile", Constants.WSFID_PARAM,
            wsf.getId().toString(), _userLogin, _token);

    if (wFile == null) {
        throw new Exception("No file obtained from web request to base url: " + _getURL);
    }

    //make the directory for the workflow
    File wfDir = new File(getWorkspaceDirectory(wsf));
    if (wfDir.isDirectory() == false) {
        _log.log(Level.INFO, "Creating directories: {0}", wfDir.getAbsolutePath());
        if (wfDir.mkdirs() == false) {
            throw new Exception("Unable to create directory: " + wfDir.getAbsolutePath());
        }
    }

    FileUtils.moveFile(wFile, getWorkspaceFile(wsf));

    if (doesWorkspaceFileExistOnFileSystem(wsf) == false) {
        throw new Exception("Unable to put workspace file on file system");
    }

    // need to update WorkspaceFile on GAE with path

}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetSiteIdListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setSiteIdUI.getValues();
    Vector<String> samples = this.setSiteIdUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setSiteIdUI.displayMessage("Error: no subject to sample mapping file");
    }/*from www  .jav a  2s . co  m*/
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String site;
                if (samples.contains(sample)) {
                    site = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + site + "\t" + fields[2] + "\t" + sample + "\t" + fields[4] + "\t"
                        + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setSiteIdUI.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setSiteIdUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setSiteIdUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setSiteIdUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetPlatformsListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setPlatformsUI.getValues();
    Vector<String> samples = this.setPlatformsUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setPlatformsUI.displayMessage("Error: no subject to sample mapping file");
    }/*  w ww  .  j  a  va 2s.c o m*/
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String platform;
                if (samples.contains(sample)) {
                    platform = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setPlatformsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setPlatformsUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetAttribute1Listener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setAttribute1UI.getValues();
    Vector<String> samples = this.setAttribute1UI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setAttribute1UI.displayMessage("Error: no subject to sample mapping file");
    }//from   w  ww.ja  v a2  s. com
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String attribute;
                if (samples.contains(sample)) {
                    attribute = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + fields[4]
                        + "\t" + fields[5] + "\t" + attribute + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            setAttribute1UI.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setAttribute1UI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setAttribute1UI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setAttribute1UI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetAttribute2Listener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setAttribute2UI.getValues();
    Vector<String> samples = this.setAttribute2UI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setAttribute2UI.displayMessage("Error: no subject to sample mapping file");
    }//from   w  w  w. j av  a  2  s . c o m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String attribute;
                if (samples.contains(sample)) {
                    attribute = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + fields[4]
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + attribute + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setAttribute2UI.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setAttribute2UI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setAttribute2UI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setAttribute2UI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetTissueTypeListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setTissueTypeUI.getValues();
    Vector<String> samples = this.setTissueTypeUI.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
        this.setTissueTypeUI.displayMessage("Error: no subject to sample mapping file");
    }//w  w w .  jav a2  s  . co  m
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(
                "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

        try {
            BufferedReader br = new BufferedReader(new FileReader(stsmf));
            String line = br.readLine();
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String tissueType;
                if (samples.contains(sample)) {
                    tissueType = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + fields[4]
                        + "\t" + tissueType + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.setTissueTypeUI.displayMessage("File error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (stsmf != null) {
                String fileName = stsmf.getName();
                stsmf.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
        } catch (IOException ioe) {
            this.setTissueTypeUI.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.setTissueTypeUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.setTissueTypeUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:com.github.cbismuth.fdupes.io.PathOrganizer.java

private void onNoTimestampPath(final Path destination, final PathElement pathElement,
        final AtomicInteger counter) {
    final Path path = pathElement.getPath();

    final String baseName = FilenameUtils.getBaseName(path.toString());
    final int count = counter.getAndIncrement();
    final String extension = FilenameUtils.getExtension(path.toString());

    final String newName = String.format("%s-%d.%s", baseName, count, extension);

    final Path sibling = path.resolveSibling(newName);

    try {// w ww.j a v  a 2s . c  o m
        FileUtils.moveFile(path.toFile(), sibling.toFile());

        FileUtils.moveFileToDirectory(sibling.toFile(), Paths.get(destination.toString(), "misc").toFile(),
                true);
    } catch (final IOException e) {
        LOGGER.error(e.getMessage());
    }
}

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

@Override
public void rollback() throws Exception {

    for (Event e : o.getLatestPackage().getEvents()) {
        if (!"CONVERT".equals(e.getType()))
            continue;

        DAFile daFile = e.getTarget_file();
        File file = wa.toFile(daFile);
        String filePath = daFile.getRelative_path();
        if (!map.containsKey(filePath))
            continue;
        String oldFilePath = map.get(filePath);
        File oldFile = new File(file.getAbsolutePath().replaceAll(filePath + "$", oldFilePath));

        daFile.setRelative_path(oldFilePath);
        FileUtils.forceMkdir(oldFile.getParentFile());
        FileUtils.moveFile(file, oldFile);

    }/*w w  w.j  a va 2 s. c  o  m*/

    logger.info("@Admin: You can safely roll back this job to status " + this.getStartStatus() + " now.");
}

From source file:com.springer.omelet.driver.DriverUtility.java

/***
 * Take Screen Shot/*w  w  w  .  ja v a2 s  .  c  om*/
 * 
 * @param driver
 * @param path
 *            :File path to store screen Shot
 * @author kapilA
 */
public static File takeScreenShot(WebDriver driver, String path) {
    File saved = new File(path);
    File scrFile;
    try {
        if (driver != null) {
            if (Driver.getBrowserConf().isRemoteFlag()) {
                Augmenter augumenter = new Augmenter();
                scrFile = ((TakesScreenshot) augumenter.augment(driver)).getScreenshotAs(OutputType.FILE);
            } else {
                scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
            }
            FileUtils.moveFile(scrFile, saved);
        } else {
            LOGGER.info("As the driver is null no point in taking screen shot");
        }
    } catch (Exception e) {
        LOGGER.info("Not able to take Screen Shot", e);
    }
    return saved;
}

From source file:com.xebialabs.overcast.OvercastPropertiesTest.java

@Test
public void testPropertyHasPrecedenceOverClasspath() throws IOException {

    System.setProperty("user.home", new File("src/test/resources/dir-without-conf").getAbsolutePath());
    System.clearProperty("precedenceTestValue");
    System.setProperty("overcast.conf.file", "src/test/resources/property-path/overcast.conf");

    File cfg = new File("overcast.conf");
    File bkp = new File("backup.conf");

    try {/*from  w ww.  jav a 2 s .  c  o m*/
        FileUtils.moveFile(cfg, bkp);
        OvercastProperties.reloadOvercastProperties();
        assertThat(OvercastProperties.getOvercastProperty("precedenceTestValue"), is("valueFromProperty"));
    } finally {
        FileUtils.moveFile(bkp, cfg);
    }
}