List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:org.forgerock.doc.maven.PreSiteBuildMojo.java
/** * Rename a single built document ${getDocumentSrcName()} + extension. For * example, rename <code>index.pdf</code> to * <code>OpenAM-Admin-Guide.pdf</code>. * * @param file File to rename, such as <code>index.pdf</code> * @param docName Simple document name such as <code>admin-guide</code> * @throws MojoExecutionException Something went wrong renaming the file. *///w w w .ja v a2 s. co m final void renameDocument(final File file, final String docName) throws MojoExecutionException { String ext = FilenameUtils.getExtension(file.getName()); String newName = file.getParent() + File.separator + DocUtils.renameDoc(getProjectName(), docName, ext); try { File newFile = new File(newName); if (!newFile.exists()) { FileUtils.moveFile(file, newFile); } getLog().info("Renamed " + file.getName() + " to " + newFile); } catch (IOException e) { throw new MojoExecutionException("Failed to rename " + file); } }
From source file:org.freeeed.print.OfficePrint.java
/** * soffice commandline exampple soffice --headless --convert-to * pdf:writer_pdf_Export --outdir . AdminContracts.doc * * @param inputFile//from w ww . jav a2 s.com * @param outputFile * @return */ public boolean convertToPdfWithSOffice(File inputFile, File outputFile) { String extension = Files.getFileExtension(inputFile.getAbsolutePath()).toLowerCase(); // passing unsupported extension causes soffice to freeze, need to review which extensions are supported. if (SUPPORTED_EXTENSIONS.indexOf(extension) >= 0) { String fullCommand = OsUtil.getSOfficeExecutableLocation() + " --headless " + " --convert-to pdf:writer_pdf_Export " + inputFile.getAbsolutePath() + " --outdir " + outputFile.getParentFile().getAbsolutePath(); try { OsUtil.runCommand(fullCommand); File sofficeOutputFile = new File( FilenameUtils.removeExtension(inputFile.getAbsolutePath()) + ".pdf"); if (sofficeOutputFile.exists()) { LOGGER.info("Created PDF at: " + sofficeOutputFile); outputFile.delete(); FileUtils.moveFile(sofficeOutputFile, outputFile); return true; } else { LOGGER.warn("soffice did not produce PDF"); return false; } } catch (IOException e) { LOGGER.error("Could not convert to PDF", e); } } return false; }
From source file:org.gatein.wcm.util.FileAux.java
public static void moveFile(String oldPath, String newPath) { try {/*from w w w. j ava 2s . c om*/ File oldF = new File(oldPath); File newF = new File(newPath); if (!newF.exists()) { FileUtils.moveFile(oldF, newF); } } catch (Exception e) { log.warning("Error trying to move upload: " + oldPath + " to " + newPath + ". Msg: " + e.getMessage()); } }
From source file:org.geopublishing.atlasStyler.swing.JScrollPaneSymbolsLocal.java
@Override protected JPopupMenu getPopupMenu() { if (popupMenu == null) { popupMenu = new JPopupMenu(); /******************************************************************* * Rename a Symbol from disk/*from w ww. jav a 2 s. c om*/ */ JMenuItem rename = new JMenuItem(AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Rename")); rename.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int index = getJListSymbols().locationToIndex(mouseCLickEvent.getPoint()); SingleRuleList singleLocalRulesList = (SingleRuleList) ((DefaultListModel) getJListSymbols() .getModel()).get(index); String symbolFileName = singleLocalRulesList.getStyleName() + ".sld"; File symbolFile = new File( AtlasStylerVector.getSymbolsDir(singleLocalRulesList.getGeometryForm()), symbolFileName); String newName = ASUtil.askForString(JScrollPaneSymbolsLocal.this, singleLocalRulesList.getStyleName(), AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Rename.AskForNewName")); if ((newName == null) || (newName.trim().equals("")) || (newName.equals(singleLocalRulesList.getStyleName()))) return; if (!newName.toLowerCase().endsWith(".sld")) { newName += ".sld"; } File newSymbolFile = new File( AtlasStylerVector.getSymbolsDir(singleLocalRulesList.getGeometryForm()), newName); try { FileUtils.moveFile(symbolFile, newSymbolFile); } catch (IOException e1) { LOGGER.error("rename failed", e1); rescan(true); String message = AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Rename.Error", symbolFile.getAbsolutePath(), newSymbolFile.getAbsolutePath()); LOGGER.warn(message); JOptionPane.showMessageDialog(JScrollPaneSymbolsLocal.this, message); } // Update the JListSymbols singleLocalRulesList.setStyleName(newName.substring(0, newName.length() - 4)); getJListSymbols().repaint(); } }); popupMenu.add(rename); /******************************************************************* * Delete a Symbol on disk */ JMenuItem remove = new JMenuItem(AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Delete")); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int index = getJListSymbols().locationToIndex(mouseCLickEvent.getPoint()); SingleRuleList singleLocalRulesList = (SingleRuleList) ((DefaultListModel) getJListSymbols() .getModel()).get(index); String symbolFileName = singleLocalRulesList.getStyleName() + ".sld"; File symbolFile = new File( AtlasStylerVector.getSymbolsDir(singleLocalRulesList.getGeometryForm()), symbolFileName); int res = JOptionPane.showConfirmDialog(JScrollPaneSymbolsLocal.this, AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Delete.Ask", singleLocalRulesList.getStyleName(), symbolFile.getName()), "", JOptionPane.YES_NO_OPTION); if (res != JOptionPane.YES_OPTION) return; if (!symbolFile.delete()) { String message = AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Delete.Error", symbolFile.getName()); LOGGER.warn(message); JOptionPane.showMessageDialog(JScrollPaneSymbolsLocal.this, message); rescan(true); } else { // Delete the entry from the JListSymbols ((DefaultListModel) getJListSymbols().getModel()).remove(index); // rescan(true); } } }); popupMenu.add(remove); popupMenu.add(new JPopupMenu.Separator()); /******************************************************************* * Rescan directory */ JMenuItem rescan = new JMenuItem(AtlasStylerVector.R("SymbolSelector.Tabs.LocalSymbols.Action.Rescan")); rescan.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { rescan(true); } }); popupMenu.add(rescan); } return popupMenu; }
From source file:org.geosdi.geoplatform.services.utility.PublishUtility.java
public static File getFileNameToLowerCase(File file) { File fileToReturn = new File( FilenameUtils.getFullPath(file.getAbsolutePath()) + file.getName().toLowerCase()); try {// w ww.jav a 2s. co m FileUtils.moveFile(file, fileToReturn); } catch (IOException ex) { logger.error("Error renaming file: " + ex); } return fileToReturn; }
From source file:org.geoserver.util.IOUtils.java
/** * Renames a file./*from w w w.j av a 2 s. c o m*/ * * @param source The file to rename. * @param dest The file to rename to. */ public static void rename(File source, File dest) throws IOException { // same path? Do nothing if (source.getCanonicalPath().equalsIgnoreCase(dest.getCanonicalPath())) return; // windows needs special treatment, we cannot rename onto an existing file boolean win = System.getProperty("os.name").startsWith("Windows"); if (win && dest.exists()) { // windows does not do atomic renames, and can not rename a file if the dest file // exists if (!dest.delete()) { throw new IOException("Could not delete: " + dest.getCanonicalPath()); } } // make sure the rename actually succeeds if (!source.renameTo(dest)) { FileUtils.deleteQuietly(dest); if (source.isDirectory()) { FileUtils.moveDirectory(source, dest); } else { FileUtils.moveFile(source, dest); } } }
From source file:org.geowebcache.sqlite.SqliteConnectionManager.java
void replace(File currentFile, File newFile) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Replacing file '%s' with file '%s'.", currentFile, newFile)); }/* w w w. j a v a 2s . com*/ PooledConnection currentPooledConnection = getPooledConnection(currentFile).getWriteLockOnValidConnection(); try { currentPooledConnection.closeConnection(); pool.remove(currentFile); FileUtils.deleteQuietly(currentFile); FileUtils.moveFile(newFile, currentFile); if (LOGGER.isInfoEnabled()) { LOGGER.info(String.format("File '%s' replaced with file '%s'.", currentFile, newFile)); } } catch (Exception exception) { throw Utils.exception(exception, "Error replacing file '%s' with file '%s'.", currentFile, newFile); } finally { currentPooledConnection.releaseWriteLock(); } }
From source file:org.geowebcache.sqlite.SqliteConnectionManager.java
void rename(File currentFile, File newFile) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Renaming file '%s' to '%s'.", currentFile, newFile)); }/*w ww . ja v a2s . c om*/ PooledConnection pooledConnection = getPooledConnection(currentFile).getWriteLockOnValidConnection(); try { pooledConnection.closeConnection(); pool.remove(currentFile); FileUtils.moveFile(currentFile, newFile); if (LOGGER.isInfoEnabled()) { LOGGER.info(String.format("File '%s' renamed to '%s'.", currentFile, newFile)); } } catch (Exception exception) { throw Utils.exception(exception, "Renaming file '%s' to '%s'.", currentFile, newFile); } finally { pooledConnection.releaseWriteLock(); } }
From source file:org.getspout.spout.io.Download.java
public void move() { File current = getTempFile(); if (current.exists()) { File destination = new File(directory, filename); try {/*from ww w . ja v a2 s . c om*/ FileUtils.moveFile(current, destination); } catch (IOException e) { } } }
From source file:org.getspout.spout.Spout.java
protected void update() { //test install once File runOnce = new File(getDataFolder(), "runonce"); if (!runOnce.exists()) { try {//from w w w . j av a 2s . c o m runOnce.createNewFile(); pingLink("http://bit.ly/spoutserverrunonce"); } catch (Exception e) { } } if (!isUpdateAvailable()) { return; } FileOutputStream fos = null; try { File directory = new File(Bukkit.getServer().getUpdateFolder()); if (!directory.exists()) { try { directory.mkdir(); } catch (SecurityException e1) { } } File tempDirectory = new File(directory, "temp"); if (!tempDirectory.exists()) { try { tempDirectory.mkdir(); } catch (SecurityException e1) { } } File plugin = new File(directory.getPath(), "Spout.jar"); File temp = new File(tempDirectory.getPath(), "Spout.jar"); if (!plugin.exists()) { URL spout = new URL( "http://ci.getspout.org/view/SpoutDev/job/Spout/promotion/latest/Recommended/artifact/target/spout-dev-SNAPSHOT.jar"); HttpURLConnection con = (HttpURLConnection) (spout.openConnection()); System.setProperty("http.agent", ""); //Spoofing the user agent is required to track stats con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30"); ReadableByteChannel rbc = Channels.newChannel(con.getInputStream()); fos = new FileOutputStream(temp); fos.getChannel().transferFrom(rbc, 0, 1 << 24); } if (temp.exists()) { FileUtils.moveFile(temp, plugin); } } catch (Exception e) { } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } }