Example usage for java.io File renameTo

List of usage examples for java.io File renameTo

Introduction

In this page you can find the example usage for java.io File renameTo.

Prototype

public boolean renameTo(File dest) 

Source Link

Document

Renames the file denoted by this abstract pathname.

Usage

From source file:io.rhiot.component.kura.deploymanager.InstallProcessor.java

@Override
public void process(Exchange exchange) throws Exception {
    byte[] bundleData = exchange.getIn().getBody(byte[].class);
    String topic = exchange.getIn().getHeader("DeployManager.topic", String.class);
    String bundleName = topic.substring(topic.lastIndexOf('/') + 1) + ".jar";

    File temporaryBundle = File.createTempFile("kura", "deploy");
    write(bundleData, new FileOutputStream(temporaryBundle));
    temporaryBundle.renameTo(new File(deployDirectory, bundleName));
}

From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void renameXsdFile(String projectsDir, String sourceProjectName, String targetProjectName)
        throws Exception {
    String oldPath = projectsDir + "/" + targetProjectName + "/" + sourceProjectName + ".xsd";
    File oldFile = new File(oldPath);
    if (oldFile.exists()) {
        String newPath = projectsDir + "/" + targetProjectName + "/" + targetProjectName + ".xsd";
        File newFile = new File(newPath);
        if (!newFile.exists()) {
            if (oldFile.renameTo(newFile)) {
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement("/" + sourceProjectName, "/" + targetProjectName));
                replacements.add(new Replacement(sourceProjectName + "_ns", targetProjectName + "_ns"));
                makeReplacementsInFile(replacements, newPath);
            } else {
                throw new Exception("Unable to rename \"" + oldPath + "\" to \"" + newPath + "\"");
            }//from w  ww.  j a  v a  2s . c om
        } else {
            throw new Exception("File \"" + newPath + "\" already exists");
        }
    }
}

From source file:mx.com.quadrum.service.impl.TipoContratoServiceImpl.java

@Override
public String agregar(TipoContrato tipoContrato, MultipartFile formato) {

    if (!formato.isEmpty()) {
        String path = FORMATOS + tipoContrato.getNombre() + ".jasper";
        try {//from  ww w .  j  a  va2s.  c o m
            if (crearArchivoContenido(path, formato.getBytes())) {
                if (tipoContratoRepository.agregar(tipoContrato)) {
                    File file = new File(path);
                    file.renameTo(new File(FORMATOS + tipoContrato.getId() + ".jasper"));
                    return ADD_CORRECT + TIPO_CONTRATO;
                }
                return ERROR_HIBERNATE;
            } else {
                return "Ups!...#No fue posible guardar el formato, intente mas tarde.";
            }
        } catch (IOException ex) {
            Logger.getLogger(TipoContratoServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return "Ups!...#Encontramos que el archivo que subio esta vacio.";

}

From source file:com.necl.service.HandlerFileUpload.java

public void handleFileToMove(String source, String target) throws Exception {

    source = "D:/file/New.xlsx";
    target = "D:/file/report/";

    File afile = new File("D:\\file\\test.xlsx");

    if (afile.renameTo(new File("D:\\file\\test\\" + afile.getName()))) {
        System.out.println("File is moved successful!");
    } else {// w ww . ja  v a  2 s .c  o  m
        System.out.println("File is failed to move!");
    }
}

From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void renameWsdlFile(String projectsDir, String sourceProjectName, String targetProjectName)
        throws Exception {
    String oldPath = projectsDir + "/" + targetProjectName + "/" + sourceProjectName + ".wsdl";
    File oldFile = new File(oldPath);
    if (oldFile.exists()) {
        String newPath = projectsDir + "/" + targetProjectName + "/" + targetProjectName + ".wsdl";
        File newFile = new File(newPath);
        if (!newFile.exists()) {
            if (oldFile.renameTo(newFile)) {
                List<Replacement> replacements = new ArrayList<Replacement>();
                replacements.add(new Replacement("/" + sourceProjectName, "/" + targetProjectName));
                replacements.add(new Replacement(sourceProjectName + "_ns", targetProjectName + "_ns"));
                replacements.add(new Replacement(sourceProjectName + ".xsd", targetProjectName + ".xsd"));
                replacements.add(new Replacement(sourceProjectName + "Port", targetProjectName + "Port"));
                replacements.add(new Replacement(sourceProjectName + "SOAP", targetProjectName + "SOAP"));
                replacements.add(new Replacement("soapAction=\"" + sourceProjectName + "\\?",
                        "soapAction=\"" + targetProjectName + "\\?"));
                replacements.add(new Replacement("definitions name=\"" + sourceProjectName + "\"",
                        "definitions name=\"" + targetProjectName + "\""));
                replacements.add(new Replacement("service name=\"" + sourceProjectName + "\"",
                        "service name=\"" + targetProjectName + "\""));
                makeReplacementsInFile(replacements, newPath);
            } else {
                throw new Exception("Unable to rename \"" + oldPath + "\" to \"" + newPath + "\"");
            }//from ww w.j av  a2s  .  co m
        } else {
            throw new Exception("File \"" + newPath + "\" already exists");
        }
    }
}

From source file:org.talend.license.LicenseRetriver.java

public void updateLicense() {
    File userHome = new File(System.getProperty("user.home"));
    File licenseRoot = new File(userHome, "licenses");
    File history = new File(licenseRoot, ".history");
    if (!licenseRoot.exists()) {
        licenseRoot.mkdirs();//from  w w  w .java2 s  . c  o  m
        history.mkdirs();
    }
    final Collection<File> files = new ArrayList<File>();
    for (String version : versions) {
        Collection<File> fs = updateLicense(version, licenseRoot);
        if (null != fs)
            files.addAll(fs);
    }
    File[] his = licenseRoot.listFiles(new FileFilter() {
        public boolean accept(File f) {
            return f.isFile() && !files.contains(f);
        }
    });
    if (null != his && his.length > 0) {
        for (File file : his) {
            file.renameTo(new File(history, file.getName()));
        }
    }
}

From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void renameProjectFile(String projectsDir, String sourceProjectName, String targetProjectName)
        throws Exception {
    String oldPath = projectsDir + "/" + targetProjectName + "/" + sourceProjectName + ".xml";
    File oldFile = new File(oldPath);
    if (oldFile.exists()) {
        String newPath = projectsDir + "/" + targetProjectName + "/" + targetProjectName + ".xml";
        File newFile = new File(newPath);
        if (!newFile.exists()) {
            if (oldFile.renameTo(newFile)) {
                List<Replacement> replacements = new ArrayList<Replacement>();
                if (isPreviousXmlFileFormat(newPath)) {
                    // replace project's bean name
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\"",
                            "value=\"" + targetProjectName + "\""));
                    makeReplacementsInFile(replacements, newPath);
                } else {
                    // replace project's bean name
                    replacements.add(new Replacement("<!--<Project : " + sourceProjectName + ">",
                            "<!--<Project : " + targetProjectName + ">"));
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\"",
                            "value=\"" + targetProjectName + "\"", "<!--<Project"));
                    replacements.add(new Replacement("<!--</Project : " + sourceProjectName + ">",
                            "<!--</Project : " + targetProjectName + ">"));
                    makeReplacementsInFile(replacements, newPath);
                }/*  www.ja  va  2s. c  o m*/
            } else {
                throw new Exception("Unable to rename \"" + oldPath + "\" to \"" + newPath + "\"");
            }
        } else {
            throw new Exception("File \"" + newPath + "\" already exists");
        }
    } else {
        throw new Exception("File \"" + oldPath + "\" does not exist");
    }
}

From source file:com.bladecoder.engineeditor.model.Chapter.java

public void renameChapter(String oldId, String newId)
        throws TransformerException, ParserConfigurationException, SAXException, IOException {
    File f = new File(modelPath + id + EngineAssetManager.CHAPTER_EXT);
    f.renameTo(new File(modelPath + newId + EngineAssetManager.CHAPTER_EXT));

    String i18nFilename = modelPath + id + ".properties";
    f = new File(i18nFilename);
    f.renameTo(new File(modelPath + newId + ".properties"));
}

From source file:com.twinsoft.convertigo.engine.util.ProjectUtils.java

public static void renameXmlProject(String projectsDir, String sourceProjectName, String targetProjectName)
        throws Exception {
    String oldPath = projectsDir + "/" + targetProjectName + "/" + sourceProjectName + ".xml";
    File oldFile = new File(oldPath);
    if (oldFile.exists()) {
        String newPath = projectsDir + "/" + targetProjectName + "/" + targetProjectName + ".xml";
        File newFile = new File(newPath);
        if (!newFile.exists()) {
            if (oldFile.renameTo(newFile)) {
                List<Replacement> replacements = new ArrayList<Replacement>();
                if (isPreviousXmlFileFormat(newPath)) {
                    // replace project's bean name
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\"",
                            "value=\"" + targetProjectName + "\""));
                    // replace project's name references
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\\.",
                            "value=\"" + targetProjectName + "\\."));
                    makeReplacementsInFile(replacements, newPath);
                } else {
                    // replace project's bean name
                    replacements.add(new Replacement("<!--<Project : " + sourceProjectName + ">",
                            "<!--<Project : " + targetProjectName + ">"));
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\"",
                            "value=\"" + targetProjectName + "\"", "<!--<Project"));
                    replacements.add(new Replacement("<!--</Project : " + sourceProjectName + ">",
                            "<!--</Project : " + targetProjectName + ">"));
                    // replace project's name references
                    replacements.add(new Replacement("value=\"" + sourceProjectName + "\\.",
                            "value=\"" + targetProjectName + "\\."));
                    makeReplacementsInFile(replacements, newPath);
                }//from ww w  .  j  a v a 2s  .  com
            } else {
                throw new Exception("Unable to rename \"" + oldPath + "\" to \"" + newPath + "\"");
            }
        } else {
            throw new Exception("File \"" + newPath + "\" already exists");
        }
    } else {
        throw new Exception("File \"" + oldPath + "\" does not exist");
    }
}

From source file:nl.jk_5.nailed.plugin.nmm.NmmMappack.java

@Override
public void prepareWorld(File destination, SettableFuture<Void> future) {
    HttpClient httpClient = HttpClientBuilder.create().build();
    try {//from w w w  .j  a  v a  2s . co  m
        String mappack = this.path.split("/", 2)[1];
        HttpGet request = new HttpGet("http://nmm.jk-5.nl/" + this.path + "/versions.json");
        HttpResponse response = httpClient.execute(request);
        MappackInfo list = NmmPlugin.gson.fromJson(EntityUtils.toString(response.getEntity(), "UTF-8"),
                MappackInfo.class);

        HttpGet request2 = new HttpGet(
                "http://nmm.jk-5.nl/" + this.path + "/" + mappack + "-" + list.latest + ".zip");
        HttpEntity response2 = httpClient.execute(request2).getEntity();
        if (response2 != null) {
            File mappackZip = new File(destination, "mappack.zip");
            try (ReadableByteChannel source = Channels.newChannel(response2.getContent());
                    FileChannel out = FileChannel.open(mappackZip.toPath(), StandardOpenOption.CREATE_NEW,
                            StandardOpenOption.WRITE)) {
                out.transferFrom(source, 0, Long.MAX_VALUE);
            }
            ZipUtils.extract(mappackZip, destination);
            mappackZip.delete();
            this.dir = destination;
            File dataDir = new File(destination, ".data");
            dataDir.mkdir();
            File metadataLocation = new File(dataDir, "game.xml");
            new File(destination, "game.xml").renameTo(metadataLocation);
            new File(destination, "scripts").renameTo(new File(dataDir, "scripts"));
            File worldsDir = new File(destination, "worlds");
            for (File f : worldsDir.listFiles()) {
                f.renameTo(new File(destination, f.getName()));
            }
            worldsDir.delete();
            //metadata = XmlMappackMetadata.fromFile(metadataLocation);
            future.set(null);
        } else {
            future.setException(new RuntimeException(
                    "Got an empty response while downloading mappack " + this.path + " from nmm.jk-5.nl"));
        }
    } catch (Exception e) {
        future.setException(
                new RuntimeException("Was not able to download mappack " + this.path + " from nmm.jk-5.nl", e));
    }
}