@Nonnull public static File moveFile (@Nonnull final File aSrc, @Nonnull final File aDestFile, final boolean bOverwrite, final boolean bRename) throws IOException { File aRealDestFile = aDestFile; if (!bOverwrite && aRealDestFile.exists ()) { if (!bRename) throw new IOException ("File already exists: " + aRealDestFile); aRealDestFile = getUniqueFile (aRealDestFile.getAbsoluteFile ().getParentFile (), aRealDestFile.getName ()); } // Copy FileIOError aIOErr = s_aFOM.copyFile (aSrc, aRealDestFile); if (aIOErr.isFailure ()) throw new IOException ("Copy failed: " + aIOErr.toString ()); // Delete old aIOErr = s_aFOM.deleteFile (aSrc); if (aIOErr.isFailure ()) { s_aFOM.deleteFile (aRealDestFile); throw new IOException ("Move failed, unable to delete " + aSrc + ": " + aIOErr.toString ()); } return aRealDestFile; }
/** * Deletes the underlying storage for a file item, including deleting any * associated temporary disk file. Although this storage will be deleted * automatically when the <code>FileItem</code> instance is garbage collected, * this method can be used to ensure that this is done at an earlier time, * thus preserving system resources. */ public void delete () { m_aCachedContent = null; final File aTempFile = getStoreLocation (); if (aTempFile != null) { final FileIOError aIOError = FileOperations.deleteFileIfExisting (aTempFile); if (aIOError.isFailure ()) if (LOGGER.isErrorEnabled ()) LOGGER.error ("Failed to delete temporary file " + aTempFile + " with error " + aIOError.toString ()); } }
public void deleteAllTemporaryFiles () { final ICommonsList <File> aTempFiles = m_aRWLock.writeLocked ( () -> { final ICommonsList <File> ret = m_aTempFiles.getClone (); m_aTempFiles.clear (); return ret; }); for (final File aTempFile : aTempFiles) { final FileIOError aIOError = FileOperations.deleteFileIfExisting (aTempFile); if (aIOError.isFailure ()) { if (LOGGER.isErrorEnabled ()) LOGGER.error ("Failed to delete temporary file " + aTempFile + " with error " + aIOError.toString ()); _addTempFile (aTempFile); } } } }
final FileIOError aError = AS4IOHelper.getFileOperationManager ().deleteFileIfExisting (aFile); if (aError.isFailure ()) LOGGER.warn (" Failed to delete " + aFile.getAbsolutePath () + ": " + aError.toString ());
aPendingFile + " - " + aIOErr.toString ());