/** * Prechecks before normal write * * <p> * * <ul> * <li>If the tag is actually empty, remove the tag * <li>if the file is not writable, throw exception * <li> * <li>If the file is too small to be a valid file, throw exception * <li> * </ul> * * @param af * @throws CannotWriteException */ private void precheckWrite(AudioFile af) throws CannotWriteException { // Preliminary checks try { if (af.getTag().isEmpty()) { delete(af); return; } } catch (CannotReadException re) { throw new CannotWriteException( ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); } if (!af.getFile().canWrite()) { logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); throw new CannotWriteException( ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); } if (af.getFile().length() <= MINIMUM_FILESIZE) { logger.severe( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg( af.getFile().getPath())); throw new CannotWriteException( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg( af.getFile().getPath())); } }
/** * Check can write to file * * @param file * @throws IOException */ public void precheck(File file) throws IOException { if (!file.exists()) { logger.severe( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_NOT_FOUND.getMsg(file.getName())); throw new IOException( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_NOT_FOUND.getMsg(file.getName())); } if (!file.canWrite()) { logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(file.getName())); throw new IOException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(file.getName())); } if (file.length() <= MINIMUM_FILESIZE) { logger.severe( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getName())); throw new IOException( ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getName())); } }