/** * Write this tag to the file, replacing any tag previously existing * * @param file * @throws IOException */ public void write(RandomAccessFile file) throws IOException { logger.config("Saving ID3v1 tag to file"); byte[] buffer = new byte[TAG_LENGTH]; int i; String str; delete(file); file.seek(file.length()); // Copy the TAGID into new buffer System.arraycopy(TAG_ID, FIELD_TAGID_POS, buffer, FIELD_TAGID_POS, TAG_ID.length); int offset = FIELD_TITLE_POS; if (TagOptionSingleton.getInstance().isId3v1SaveTitle()) { str = ID3Tags.truncate(title, FIELD_TITLE_LENGTH); for (i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } } offset = FIELD_ARTIST_POS; if (TagOptionSingleton.getInstance().isId3v1SaveArtist()) { str = ID3Tags.truncate(artist, FIELD_ARTIST_LENGTH); for (i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } } offset = FIELD_ALBUM_POS; if (TagOptionSingleton.getInstance().isId3v1SaveAlbum()) { str = ID3Tags.truncate(album, FIELD_ALBUM_LENGTH); for (i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } } offset = FIELD_YEAR_POS; if (TagOptionSingleton.getInstance().isId3v1SaveYear()) { str = ID3Tags.truncate(year, AbstractID3v1Tag.FIELD_YEAR_LENGTH); for (i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } } offset = FIELD_COMMENT_POS; if (TagOptionSingleton.getInstance().isId3v1SaveComment()) { str = ID3Tags.truncate(comment, FIELD_COMMENT_LENGTH); for (i = 0; i < str.length(); i++) { buffer[i + offset] = (byte) str.charAt(i); } } offset = FIELD_GENRE_POS; if (TagOptionSingleton.getInstance().isId3v1SaveGenre()) { buffer[offset] = genre; } file.write(buffer); logger.config("Saved ID3v1 tag to file"); }
/** * Set year * * @param year */ public void setYear(String year) { this.year = ID3Tags.truncate(year, FIELD_YEAR_LENGTH); }
/** * Set Title * * @param title */ public void setTitle(String title) { if (title == null) { throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg()); } this.title = ID3Tags.truncate(title, FIELD_TITLE_LENGTH); }
/** * Set Comment * * @param comment * @throws IllegalArgumentException if comment null */ public void setComment(String comment) { if (comment == null) { throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg()); } this.comment = ID3Tags.truncate(comment, FIELD_COMMENT_LENGTH); }
/** * Set Artist * * @param artist */ public void setArtist(String artist) { if (artist == null) { throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg()); } this.artist = ID3Tags.truncate(artist, FIELD_ARTIST_LENGTH); }
/** * Set Album * * @param album */ public void setAlbum(String album) { if (album == null) { throw new IllegalArgumentException(ErrorMessage.GENERAL_INVALID_NULL_ARGUMENT.getMsg()); } this.album = ID3Tags.truncate(album, FIELD_ALBUM_LENGTH); }