示例#1
0
 /**
  * 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");
 }
示例#2
0
 /**
  * Set year
  *
  * @param year
  */
 public void setYear(String year) {
   this.year = ID3Tags.truncate(year, FIELD_YEAR_LENGTH);
 }
示例#3
0
 /**
  * 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);
 }
示例#4
0
 /**
  * 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);
 }
示例#5
0
 /**
  * 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);
 }
示例#6
0
 /**
  * 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);
 }