Mp3dings 
20100427

helliker.id3
Class ID3v1Tag

java.lang.Object
  extended by helliker.id3.ID3v1Tag
All Implemented Interfaces:
ID3Tag

public class ID3v1Tag
extends Object
implements ID3Tag

This class reads and writes id3v1.1 tags from/to files.


Constructor Summary
ID3v1Tag(File mp3)
          Create an id3v1tag from the file specified.
 
Method Summary
 void copyFrom(ID3Tag tag)
          Copies information from the ID3Tag parameter and inserts it into this tag.
 String getAlbum()
          Return the album field of the tag
 String getArtist()
          Return the artist field of the tag
 byte[] getBytes()
          Returns a binary representation of this id3v1 tag.
 String getComment()
          Return the comment field of the tag
 int getGenre()
          Return the genre field of the tag, -1 if tag doesn't exist
 String getGenreString()
          Return the genre name based on the ID3/Nullsoft standards.
 int getSize()
          Return the size in bytes of the tag.
 String getTitle()
          Return the title field of the tag
 int getTrack()
          Return the track field of the tag.
 String getYear()
          Return the year field of the tag
 void removeTag()
          Removes the id3v1 tag from the file specified in the constructor
 void removeTag(boolean b)
          Removes the id3v1 tag from the file specified in the constructor
 void setAlbum(String newAlbum)
          Set the album field of the tag.
 void setArtist(String newArtist)
          Set the artist field of the tag.
 void setComment(String newComment)
          Set the comment field of the tag.
 void setGenre(int newGenre)
          Set the genre field of the tag.
 boolean setGenreString(String str)
          Attempt to set the genre value of this tag from the string specified.
 void setTitle(String newTitle)
          Set the title field of the tag.
 void setTrack(int newTrack)
          Set the track field of the tag.
 void setYear(String newYear)
          Set the year field of the tag.
 boolean tagExists()
          Checks if a tag exists
 String toString()
          Returns a String representation of this object.
 void writeTag()
          Writes the information in this tag to the file specified in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ID3v1Tag

public ID3v1Tag(File mp3)
         throws IOException
Create an id3v1tag from the file specified. If the file contains a tag, the information is automatically extracted. Supports only id3v1.1 directly but id3v1.0 tags will most likely work correctly too.

Parameters:
mp3 - the file to read/write the tag to
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs
Method Detail

writeTag

public void writeTag()
              throws IOException
Writes the information in this tag to the file specified in the constructor. If a tag does not exist, one will be created. If a tag already exists, it will be overwritten.

Specified by:
writeTag in interface ID3Tag
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

getBytes

public byte[] getBytes()
Returns a binary representation of this id3v1 tag. It is in the correct format according to the id3v1.1 specifications.

Returns:
a binary representation of this id3v1 tag

removeTag

public void removeTag()
               throws IOException
Removes the id3v1 tag from the file specified in the constructor

Specified by:
removeTag in interface ID3Tag
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

removeTag

public void removeTag(boolean b)
               throws IOException
Removes the id3v1 tag from the file specified in the constructor

Specified by:
removeTag in interface ID3Tag
Parameters:
b - ignored
Throws:
FileNotFoundException - if an error occurs
IOException - if an error occurs

getGenreString

public String getGenreString()
Return the genre name based on the ID3/Nullsoft standards. If the genre value is not valid, an empty String is returned.

Returns:
return the genre name or null if the genre value is not valid

setGenreString

public boolean setGenreString(String str)
Attempt to set the genre value of this tag from the string specified. The value returned is based on the ID3/Nullsoft standards. Returns true if a match is found in the table and false otherwise.

Parameters:
str - the string value of the genre to attempt to set
Returns:
true if a match is found, false otherwise

tagExists

public boolean tagExists()
Checks if a tag exists

Returns:
true if a tag exists

getTitle

public String getTitle()
Return the title field of the tag

Returns:
the title field of the tag

setTitle

public void setTitle(String newTitle)
Set the title field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newTitle - the title for the tag

getArtist

public String getArtist()
Return the artist field of the tag

Returns:
the artist field of the tag

setArtist

public void setArtist(String newArtist)
Set the artist field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newArtist - the artist for the tag

getAlbum

public String getAlbum()
Return the album field of the tag

Returns:
the album field of the tag

setAlbum

public void setAlbum(String newAlbum)
Set the album field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newAlbum - the album for the tag

getYear

public String getYear()
Return the year field of the tag

Returns:
the year field of the tag

setYear

public void setYear(String newYear)
Set the year field of the tag. The maximum size of the String is 4. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newYear - the year for the tag

getComment

public String getComment()
Return the comment field of the tag

Returns:
the comment field of the tag

setComment

public void setComment(String newComment)
Set the comment field of the tag. The maximum size of the String is 30. If the size exceeds the maximum size, the String will be truncated.

Parameters:
newComment - the comment of the tag

getTrack

public int getTrack()
Return the track field of the tag. This method will return 0 if the track byte is either 0x00 or 0xFF.

Returns:
an integer between 0 and 254 (inclusive)

setTrack

public void setTrack(int newTrack)
Set the track field of the tag. The track number has to be between 0 and 255. If it is not, nothing will happen.

Parameters:
newTrack - the track of the tag

getGenre

public int getGenre()
Return the genre field of the tag, -1 if tag doesn't exist

Returns:
the genre field of the tag

setGenre

public void setGenre(int newGenre)
              throws ID3FieldDataException
Set the genre field of the tag. This probably should not be greater than 115, but supports values from 0-255.

Parameters:
newGenre - the genre of the tag
Throws:
ID3FieldDataException - if the value supplie is invalid

getSize

public int getSize()
Return the size in bytes of the tag. This returns 128 if the tag exists and 0 otherwise.

Returns:
the size of the tag in bytes

toString

public String toString()
Returns a String representation of this object. Contains all information within the tag.

Overrides:
toString in class Object
Returns:
a String representation of this object

copyFrom

public void copyFrom(ID3Tag tag)
Copies information from the ID3Tag parameter and inserts it into this tag. Previous data will be overwritten. [NOT IMPLEMENTED]

Specified by:
copyFrom in interface ID3Tag
Parameters:
tag - the tag to copy from

Mp3dings 
20100427