public class MyAudioFile implements Parcelable{ private File file; //other fields... public MyAudioFile(AudioFile audioFile){ this.file = audioFile.getFile(); //populate other fields } //parcelable stuff }
/** * <p>Returns a multi-line string with the file path, the encoding audioHeader, and the tag contents.</p> * * @return A multi-line string with the file path, the encoding audioHeader, and the tag contents. * TODO Maybe this can be changed ? */ public String toString() { return "AudioFile " + getFile().getAbsolutePath() + " --------\n" + audioHeader.toString() + "\n" + ((tag == null) ? "" : tag.toString()) + "\n-------------------"; }
/** * <p>Returns a multi-line string with the file path, the encoding audioHeader, and the tag contents.</p> * * @return A multi-line string with the file path, the encoding audioHeader, and the tag contents. * TODO Maybe this can be changed ? */ public String toString() { return "AudioFile " + getFile().getAbsolutePath() + " --------\n" + audioHeader.toString() + "\n" + ((tag == null) ? "" : tag.toString()) + "\n-------------------"; }
/** * <p>Returns a multi-line string with the file path, the encoding audioHeader, and the tag contents. * * @return A multi-line string with the file path, the encoding audioHeader, and the tag contents. * TODO Maybe this can be changed ? */ public String toString() { return "AudioFile " + getFile().getAbsolutePath() + " --------\n" + audioHeader.toString() + "\n" + ((tag == null) ? "" : tag.toString()) + "\n-------------------"; }
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); if (!af.getFile().canWrite()) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); if (af.getFile().length() <= MINIMUM_FILESIZE) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(af.getFile().getPath()));
.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) .getMsg(af.getFile().getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL .getMsg(af.getFile().getPath()));
if (!af.getFile().canWrite()) { throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED.getMsg(af.getFile().getPath())); if (af.getFile().length() <= MINIMUM_FILESIZE) { throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED.getMsg(af.getFile().getPath())); tempF = File.createTempFile(af.getFile().getName().replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile()); rafTemp = new RandomAccessFile(tempF, WRITE_MODE); raf = new RandomAccessFile(af.getFile(), WRITE_MODE); raf.seek(0); rafTemp.seek(0); throw new CannotWriteException("\"" + af.getFile().getAbsolutePath() + "\" :" + e, e); } finally { File result = af.getFile(); try { if (raf != null) { boolean deleteResult = af.getFile().delete(); if (deleteResult == false) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath())); boolean renameResult = tempF.renameTo(af.getFile()); if (renameResult == false) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath()));
if (!af.getFile().canWrite()) .getMsg(af.getFile().getPath())); if (af.getFile().length() <= MINIMUM_FILESIZE) .getMsg(af.getFile().getPath())); tempF = File.createTempFile(af.getFile().getName() .replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile() .getParentFile()); rafTemp = new RandomAccessFile(tempF, WRITE_MODE); raf = new RandomAccessFile(af.getFile(), WRITE_MODE); raf.seek(0); rafTemp.seek(0); throw new CannotWriteException("\"" + af.getFile().getAbsolutePath() + "\" :" + e, e); File result = af.getFile(); try boolean deleteResult = af.getFile().delete(); if (!deleteResult) .getMsg(af.getFile().getPath(), tempF .getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE .getMsg(af.getFile().getPath(), tempF .getPath()));
/** * Replace with new tag * * @param af The file we want to process * @throws CannotWriteException */ @Override public void write(AudioFile af) throws CannotWriteException { Path file = af.getFile().toPath(); if (TagOptionSingleton.getInstance().isCheckIsWritable() && !Files.isWritable(file)) { logger.severe(Permissions.displayPermissions(file)); logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile() .getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING .getMsg(file)); } if (af.getFile().length() <= MINIMUM_FILESIZE) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL .getMsg(file)); } writeTag(af.getTag(), file); }
/** * <p/> * Write the tag contained in the audioFile in the actual file on the disk. * </p> * * @param f The AudioFile to be written * @throws CannotWriteException If the file could not be written/accessed, the extension * wasn't recognized, or other IO error occurred. */ public void writeFile(AudioFile f) throws CannotWriteException { String ext = Utils.getExtension(f.getFile()); AudioFileWriter afw = writers.get(ext); if (afw == null) { throw new CannotWriteException(ErrorMessage.NO_WRITER_FOR_THIS_FORMAT.getMsg(ext)); } afw.write(f); } }
newFile = File.createTempFile(af.getFile().getName().replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile()); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_CREATE_TEMPORARY_FILE_IN_FOLDER.getMsg(af.getFile().getName(), af.getFile().getParentFile().getAbsolutePath())); raf = new RandomAccessFile(af.getFile(), WRITE_MODE); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(af.getFile().getAbsolutePath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE.getMsg(af.getFile(), e.getMessage())); } finally { try { result = af.getFile(); File originalFileBackup = new File(af.getFile().getParentFile().getPath(), AudioFile.getBaseFilename(af.getFile()) + ".old"); boolean renameResult = af.getFile().renameTo(originalFileBackup); if (renameResult == false) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_ORIGINAL_FILE_TO_BACKUP.getMsg(af.getFile().getPath(), originalFileBackup.getName())); renameResult = newFile.renameTo(af.getFile()); if (!renameResult) { if (!originalFileBackup.renameTo(af.getFile())) { throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getAbsolutePath(), newFile.getName())); } else {
/** * <p/> * Write the tag contained in the audioFile in the actual file on the disk. * </p> * * @param f The AudioFile to be written * @throws CannotWriteException If the file could not be written/accessed, the extension * wasn't recognized, or other IO error occurred. */ public void writeFile(AudioFile f) throws CannotWriteException { String ext = Utils.getExtension(f.getFile()); AudioFileWriter afw = writers.get(ext); if (afw == null) { throw new CannotWriteException(ErrorMessage.NO_WRITER_FOR_THIS_FORMAT.getMsg(ext)); } afw.write(f); } }
Path file = af.getFile().toPath(); if (TagOptionSingleton.getInstance().isCheckIsWritable() && !Files.isWritable(file)) if (af.getFile().length() <= MINIMUM_FILESIZE) tempF = File.createTempFile(af.getFile().getName().replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile()); rafTemp = new RandomAccessFile(tempF, WRITE_MODE); raf = new RandomAccessFile(af.getFile(), WRITE_MODE); raf.seek(0); rafTemp.seek(0); throw new CannotWriteException("\"" + af.getFile().getAbsolutePath() + "\" :" + e, e); File result = af.getFile(); try boolean deleteResult = af.getFile().delete(); if (!deleteResult) logger.warning(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_DELETE_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath())); boolean renameResult = tempF.renameTo(af.getFile()); if (!renameResult) logger.warning(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_RENAME_TO_ORIGINAL_FILE.getMsg(af.getFile().getPath(), tempF.getPath())); logger.severe("AudioFileWriter exception cleaning up delete:" + af.getFile().getPath() + " or" + tempF.getAbsolutePath() + ":" + ex);
logger.config("Started writing tag data for file:" + af.getFile().getName()); newFile = File.createTempFile(af.getFile().getName().replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile()); if (ioe.getMessage().equals(FILE_NAME_TOO_LONG) && (af.getFile().getName().length() > FILE_NAME_TOO_LONG_SAFE_LIMIT)) newFile = File.createTempFile(af.getFile().getName().substring(0, FILE_NAME_TOO_LONG_SAFE_LIMIT).replace('.', '_'), TEMP_FILENAME_SUFFIX, af.getFile().getParentFile()); logger.log(Level.SEVERE, ErrorMessage.GENERAL_WRITE_FAILED_TO_CREATE_TEMPORARY_FILE_IN_FOLDER.getMsg(af.getFile().getName(), af.getFile().getParentFile().getAbsolutePath()), ioe2); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_CREATE_TEMPORARY_FILE_IN_FOLDER.getMsg(af.getFile().getName(), af.getFile().getParentFile().getAbsolutePath())); logger.log(Level.SEVERE, ErrorMessage.GENERAL_WRITE_FAILED_TO_CREATE_TEMPORARY_FILE_IN_FOLDER.getMsg(af.getFile().getName(), af.getFile().getParentFile().getAbsolutePath()), ioe); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_CREATE_TEMPORARY_FILE_IN_FOLDER.getMsg(af.getFile().getName(), af.getFile().getParentFile().getAbsolutePath())); raf = new RandomAccessFile(af.getFile(), WRITE_MODE); logger.log(Level.SEVERE, ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(af.getFile().getAbsolutePath()), ioe); logger.log(Level.WARNING, ErrorMessage.GENERAL_WRITE_PROBLEM_CLOSING_FILE_HANDLE.getMsg(af.getFile(), ioe.getMessage()), ioe2); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(af.getFile().getAbsolutePath())); logger.log(Level.SEVERE, ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE.getMsg(af.getFile(), e.getMessage()), e); logger.log(Level.WARNING, ErrorMessage.GENERAL_WRITE_PROBLEM_CLOSING_FILE_HANDLE.getMsg(af.getFile().getAbsolutePath(), ioe.getMessage()), ioe); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE.getMsg(af.getFile(), e.getMessage())); logger.log(Level.WARNING, ErrorMessage.GENERAL_WRITE_PROBLEM_CLOSING_FILE_HANDLE.getMsg(af.getFile().getAbsolutePath(), ioe.getMessage()), ioe);
/** * <p/> * Delete the tag, if any, contained in the given file. * </p> * * @param f The file where the tag will be deleted * @throws CannotWriteException If the file could not be written/accessed, the extension * wasn't recognized, or other IO error occurred. * @throws org.jaudiotagger.audio.exceptions.CannotReadException * */ public void deleteTag(AudioFile f) throws CannotReadException, CannotWriteException { String ext = Utils.getExtension(f.getFile()); Object afw = writers.get(ext); if (afw == null) { throw new CannotWriteException(ErrorMessage.NO_DELETER_FOR_THIS_FORMAT.getMsg(ext)); } ((AudioFileWriter) afw).delete(f); }
/** * * Delete the tag, if any, contained in the given file. * * * @param f The file where the tag will be deleted * @throws org.jaudiotagger.audio.exceptions.CannotWriteException If the file could not be written/accessed, the extension * wasn't recognized, or other IO error occurred. * @throws org.jaudiotagger.audio.exceptions.CannotReadException */ public void deleteTag(AudioFile f) throws CannotReadException, CannotWriteException { String ext = Utils.getExtension(f.getFile()); Object afw = writers.get(ext); if (afw == null) { throw new CannotWriteException(ErrorMessage.NO_DELETER_FOR_THIS_FORMAT.getMsg(ext)); } ((AudioFileWriter) afw).delete(f); }
/** * <p/> * Delete the tag, if any, contained in the given file. * </p> * * @param f The file where the tag will be deleted * @throws CannotWriteException If the file could not be written/accessed, the extension * wasn't recognized, or other IO error occurred. * @throws org.jaudiotagger.audio.exceptions.CannotReadException */ public void deleteTag(AudioFile f) throws CannotReadException, CannotWriteException { String ext = Utils.getExtension(f.getFile()); Object afw = writers.get(ext); if (afw == null) { throw new CannotWriteException(ErrorMessage.NO_DELETER_FOR_THIS_FORMAT.getMsg(ext)); } ((AudioFileWriter) afw).delete(f); }
throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); Path file = af.getFile().toPath(); if (TagOptionSingleton.getInstance().isCheckIsWritable() && !Files.isWritable(file)) logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath())); throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(file)); if (af.getFile().length() <= MINIMUM_FILESIZE)
try Utils.copyThrowsOnException(f.getFile(), destination); f.setFile(destination); } catch (IOException e) {
/** * Delete the tag (if any) present in the given file * * @param af The file to process * * @throws CannotWriteException if anything went wrong * @throws org.jaudiotagger.audio.exceptions.CannotReadException */ @Override public void delete(AudioFile af) throws CannotReadException, CannotWriteException { Path file = af.getFile().toPath(); if (TagOptionSingleton.getInstance().isCheckIsWritable() && !Files.isWritable(file)) { logger.severe(Permissions.displayPermissions(file)); throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED .getMsg(file)); } if (af.getFile().length() <= MINIMUM_FILESIZE) { throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED_BECAUSE_FILE_IS_TOO_SMALL .getMsg(file)); } deleteTag(af.getTag(), file); }