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

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

Introduction

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

Prototype

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

Source Link

Document

Copies a file to a new location preserving the file date.

Usage

From source file:com.linkedin.pinot.common.segment.fetcher.LocalFileSegmentFetcher.java

@Override
public void fetchSegmentToLocal(String uri, File tempFile) throws Exception {
    FileUtils.copyFile(new File(uri), tempFile);
    LOGGER.info("Copy file from {} to {}; Length of file: {}", uri, tempFile, tempFile.length());
}

From source file:com.googlesites.CaptureFailure.java

@Override
public void onTestFailure(ITestResult result) {

    File scrFile = ((TakesScreenshot) WebDriverInstance.getCurrentDriverInstance())
            .getScreenshotAs(OutputType.FILE);
    DateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy__hh_mm_ssaa");
    String destDir = Config.getPropertyValue("failedTestsScreenshotsLocation");
    new File(destDir).mkdirs();
    String destFile = result.getMethod().getMethodName() + dateFormat.format(new Date()) + ".png";

    try {//from www .j a  v a  2s .  c o m
        FileUtils.copyFile(scrFile, new File(destDir + destFile));
    } catch (IOException e) {
        System.out.println("Something wrong happend at the creation of the screenshot: " + e);
    }
    WebDriverInstance.getCurrentDriverInstance().close();
}

From source file:mesclasses.util.EleveFileUtil.java

public static String copyFileForEleve(Eleve eleve, File file, String type) throws IOException {
    File eleveDir = getEleveDirWithType(eleve, type);
    eleveDir.mkdirs();//from   w ww.jav  a  2s . co m
    String fileName = FilenameUtils.getName(file.getPath());
    File newFile = new File(eleveDir.getPath() + File.separator + fileName);
    if (newFile.exists()) {
        throw new IOException(
                "Le fichier " + fileName + " de type " + type + " existe dj pour " + eleve.getFirstName());
    }
    FileUtils.copyFile(file, newFile);
    return newFile.getPath();
}

From source file:db.pj.action.admin.ImportAction.java

public String execute() throws IOException {
    String realpath = ServletActionContext.getServletContext().getRealPath("/temp");
    if (excel == null)
        return SUCCESS;

    // upload file
    String saveName = IDGenerator.generateUUID() + excelFileName.substring(excelFileName.indexOf("."));
    File saveFile = new File(new File(realpath), saveName);
    if (!saveFile.getParentFile().exists())
        saveFile.getParentFile().mkdirs();
    FileUtils.copyFile(excel, saveFile);

    // import data
    List<String> result = new ArrayList<String>();
    if (type.equals("trad"))
        result = ExcelUtil.importAdministration(saveFile);
    else if (type.equals("staff"))
        result = ExcelUtil.importStaff(saveFile);
    else if (type.equals("licn"))
        result = ExcelUtil.importLicense(saveFile);
    else if (type.equals("pnlt"))
        result = ExcelUtil.importPenalty(saveFile);
    else//from w  w w .j a  v  a 2s .c  o  m
        result.add("");

    // delete temp file and add log
    saveFile.delete();
    DaoFactory.getLoggingDao().addLogging(SessionConstants.ADMIN_NAME, result.get(0));

    // return
    ActionContext actionContext = ActionContext.getContext();
    actionContext.put("exeTip", result);
    return SUCCESS;
}

From source file:glass.Plugins.ServerLogPlugin.java

/**
 * @param args the command line arguments
 *///  w  w  w  .j  a v a 2 s . c  o m
@Override
public String processFile(String path) {

    //code to create/cleanup work directory 
    String output_folder = "work/ServerLogPlugin/";
    cleanWorkDir(output_folder);

    try {
        FileUtils.copyFile(new File(GUI.toolPath + "configFiles\\ServerLogConfigFiles\\temperature_config.txt"),
                new File(output_folder + "temperature_config.txt"));//copy config files to dest
        FileUtils.copyFile(new File(GUI.toolPath + "configFiles\\ServerLogConfigFiles\\cpu_config.txt"),
                new File(output_folder + "cpu_config.txt"));//copy config files to dest
        FileUtils.copyFile(new File(GUI.toolPath + "configFiles\\ServerLogConfigFiles\\power_config.txt"),
                new File(output_folder + "power_config.txt"));//copy config files to dest
        FileUtils.copyFile(new File(GUI.toolPath + "configFiles\\ServerLogConfigFiles\\dma_config.txt"),
                new File(output_folder + "dma_config.txt"));//copy config files to dest

        //FileUtils.
        List<String> lines = Files.readAllLines(Paths.get(path), Charset.defaultCharset());
        double xValues[] = new double[lines.size()];

        double yValues1[] = new double[lines.size()];
        double yValues2[] = new double[lines.size()];
        double yValues3[] = new double[lines.size()];
        double yValues4[] = new double[lines.size()];

        ArrayList<String> lines_out1 = new ArrayList<>();
        ArrayList<String> lines_out2 = new ArrayList<>();
        ArrayList<String> lines_out3 = new ArrayList<>();
        ArrayList<String> lines_out4 = new ArrayList<>();

        for (int i = 1; i < lines.size(); i++) {
            String[] line_cloumn = lines.get(i).split(",");
            xValues[i] = i;

            yValues1[i] = Double.parseDouble(line_cloumn[49]);
            yValues2[i] = Double.parseDouble(line_cloumn[1]);
            yValues3[i] = Double.parseDouble(line_cloumn[48]);
            yValues4[i] = Double.parseDouble(line_cloumn[11]);

            lines_out1.add("" + xValues[i] + "," + yValues1[i]);
            lines_out2.add("" + xValues[i] + "," + yValues2[i]);
            lines_out3.add("" + xValues[i] + "," + yValues3[i]);
            lines_out4.add("" + xValues[i] + "," + yValues4[i]);
        }

        Files.write(Paths.get(output_folder + "temperature" + ".txt"), lines_out1, Charset.defaultCharset());
        Files.write(Paths.get(output_folder + "cpu" + ".txt"), lines_out2, Charset.defaultCharset());
        Files.write(Paths.get(output_folder + "power" + ".txt"), lines_out3, Charset.defaultCharset());
        Files.write(Paths.get(output_folder + "dma" + ".txt"), lines_out4, Charset.defaultCharset());

        return output_folder;
    } catch (Exception ex) {
        Logger.getLogger(ServerLogPlugin.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
        return "";
    }
}

From source file:mx.itesm.imb.ImbBusController.java

@SuppressWarnings("unchecked")
public static void generateImbBusController(final File rooProject, final File busProject) {
    Writer writer;//w  ww  . ja  va2 s. c  om
    File typeReference;
    File controllerFile;
    int basePackageIndex;
    String imbTypePackage;
    String webConfiguration;
    VelocityContext context;
    Collection<String> types;
    String controllerPackage;
    Iterator<File> typesIterator;

    try {
        // Copy imb types
        FileUtils.copyDirectory(new File(rooProject, "/src/main/java/imb"),
                new File(busProject, "/src/main/java/imb"));
        FileUtils.copyFile(new File(rooProject, "/src/main/resources/schema.xsd"),
                new File(busProject, "/src/main/resources/schema.xsd"));

        imbTypePackage = null;
        types = new ArrayList<String>();
        typesIterator = FileUtils.iterateFiles(new File(busProject, "/src/main/java/imb"),
                new String[] { "java" }, true);
        while (typesIterator.hasNext()) {
            typeReference = typesIterator.next();
            if ((!typeReference.getName().equals("ObjectFactory.java"))
                    && (!typeReference.getName().equals("package-info.java"))) {
                if (FileUtils.readFileToString(typeReference).contains("public class")) {
                    types.add(typeReference.getName().replace(".java", ""));
                    if (imbTypePackage == null) {
                        imbTypePackage = typeReference.getPath()
                                .substring(
                                        typeReference.getPath().indexOf("src/main/java")
                                                + "src/main/java".length() + 1,
                                        typeReference.getPath().indexOf(typeReference.getName()) - 1)
                                .replace(File.separatorChar, '.');
                    }
                }
            }
        }

        // Add rest configuration
        FileUtils.copyFile(
                new File(rooProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"),
                new File(busProject,
                        "/src/main/resources/META-INF/spring/applicationContext-contentresolver.xml"));

        context = new VelocityContext();
        context.put("types", types);
        context.put("imbTypePackage", imbTypePackage);

        webConfiguration = FileUtils
                .readFileToString(new File(busProject, "src/main/webapp/WEB-INF/spring/webmvc-config.xml"));
        basePackageIndex = webConfiguration.indexOf("base-package=\"") + "base-package=\"".length();
        controllerPackage = webConfiguration.substring(basePackageIndex,
                webConfiguration.indexOf('"', basePackageIndex)) + ".web";
        context.put("controllerPackage", controllerPackage);
        context.put("typePackage", controllerPackage.replace(".web", ".domain"));
        controllerFile = new File(busProject,
                "/src/main/java/" + controllerPackage.replace('.', '/') + "/ImbBusController.java");
        writer = new FileWriter(controllerFile);
        ImbBusController.controllerTemplate.merge(context, writer);
        writer.close();
    } catch (Exception e) {
        System.out.println("Error while configuring IMB Bus: " + e.getMessage());
    }
}

From source file:de.jcup.egradle.sdk.builder.action.mapping.CopyApiMappingsAction.java

@Override
public void execute(SDKBuilderContext context) throws IOException {
    /* copy origin mapping file to target directory */
    File targetPathDirectory = context.targetPathDirectory;
    FileUtils.copyFile(context.gradleOriginMappingFile,
            new File(targetPathDirectory, context.gradleOriginMappingFile.getName()));
}

From source file:controllers.QuestionEdit.java

/**
 * Tlcharge les images dans les rponses//from  w  w w.j a v a2 s.c o  m
 * @return
 */
public static Result uploadForReponses() {
    MultipartFormData body = request().body().asMultipartFormData();
    DynamicForm info = Form.form().bindFromRequest();
    FilePart fp = body.getFile("reponseImages");
    int reponsePosition = Integer.parseInt(info.get("position"));
    Long questionId = Long.parseLong(info.get("question"));
    if (UploadImages.isImage(fp)) {
        Image i = new Image(fp.getFilename());
        File image = fp.getFile();
        File destinationFile = new File(
                play.Play.application().path().getAbsolutePath() + "/img/" + i.fileName);
        try {
            FileUtils.copyFile(image, destinationFile);
            i.save();
            Question question = Question.find.byId(questionId);
            question.reponses.get(reponsePosition).image = i;
            question.save();
            return ok("<img class=\"image\" src=\"/images/" + i.fileName + "\">");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("Impossible de copier l'image sur le serveur...");
            return internalServerError("Impossible de copier l'image sur le serveur...");
        }
    } else
        return badRequest("Le fichier que vous avez slectionn n'est pas reconnu comme une image.");
}

From source file:com.molo.dagger.LogTools.java

public static String screenShot(BrowserEmulator be) {
    String dir = "screenshot"; // TODO
    String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
    String screenShotPath = dir + File.separator + time + ".png";

    WebDriver augmentedDriver = null;//from w ww . j a  v a  2s.  c om
    if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) {
        augmentedDriver = be.getBrowserCore();
        augmentedDriver.manage().window().setPosition(new Point(0, 0));
        augmentedDriver.manage().window().setSize(new Dimension(9999, 9999));
    } else if (GlobalSettings.browserCoreType == 2) {
        augmentedDriver = new Augmenter().augment(be.getBrowserCore());
    } else {
        return "Incorrect browser type";
    }

    try {
        File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(sourceFile, new File(screenShotPath));
    } catch (Exception e) {
        e.printStackTrace();
        return "Failed to screenshot";
    }

    // Convert '\' into '/' for web image browsing.
    return screenShotPath.replace("\\", "/");
}

From source file:com.bitplan.vzjava.AppMode.java

/**
 * set the given mode of operation//from w  w  w.ja  v  a2  s.  co m
 * 
 * @param mode
 *          - the mode to set
 */
public static void setMode(Mode mode) {
    try {
        switch (mode) {
        case Welcome:
            demoDb.delete();
            break;
        case Demo:
            testDb.delete();
            FileUtils.copyFile(demoDbRelease, demoDb);
            break;
        case Test:
            demoDb.delete();
            FileUtils.copyFile(demoDbRelease, testDb);
        case Operation:
            break;
        default:
            break;
        }
    } catch (IOException e) {
        ErrorHandler.handle(e);
    }
}