Example usage for java.nio.file Files move

List of usage examples for java.nio.file Files move

Introduction

In this page you can find the example usage for java.nio.file Files move.

Prototype

public static Path move(Path source, Path target, CopyOption... options) throws IOException 

Source Link

Document

Move or rename a file to a target file.

Usage

From source file:frameworks.Masken.java

public boolean maskenInstall(JTable table, JTextArea jTLog, EDPSession session, String LinuxUser,
        String LinuxPass, String Host) {
    try {/*w  w w. j  ava 2  s.co m*/
        ByteArrayOutputStream error = new ByteArrayOutputStream();
        StringBuilder fromServer = new StringBuilder();
        StringBuilder screenls = new StringBuilder();
        StringBuilder screenlsstring = new StringBuilder();
        String maskennummer;
        String fromServerString = "";
        String[] fromServerArray;
        String resourcesServerString = "";
        String[] resourcesServerArray;
        ArrayList datei = new ArrayList();
        String prio = "";
        String xmlziel = "";
        String resourcesziel = "";
        int masksearch = 0;
        int sshexitstatus = 0;
        File file = null;
        int zielzeile = 0;
        String tabellekopf = "";
        boolean failure = false;
        int firstcell = 0;
        int lastcell = 0;
        boolean newpanenotebook = true;

        //SSh Verbindung zum Mandanten ffnen
        SshClient sshclient = new SshClient();
        sshclient.connect(LinuxUser, LinuxPass, Host, 22);

        jTLog.append("----------Maskenimport----------\n");

        jTLog.append("Vorhandene Masken aus Mandanten ermittelt\n");
        jTLog.paint(jTLog.getGraphics());
        //Dateinamen erzeugen
        for (int i = 0; i < table.getRowCount(); i++) {
            //Fehlerflag auf true setzen
            failure = true;
            xmlziel = table.getValueAt(i, 2).toString().replace(table.getValueAt(i, 0).toString(),
                    table.getValueAt(i, 1).toString());
            xmlziel = table.getValueAt(i, 2).toString();
            resourcesziel = table.getValueAt(i, 3).toString().replace(table.getValueAt(i, 0).toString(),
                    table.getValueAt(i, 1).toString());
            maskennummer = table.getValueAt(i, 1).toString();

            // hab ich eine ZD und ein Masken TGZ?      
            if (table.getValueAt(i, 3).equals("TGZ")) {
                xmlziel = table.getValueAt(i, 2).toString();
                prio = xmlziel.substring(xmlziel.indexOf(".") + 1, xmlziel.lastIndexOf("."));
                prio = prio.substring(prio.indexOf(".") + 1, prio.length());
                // Dann kann ich die Maske einfach auf den Serverv kopieren
                file = new File(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString());
                sshexitstatus = sshclient.sendfile(file.toString(), xmlziel);
                jTLog.append("Neue Maske " + maskennummer + prio + " wird hochgeladen\n");
                jTLog.paint(jTLog.getGraphics());
                // und importieren
                jTLog.append("Neue Maske " + maskennummer + prio + " wird im Mandanten importiert\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendcommand(
                        "eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio + " " + xmlziel,
                        error, fromServer);

                // und generieren
                jTLog.append("Neue Maske " + maskennummer + prio + " wird generiert\n");
                jTLog.paint(jTLog.getGraphics());
                // Maske generieren
                maskegenerieren(session, maskennummer, prio);

                jTLog.append(error.toString());
                jTLog.paint(jTLog.getGraphics());
                // Kein ZD und kein TGZ File, also muss die Maske integriert werden
            } else {
                datei.clear();
                prio = xmlziel.substring(xmlziel.indexOf(".") + 1, xmlziel.lastIndexOf("."));
                prio = prio.substring(prio.indexOf(".") + 1, prio.indexOf("-"));
                //Tabelle oder Kopf
                tabellekopf = xmlziel.substring(xmlziel.lastIndexOf(".") - 1, xmlziel.lastIndexOf("."));
                if (tabellekopf.equals("Z")) {
                    tabellekopf = "_T.xml";
                } else {
                    tabellekopf = "_M.xml";
                }
                // Maske individualisieren falls notwendig
                individuelleMaskePruefen(session, maskennummer, prio, jTLog);
                // Maske sichern mit screen_export
                jTLog.append(
                        "Maske " + maskennummer + " " + prio + " wird gesichert und kann mit screen_import -n "
                                + maskennummer + " -p " + prio + " screen_restauriert werden\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendcommand(
                        "eval `sh denv.sh`;screen_export.sh -n " + maskennummer + " -p " + prio, error,
                        fromServer);

                //Tmp leeren
                File tmpdir = new File("tmp");
                if (tmpdir.exists() && (tmpdir.isDirectory())) {
                    deleteDir(tmpdir);

                }
                new File("tmp").mkdir();

                // Masken.tgz abholen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird geladen\n");
                jTLog.paint(jTLog.getGraphics());
                String servermaske = "./screen." + maskennummer + "." + prio + ".tgz";

                sshexitstatus = sshclient.getfile(servermaske, "tmp\\");
                if (sshexitstatus == -1) {// Maske wurde erfolgreich geladen

                    //Maske einlesen
                    jTLog.append("Maske " + maskennummer + " " + prio + " wird ausgepackt\n");
                    jTLog.paint(jTLog.getGraphics());
                    //tgz lokal auspacken
                    uncompressTarGZ(new File("tmp\\screen." + maskennummer + "." + prio + ".tgz"),
                            new File("tmp\\"));
                    // tgz lschen
                    new File("tmp\\screen." + maskennummer + "." + prio + ".tgz").delete();
                    String changemaske = "screen_" + maskennummer + "_" + prio + tabellekopf;
                    //Maske einlesen
                    jTLog.append("Maske " + maskennummer + " " + prio + " wird erweitert\n");
                    jTLog.paint(jTLog.getGraphics());
                    BufferedReader inservermaske = null;
                    inservermaske = new BufferedReader(new FileReader("tmp\\screens\\screen_" + maskennummer
                            + "\\" + prio + "\\screen_" + maskennummer + "_" + prio + tabellekopf));
                    BufferedReader inmaske = null;
                    inmaske = new BufferedReader(
                            new FileReader(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString()));
                    PrintWriter outservermaske = new PrintWriter(
                            new BufferedWriter(new FileWriter("tmp\\screens\\screen_" + maskennummer + "\\"
                                    + prio + "\\Xscreen_" + maskennummer + "_" + prio + tabellekopf)));
                    int lineNr = 0;
                    zielzeile = 0;
                    firstcell = 0;
                    lastcell = 0;
                    String line = inservermaske.readLine();
                    while (line != null) {

                        datei.add(line);
                        if (line.contains("<cell") && (firstcell == 0))
                            firstcell = lineNr;
                        if (line.contains("</layout.grid") && (firstcell != 0))
                            lastcell = lineNr;
                        if (line.contains("</pane.notebook>")) {
                            zielzeile = lineNr;
                            newpanenotebook = false;
                        }
                        lineNr++;

                        line = inservermaske.readLine();
                    }
                    inservermaske.close();

                    // Raus schreiben der Datei
                    for (int izeilen = 0; izeilen < lineNr - 1; izeilen++) {
                        outservermaske.print(datei.get(izeilen) + "\n");
                        if ((zielzeile == 0) && (firstcell == izeilen)) {
                            outservermaske.print(
                                    "<layout.notebook>\n<pane.notebook msgId=\"b825893d-f00a-4500-ae24-c2fe5364ae0e\">\n <layout.grid>\n"
                                            + "      <cell gridX=\"0\" gridY=\"0\">\n");
                        }
                        if ((zielzeile == 0) && (lastcell == izeilen)) {
                            outservermaske.print("</pane.notebook>\n");
                            zielzeile = izeilen;
                        }

                        if ((izeilen == zielzeile) && (zielzeile != 0)) {
                            line = inmaske.readLine();
                            while (line != null) {
                                // Zuerst die Datei einlesen und jede Zeile raus schreiben
                                outservermaske.print(line + "\n");
                                line = inmaske.readLine();

                            }
                            if (newpanenotebook)
                                outservermaske.print("</layout.notebook>\n </cell>\n </layout.grid> \n");
                        }
                    }
                    outservermaske.close();

                    // Neue Datei nun auf die alte kopieren
                    Files.move(
                            Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\Xscreen_"
                                    + maskennummer + "_" + prio + tabellekopf),
                            Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\screen_"
                                    + maskennummer + "_" + prio + tabellekopf),
                            REPLACE_EXISTING);

                    // Resources Dateien anschauen
                    // Append an die Resources.language
                    // sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >> ./screens/screen_" + maskennummer + "/" + prio + "/Resources.language", error, fromServer);
                    String resourcesstring = FileUtils.readFileToString(
                            new File(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 3).toString()),
                            "utf-8");
                    FileWriter fw = new FileWriter(new File(
                            "tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\Resources.language"),
                            true);
                    fw.write(resourcesstring);//appends the string to the file
                    if (newpanenotebook)
                        fw.write("b825893d-f00a-4500-ae24-c2fe5364ae0e=Allgemein\n");
                    fw.close();
                    //An Resources_*  den String auch noch anhngen
                    // dazu erst mal die Dateien suchen
                    Path dir = Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio);
                    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "Resources_*")) {
                        for (Path resourcesfile : stream) {
                            fw = new FileWriter(resourcesfile.toFile(), true);
                            fw.write(resourcesstring);//appends the string to the file
                            if (newpanenotebook)
                                fw.write("b825893d-f00a-4500-ae24-c2fe5364ae0e=Allgemein\n");
                            fw.close();
                        }
                    }

                    // Tgz wieder erzeugen
                    createTarGzip("tmp\\", "tmp\\screen." + maskennummer + "." + prio + ".tgz");
                    // Maske wieder auf Server schieben

                    sshexitstatus = sshclient.sendfile("\\tmp\\screen." + maskennummer + "." + prio + ".tgz",
                            "screen." + maskennummer + "." + prio + ".tgz");
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird hochgeladen\n");
                    jTLog.paint(jTLog.getGraphics());
                    // und importieren
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird im Mandanten importiert\n");
                    jTLog.paint(jTLog.getGraphics());
                    sshexitstatus = sshclient
                            .sendcommand(
                                    "eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio
                                            + " " + "screen." + maskennummer + "." + prio + ".tgz",
                                    error, fromServer);

                    // und generieren
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird generiert\n");
                    jTLog.paint(jTLog.getGraphics());
                    // Maske generieren
                    maskegenerieren(session, maskennummer, prio);

                    jTLog.append(error.toString());
                    jTLog.paint(jTLog.getGraphics());

                }
                /*
                //Alter Weg
                // Maske abholen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird geladen\n");
                jTLog.paint(jTLog.getGraphics());
                //String servermaske = "./screens/screen_" + maskennummer + "/" + prio + "/screen_" + maskennummer + "_" + prio + "_M.xml";
                servermaske = "./screens/screen_" + maskennummer + "/" + prio + "/screen_" + maskennummer + "_" + prio + tabellekopf;
                        
                sshexitstatus = sshclient.getfile(servermaske, "tmp\\" + maskennummer + prio + ".xml");
                if (sshexitstatus == -1) {// Maske wurde erfolgreich geladen
                //Maske einlesen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird erweitert\n");
                jTLog.paint(jTLog.getGraphics());
                        
                BufferedReader inservermaske = null;
                inservermaske = new BufferedReader(new FileReader("tmp\\" + maskennummer + prio + ".xml"));
                BufferedReader inmaske = null;
                inmaske = new BufferedReader(new FileReader(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString()));
                PrintWriter outservermaske = new PrintWriter(new BufferedWriter(new FileWriter("tmp\\" + maskennummer + prio + "X.xml")));
                int lineNr = 0;
                String line = inservermaske.readLine();
                while (line != null) {
                        
                    datei.add(line);
                        
                    if (line.contains("</pane.notebook>")) {
                        zielzeile = lineNr;
                    }
                    lineNr++;
                        
                    line = inservermaske.readLine();
                }
                inservermaske.close();
                        
                // Raus schreiben der Datei
                for (int izeilen = 0; izeilen < lineNr - 1; izeilen++) {
                    outservermaske.print(datei.get(izeilen) + "\n");
                    if (izeilen == zielzeile) {
                        line = inmaske.readLine();
                        while (line != null) {
                            // Zuerst die Datei einlesen und jede Zeile raus schreiben
                            outservermaske.print(line + "\n");
                            line = inmaske.readLine();
                        
                        }
                    }
                }
                outservermaske.close();
                        
                //Datei zurck zum server schicken
                jTLog.append("Maske " + maskennummer + " " + prio + " wird gesendet\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendfile("tmp\\" + maskennummer + prio + "X.xml", servermaske);
                if (sshexitstatus == -1) {// Maske wurde auf Server bertragen
                    // Jetzt noch die Resources Datei an die Resources auf dem server anhngen
                    sshexitstatus = sshclient.sendfile(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 3).toString(), "./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW");
                    if (sshexitstatus == -1) {
                        sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >> ./screens/screen_" + maskennummer + "/" + prio + "/Resources.language", error, fromServer);
                        //Resources wurde auf Server bertragen  
                         jTLog.append(error.toString());
                        jTLog.paint(jTLog.getGraphics());
                        if (sshexitstatus==0)
                        {
                           sshexitstatus = sshclient.sendcommand("ls screens/screen_" + maskennummer + "/" + prio + "/Resources_* -l", error, fromServer);
                           jTLog.append(error.toString());
                            jTLog.paint(jTLog.getGraphics());
                        if (sshexitstatus == 0) {
                                    
                            resourcesServerString = fromServer.toString();
                            resourcesServerArray = resourcesServerString.split("\n");
                            ///Bisher alles gut gelaufen, deswegen failure auf false setzen
                            failure = false;
                            for (int iresources = 0; iresources < resourcesServerArray.length; iresources++) {
                                if (resourcesServerArray[iresources].toString().contains("Resources")) {
                                    sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >>" + resourcesServerArray[iresources].toString().substring(resourcesServerArray[iresources].lastIndexOf(" "), resourcesServerArray[iresources].length()), error, fromServer);
                                    if (sshexitstatus != 0) {
                                        failure = true;
                                    }
                                    jTLog.append(error.toString());
                                    jTLog.paint(jTLog.getGraphics());
                                }
                        
                            }
                        
                            jTLog.append("Maske " + maskennummer + " " + prio + " wird generiert\n");
                        
                            // Maske nun noch generieren
                            maskegenerieren(session, maskennummer, prio); 
                        }
                               
                                
                        }
                        
                    }
                        
                }
                        
                }*/
                if (failure) {

                    //Alte Maske wieder importieren 
                    //  jTLog.append(error.toString());
                    //  jTLog.append("Gesicherte Maske wird wieder installiert !!! manuelle Nacharbeit notwendig!!!\n");
                    //  jTLog.paint(jTLog.getGraphics());
                    //  sshexitstatus = sshclient.sendcommand("eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio+" screen."+maskennummer+"."+prio+".tgz", error, fromServer);
                }

            }

        }

    } catch (JSchException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InterruptedException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SftpException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    }
    return true;
}

From source file:org.apache.nifi.processors.standard.FetchFile.java

protected void move(final File source, final File target, final boolean overwrite) throws IOException {
    final File targetDirectory = target.getParentFile();

    // convert to path and use Files.move instead of file.renameTo so that if we fail, we know why
    final Path targetPath = target.toPath();
    if (!targetDirectory.exists()) {
        Files.createDirectories(targetDirectory.toPath());
    }/* w  w  w .  ja  v  a 2  s  .  co  m*/

    final CopyOption[] copyOptions = overwrite ? new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }
            : new CopyOption[] {};
    Files.move(source.toPath(), targetPath, copyOptions);
}

From source file:org.artifactory.repo.db.importexport.DbRepoImportHandler.java

private void moveFileToExternalFileStore(File sourceFile, String expectedSha1) throws IOException {
    // If exclude content and file exists use it for the external filestore if it exists
    StorageProperties storageProperties = StorageContextHelper.get().beanForType(StorageProperties.class);
    String extFilestoreDir = storageProperties.getBinaryProviderExternalDir();
    if (StringUtils.isNotBlank(extFilestoreDir)) {
        Path filePath = Paths.get(extFilestoreDir, expectedSha1.substring(0, 2), expectedSha1);
        if (!Files.exists(filePath)) {
            Files.move(sourceFile.toPath(), filePath, StandardCopyOption.ATOMIC_MOVE);
        }//from w  ww  .java  2  s  .  c  om
    }
}

From source file:org.codice.ddf.configuration.admin.ConfigurationAdminMigrationTest.java

@Test
public void testInitStillProcessesFilesWhenTheyCannotBeMovedToFailedDirectory() throws Exception {

    setUpTwoConfigFileIterator(configurationDirectoryStream);

    when(configurationFileFactory.createConfigurationFile(CONFIG_PATH1))
            .thenThrow(new ConfigurationFileException(""));
    when(configurationFileFactory.createConfigurationFile(CONFIG_PATH2))
            .thenThrow(new ConfigurationFileException(""));

    PowerMockito.doThrow(new IOException()).when(Files.class);
    Files.move(any(Path.class), any(Path.class), any(StandardCopyOption.class));

    ConfigurationAdminMigration configurationAdminMigration = new ConfigurationAdminMigration(
            configurationDirectoryStream, PROCESSED_DIRECTORY_PATH, FAILED_DIRECTORY_PATH,
            configurationFileFactory, configurationFilePoller, configurationAdmin,
            CONFIGURATION_FILE_EXTENSION);

    configurationAdminMigration.init();//from w w w  .  j  ava2  s.c om

    verify(configurationDirectoryStream).iterator();
    verify(configurationFileFactory).createConfigurationFile(CONFIG_PATH1);
    verify(configurationFileFactory).createConfigurationFile(CONFIG_PATH2);
    verify(configurationDirectoryStream).close();
}

From source file:com.smi.travel.monitor.MonitorGalileo.java

@Override
int archiveDataFile(String file, int option) {
    try {/*from   w  w  w  . j av  a2 s.  c o m*/
        Path sourceFile = Paths.get(this.monitorDirectory + file);
        Path destFile = Paths.get(this.archivedDirectory + file);
        Path errFile = Paths.get(this.errorDirectory + file);

        if (option == 1) {
            System.out.println("Archiving file " + destFile);
            Files.move(sourceFile, destFile, REPLACE_EXISTING);
        } else {
            System.out.println("Archiving to error folder for file " + errFile);
            Files.move(sourceFile, errFile, REPLACE_EXISTING);
        }
        return 1;
    } catch (IOException ex) {
        Logger.getLogger(MonitorAmadeus.class.getName()).log(Level.SEVERE, null, ex);
    }
    return 0;
}

From source file:com.smi.travel.monitor.MonitorAmadeus.java

@Override
protected int archiveDataFile(String file, int option) {
    try {//from   ww  w. j  av  a 2s . co  m
        Path sourceFile = Paths.get(this.monitorDirectory + file);
        Path destFile = Paths.get(this.archivedDirectory + file);
        Path errFile = Paths.get(this.errorDirectory + file);

        if (option == 1) {
            Files.move(sourceFile, destFile, REPLACE_EXISTING);
        } else {
            Files.move(sourceFile, errFile, REPLACE_EXISTING);
        }
        return 1;

    } catch (IOException ex) {
        Logger.getLogger(MonitorAmadeus.class.getName()).log(Level.SEVERE, null, ex);
    }
    return 0;
}

From source file:org.cryptomator.cryptofs.CryptoFileSystemImpl.java

void move(CryptoPath cleartextSource, CryptoPath cleartextTarget, CopyOption... options) throws IOException {
    if (cleartextSource.equals(cleartextTarget)) {
        return;//from   w w w . ja v a2 s  .com
    }
    Path ciphertextSourceFile = cryptoPathMapper.getCiphertextFilePath(cleartextSource,
            CiphertextFileType.FILE);
    Path ciphertextSourceDirFile = cryptoPathMapper.getCiphertextFilePath(cleartextSource,
            CiphertextFileType.DIRECTORY);
    if (Files.exists(ciphertextSourceFile)) {
        // FILE:
        Path ciphertextTargetFile = cryptoPathMapper.getCiphertextFilePath(cleartextTarget,
                CiphertextFileType.FILE);
        Files.move(ciphertextSourceFile, ciphertextTargetFile, options);
    } else if (Files.exists(ciphertextSourceDirFile)) {
        // DIRECTORY:
        Path ciphertextTargetDirFile = cryptoPathMapper.getCiphertextFilePath(cleartextTarget,
                CiphertextFileType.DIRECTORY);
        if (!ArrayUtils.contains(options, StandardCopyOption.REPLACE_EXISTING)) {
            // try to move, don't replace:
            Files.move(ciphertextSourceDirFile, ciphertextTargetDirFile, options);
        } else if (ArrayUtils.contains(options, StandardCopyOption.ATOMIC_MOVE)) {
            // replace atomically (impossible):
            assert ArrayUtils.contains(options, StandardCopyOption.REPLACE_EXISTING);
            throw new AtomicMoveNotSupportedException(cleartextSource.toString(), cleartextTarget.toString(),
                    "Replacing directories during move requires non-atomic status checks.");
        } else {
            // move and replace (if dir is empty):
            assert ArrayUtils.contains(options, StandardCopyOption.REPLACE_EXISTING);
            assert !ArrayUtils.contains(options, StandardCopyOption.ATOMIC_MOVE);
            if (Files.exists(ciphertextTargetDirFile)) {
                Path ciphertextTargetDir = cryptoPathMapper.getCiphertextDirPath(cleartextTarget);
                try (DirectoryStream<Path> ds = Files.newDirectoryStream(ciphertextTargetDir)) {
                    if (ds.iterator().hasNext()) {
                        throw new DirectoryNotEmptyException(cleartextTarget.toString());
                    }
                }
                Files.delete(ciphertextTargetDir);
            }
            Files.move(ciphertextSourceDirFile, ciphertextTargetDirFile, options);
        }
        dirIdProvider.move(ciphertextSourceDirFile, ciphertextTargetDirFile);
    } else {
        throw new NoSuchFileException(cleartextSource.toString());
    }
}

From source file:org.codice.ddf.configuration.admin.ConfigurationAdminMigrationTest.java

@Test
public void testNotifyWhenFileIsReprocessed() throws Exception {

    when(configurationFileFactory.createConfigurationFile(CONFIG_PATH1)).thenReturn(configFile1);

    ConfigurationAdminMigration configurationAdminMigration = createConfigurationAdminMigratorForNotify();

    configurationAdminMigration.notify(CONFIG_PATH1);

    verify(configurationFileFactory).createConfigurationFile(CONFIG_PATH1);
    verify(configFile1).createConfig();//from   ww  w .j  a  v a 2  s  .  c  o  m
    verifyStatic();
    Files.move(Paths.get("/root/etc/" + CONFIG_FILE_PATH1),
            Paths.get(PROCESSED_DIRECTORY_PATH.resolve(CONFIG_FILE_PATH1).toString()), REPLACE_EXISTING);

}

From source file:com.searchcode.app.jobs.repository.IndexBaseRepoJob.java

/**
 * Logs to the logs directory a formatted CSV of the supplied list strings
 */// w w  w  .  j a v a2  s.c  om
private void logIndexed(String repoName, List<String[]> reportList) {
    try {
        CSVWriter writer = new CSVWriter(
                new FileWriter(Singleton.getHelpers().getLogPath() + repoName + ".csv.tmp"));
        writer.writeAll(reportList);
        writer.flush();
        writer.close();

        Path source = Paths.get(Singleton.getHelpers().getLogPath() + repoName + ".csv.tmp");
        Files.move(source, source.resolveSibling(repoName + ".csv"), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException ex) {
        Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass()
                + " logIndexed for " + repoName + "\n with message: " + ex.getMessage());
    }
}

From source file:com.stimulus.archiva.store.MessageStore.java

public void quarantineMessages() {
    String notarchiveddir = Config.getFileSystem().getNoArchivePath();
    logger.debug("quarantineEmails {noarchivedpath='" + notarchiveddir + "'}");
    File noarchiveDir = new File(notarchiveddir);
    if (!noarchiveDir.exists())
        return;//from   w w  w .  j a v a 2 s . c  o  m
    if (noarchiveDir.isDirectory()) {
        String[] children = noarchiveDir.list();
        if (children.length > 0)
            logger.warn("there are messages that require rearchival {notarchiveddirectory='" + notarchiveddir
                    + "'}");
        for (int i = 0; i < children.length; i++) {
            String filepath = notarchiveddir + File.separatorChar + children[i];
            logger.debug("attempting to quarantine file {path='" + filepath + "'}");
            try {
                copyEmailToQuarantine(new File(filepath));
            } catch (Exception e) {
                logger.error("failed to quarantine email (filepath='" + filepath + "'}", e);
                continue;
            }
            try {
                File delFile = new File(filepath);
                boolean deleted;
                deleted = delFile.delete();
                File tmpfile = null;
                if (!deleted)
                    //Mod start Seolhwa.kim 2017-04-13
                    //delFile.renameTo(File.createTempFile("oldrecovery", "tmp"));

                    tmpfile = File.createTempFile("oldrecovery", "tmp");

                try {
                    Files.move(Paths.get(delFile.getAbsolutePath()), Paths.get(tmpfile.getAbsolutePath()),
                            StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //Mod end Seolhwa.kim 2017-04-13

                delFile.deleteOnExit();
            } catch (IOException io) {
                logger.error("failed to delete email {filepath='" + filepath + "'");
            }
        }
    }
}