001    package edu.rice.cs.cunit.instrumentors;
002    
003    import java.io.File;
004    import java.io.IOException;
005    
006    /**
007     * Exception inside the file instrumentor, preventing it to rename two files.
008     *
009     * @author Mathias Ricken
010     */
011    public class CouldNotRenameException extends RetryIOException {
012        /**
013         * Old file, to be renamed to _newFile.
014         */
015        private File _oldFile = null;
016    
017        /**
018         * New file.
019         */
020        private File _newFile = null;
021    
022        /**
023         * Constructs a new exception.
024         * @param oldFile old file to be renamed to newFile
025         * @param newFile new file
026         */
027        public CouldNotRenameException(File oldFile, File newFile) {
028            super("Could not rename file " + oldFile.getPath()+ " to " + newFile.getPath());
029            _oldFile = oldFile;
030            _newFile = newFile;
031        }
032    
033        /**
034         * Retry the failed operation one more time.
035         * @throws java.io.IOException
036         */
037        public void retry() throws IOException {
038            if (_oldFile.exists() && !_newFile.exists()) {
039                if (_oldFile.exists() && !(_oldFile.renameTo(_newFile))) {
040                    throw new IOException(getMessage());
041                }
042            }
043            else {
044                throw new IOException(getMessage() + "; cannot fix, situation not applicable");
045            }
046        }
047    
048    
049    }