org.jaudiotagger.tag.id3
Class ID3v1Tag

java.lang.Object
  extended by org.jaudiotagger.tag.id3.AbstractTagItem
      extended by org.jaudiotagger.tag.id3.AbstractTag
          extended by org.jaudiotagger.tag.id3.AbstractID3Tag
              extended by org.jaudiotagger.tag.id3.AbstractID3v1Tag
                  extended by org.jaudiotagger.tag.id3.ID3v1Tag
All Implemented Interfaces:
Tag
Direct Known Subclasses:
ID3v11Tag

public class ID3v1Tag
extends AbstractID3v1Tag
implements Tag

Represents an ID3v1 tag.

Author:
: Eric Farng, : Paul Taylor

Field Summary
protected  java.lang.String album
           
protected  java.lang.String artist
           
protected static int BYTE_TO_UNSIGNED
           
protected  java.lang.String comment
           
protected static int FIELD_COMMENT_LENGTH
           
protected static int FIELD_COMMENT_POS
           
protected  byte genre
           
protected static int GENRE_UNDEFINED
           
private static byte MAJOR_VERSION
           
private static byte RELEASE
           
private static byte REVISION
           
(package private) static java.util.EnumMap<FieldKey,ID3v1FieldKey> tagFieldToID3v1Field
           
protected  java.lang.String title
           
protected static java.lang.String TYPE_COMMENT
           
protected  java.lang.String year
           
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractID3v1Tag
END_OF_FIELD, endofStringPattern, FIELD_ALBUM_LENGTH, FIELD_ALBUM_POS, FIELD_ARTIST_LENGTH, FIELD_ARTIST_POS, FIELD_GENRE_LENGTH, FIELD_GENRE_POS, FIELD_TAGID_LENGTH, FIELD_TAGID_POS, FIELD_TITLE_LENGTH, FIELD_TITLE_POS, FIELD_YEAR_LENGTH, FIELD_YEAR_POS, logger, TAG_DATA_LENGTH, TAG_ID, TAG_LENGTH, TYPE_ALBUM, TYPE_ARTIST, TYPE_GENRE, TYPE_TITLE, TYPE_YEAR
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractID3Tag
TAG_RELEASE
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractTag
TYPE_TAG
 
Constructor Summary
ID3v1Tag()
          Creates a new ID3v1 datatype.
ID3v1Tag(AbstractTag mp3tag)
           
ID3v1Tag(ID3v1Tag copyObject)
           
ID3v1Tag(java.io.RandomAccessFile file)
          Deprecated. use ID3v1Tag(RandomAccessFile,String) instead
ID3v1Tag(java.io.RandomAccessFile file, java.lang.String loggingFilename)
          Creates a new ID3v1 datatype.
 
Method Summary
 void addField(Artwork artwork)
          Create artwork field based on the data in artwork and then add it to the tag itself

 void addField(FieldKey genericKey, java.lang.String value)
          Create the field based on the generic key and add it to the tag This is handled differently by different formats
 void addField(TagField field)
          Adds a field to the structure, used internally by the library

 TagField createField(Artwork artwork)
          Create artwork field based on the data in artwork
 TagField createField(FieldKey genericKey, java.lang.String value)
          Create Tag Field using generic key
 void createStructure()
          Create structured representation of this item.
 void deleteArtworkField()
          Delete all instance of artwork Field
 void deleteField(FieldKey genericKey)
          Delete any instance of tag fields with this key
 void deleteField(java.lang.String id)
          Delete any fields with this Flac (Vorbis Comment) id
 boolean equals(java.lang.Object obj)
          Determines whether another datatype is equal to this tag.
 java.util.List<TagField> getAlbum()
           
 java.util.List<TagField> getArtist()
           
 java.util.List<Artwork> getArtworkList()
           
 java.util.List<TagField> getComment()
           
 java.lang.String getEncoding()
           
 int getFieldCount()
          Return the number of fields

 int getFieldCountIncludingSubValues()
          Return the number of fields taking multiple value fields into consideration Fields that actually contain multiple values are counted seperately i.e.
 java.util.Iterator<TagField> getFields()
          Iterator over all the fields within the tag, handle multiple fields with the same id
 java.util.List<TagField> getFields(FieldKey genericKey)
          Returns a list of TagField objects whose "id" is the specified one.
 java.util.List<TagField> getFields(java.lang.String id)
          Returns a list of TagField objects whose "id" is the specified one.
 java.lang.String getFirst(FieldKey genericKey)
          Retrieve the first value that exists for this generic key
 java.lang.String getFirst(java.lang.String genericKey)
          Retrieve the first value that exists for this key id
protected  java.lang.String getFirstAlbum()
          Get Album
protected  java.lang.String getFirstArtist()
          Get Artist
 Artwork getFirstArtwork()
           
 java.lang.String getFirstComment()
          Get Comment
 TagField getFirstField(FieldKey genericKey)
           
 TagField getFirstField(java.lang.String id)
          Retrieve the first field that exists for this format specific key

 java.lang.String getFirstGenre()
          Get Genre
 java.lang.String getFirstTitle()
          Get title
 java.lang.String getFirstTrack()
           
 java.lang.String getFirstYear()
          Get year
 java.util.List<TagField> getGenre()
          Get Genre field

 byte getMajorVersion()
          Retrieve the Major Version
 byte getRelease()
          Retrieve the Release
 byte getRevision()
          Retrieve the Revision
 java.lang.String getSubValue(FieldKey id, int n, int m)
          The m parameter is effectively ignored
 java.util.List<TagField> getTitle()
          Get title field

 java.util.List<TagField> getTrack()
           
 java.lang.String getValue(FieldKey genericKey, int index)
          Retrieve String value of the nth tag field that exists for this generic key
 java.util.List<TagField> getYear()
          Get year field

 boolean hasCommonFields()
          Returns true, if at least one of the contained fields is a common field (TagField.isCommon()).
 boolean hasField(java.lang.String id)
          Determines whether the tag has at least one field with the specified "id".
 boolean isEmpty()
          Determines whether the tag has no fields specified.
 java.util.Iterator iterator()
           
 void read(java.nio.ByteBuffer byteBuffer)
           
protected  java.util.List<TagField> returnFieldToList(ID3v1TagField field)
           
 boolean seek(java.nio.ByteBuffer byteBuffer)
          Does a tag of this version exist within the byteBuffer
 void setAlbum(java.lang.String album)
          Set Album
 void setArtist(java.lang.String artist)
          Set Artist
 void setComment(java.lang.String comment)
          Set Comment
 boolean setEncoding(java.lang.String encoding)
           
 void setField(Artwork artwork)
          Create artwork field based on the data in artwork and then set it in the tag itself

 void setField(FieldKey genericKey, java.lang.String value)
          Create the field based on the generic key and set it in the tag
 void setField(TagField field)
          Sets a field in the structure, used internally by the library

 void setGenre(java.lang.String genreVal)
          Sets the genreID,

 void setTitle(java.lang.String title)
          Set Title
 void setYear(java.lang.String year)
          Set year
 void write(java.io.RandomAccessFile file)
          Write this tag to the file, replacing any tag previously existing
 
Methods inherited from class org.jaudiotagger.tag.id3.AbstractID3v1Tag
delete, getSize, seekForV1OrV11Tag
 
Methods inherited from class org.jaudiotagger.tag.id3.AbstractID3Tag
getIdentifier, getLoggingFilename, setLoggingFilename, toString
 
Methods inherited from class org.jaudiotagger.tag.id3.AbstractTagItem
isSubsetOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.tag.Tag
toString
 

Field Detail

tagFieldToID3v1Field

static java.util.EnumMap<FieldKey,ID3v1FieldKey> tagFieldToID3v1Field

TYPE_COMMENT

protected static final java.lang.String TYPE_COMMENT
See Also:
Constant Field Values

FIELD_COMMENT_LENGTH

protected static final int FIELD_COMMENT_LENGTH
See Also:
Constant Field Values

FIELD_COMMENT_POS

protected static final int FIELD_COMMENT_POS
See Also:
Constant Field Values

BYTE_TO_UNSIGNED

protected static final int BYTE_TO_UNSIGNED
See Also:
Constant Field Values

GENRE_UNDEFINED

protected static final int GENRE_UNDEFINED
See Also:
Constant Field Values

album

protected java.lang.String album

artist

protected java.lang.String artist

comment

protected java.lang.String comment

title

protected java.lang.String title

year

protected java.lang.String year

genre

protected byte genre

RELEASE

private static final byte RELEASE
See Also:
Constant Field Values

MAJOR_VERSION

private static final byte MAJOR_VERSION
See Also:
Constant Field Values

REVISION

private static final byte REVISION
See Also:
Constant Field Values
Constructor Detail

ID3v1Tag

public ID3v1Tag()
Creates a new ID3v1 datatype.


ID3v1Tag

public ID3v1Tag(ID3v1Tag copyObject)

ID3v1Tag

public ID3v1Tag(AbstractTag mp3tag)

ID3v1Tag

public ID3v1Tag(java.io.RandomAccessFile file,
                java.lang.String loggingFilename)
         throws TagNotFoundException,
                java.io.IOException
Creates a new ID3v1 datatype.

Parameters:
file -
loggingFilename -
Throws:
TagNotFoundException
java.io.IOException

ID3v1Tag

public ID3v1Tag(java.io.RandomAccessFile file)
         throws TagNotFoundException,
                java.io.IOException
Deprecated. use ID3v1Tag(RandomAccessFile,String) instead

Creates a new ID3v1 datatype.

Parameters:
file -
Throws:
TagNotFoundException
java.io.IOException
Method Detail

getRelease

public byte getRelease()
Retrieve the Release

Specified by:
getRelease in class AbstractID3Tag
Returns:

getMajorVersion

public byte getMajorVersion()
Retrieve the Major Version

Specified by:
getMajorVersion in class AbstractID3Tag
Returns:

getRevision

public byte getRevision()
Retrieve the Revision

Specified by:
getRevision in class AbstractID3Tag
Returns:

addField

public void addField(TagField field)
Description copied from interface: Tag
Adds a field to the structure, used internally by the library

Specified by:
addField in interface Tag
Parameters:
field - The field to add.

getFields

public java.util.List<TagField> getFields(java.lang.String id)
Description copied from interface: Tag
Returns a list of TagField objects whose "id" is the specified one.

Can be used to retrieve fields with any identifier, useful if the identifier is not within FieldKey

Specified by:
getFields in interface Tag
Parameters:
id - The field id.
Returns:
A list of TagField objects with the given "id".

getFieldCount

public int getFieldCount()
Description copied from interface: Tag
Return the number of fields

Fields with the same identifiers are counted separately i.e two TITLE fields in a Vorbis Comment file would count as two

Specified by:
getFieldCount in interface Tag
Returns:
total number of fields

getFieldCountIncludingSubValues

public int getFieldCountIncludingSubValues()
Description copied from interface: Tag
Return the number of fields taking multiple value fields into consideration Fields that actually contain multiple values are counted seperately i.e. a TCON frame in ID3v24 frame containing multiple genres would add to count for each genre.

Specified by:
getFieldCountIncludingSubValues in interface Tag
Returns:
total number of fields taking multiple value fields into consideration

returnFieldToList

protected java.util.List<TagField> returnFieldToList(ID3v1TagField field)

setAlbum

public void setAlbum(java.lang.String album)
Set Album

Parameters:
album -

getFirstAlbum

protected java.lang.String getFirstAlbum()
Get Album

Returns:
album

getAlbum

public java.util.List<TagField> getAlbum()
Returns:
album within list or empty if does not exist

setArtist

public void setArtist(java.lang.String artist)
Set Artist

Parameters:
artist -

getFirstArtist

protected java.lang.String getFirstArtist()
Get Artist

Returns:
artist

getArtist

public java.util.List<TagField> getArtist()
Returns:
Artist within list or empty if does not exist

setComment

public void setComment(java.lang.String comment)
Set Comment

Parameters:
comment -
Throws:
java.lang.IllegalArgumentException - if comment null

getComment

public java.util.List<TagField> getComment()
Returns:
comment within list or empty if does not exist

getFirstComment

public java.lang.String getFirstComment()
Get Comment

Returns:
comment

setGenre

public void setGenre(java.lang.String genreVal)
Sets the genreID,

ID3v1 only supports genres defined in a predefined list so if unable to find value in list set 255, which seems to be the value winamp uses for undefined.

Parameters:
genreVal -

getFirstGenre

public java.lang.String getFirstGenre()
Get Genre

Returns:
genre or empty string if not valid

getGenre

public java.util.List<TagField> getGenre()
Get Genre field

Only a single genre is available in ID3v1

Returns:

setTitle

public void setTitle(java.lang.String title)
Set Title

Parameters:
title -

getFirstTitle

public java.lang.String getFirstTitle()
Get title

Returns:
Title

getTitle

public java.util.List<TagField> getTitle()
Get title field

Only a single title is available in ID3v1

Returns:

setYear

public void setYear(java.lang.String year)
Set year

Parameters:
year -

getFirstYear

public java.lang.String getFirstYear()
Get year

Returns:
year

getYear

public java.util.List<TagField> getYear()
Get year field

Only a single year is available in ID3v1

Returns:

getFirstTrack

public java.lang.String getFirstTrack()

getTrack

public java.util.List<TagField> getTrack()

getFirstField

public TagField getFirstField(java.lang.String id)
Description copied from interface: Tag
Retrieve the first field that exists for this format specific key

Can be used to retrieve fields with any identifier, useful if the identifier is not within FieldKey

Specified by:
getFirstField in interface Tag
Parameters:
id - audio specific key
Returns:
tag field or null if doesn't exist

getFields

public java.util.Iterator<TagField> getFields()
Description copied from interface: Tag
Iterator over all the fields within the tag, handle multiple fields with the same id

Specified by:
getFields in interface Tag
Returns:
iterator over whole list

hasCommonFields

public boolean hasCommonFields()
Description copied from interface: Tag
Returns true, if at least one of the contained fields is a common field (TagField.isCommon()).

Specified by:
hasCommonFields in interface Tag
Returns:
true if a common field is present.

hasField

public boolean hasField(java.lang.String id)
Description copied from interface: Tag
Determines whether the tag has at least one field with the specified "id".

Specified by:
hasField in interface Tag
Parameters:
id - The field id to look for.
Returns:
true if tag contains a TagField with the given id.

isEmpty

public boolean isEmpty()
Description copied from interface: Tag
Determines whether the tag has no fields specified.

Specified by:
isEmpty in interface Tag
Returns:
true if tag contains no field.

setField

public void setField(FieldKey genericKey,
                     java.lang.String value)
              throws KeyNotFoundException,
                     FieldDataInvalidException
Description copied from interface: Tag
Create the field based on the generic key and set it in the tag

Specified by:
setField in interface Tag
Throws:
KeyNotFoundException
FieldDataInvalidException

addField

public void addField(FieldKey genericKey,
                     java.lang.String value)
              throws KeyNotFoundException,
                     FieldDataInvalidException
Description copied from interface: Tag
Create the field based on the generic key and add it to the tag This is handled differently by different formats

Specified by:
addField in interface Tag
Throws:
KeyNotFoundException
FieldDataInvalidException

setField

public void setField(TagField field)
Description copied from interface: Tag
Sets a field in the structure, used internally by the library

Specified by:
setField in interface Tag
Parameters:
field - The field to add.

setEncoding

public boolean setEncoding(java.lang.String encoding)
Specified by:
setEncoding in interface Tag
Parameters:
encoding -
Returns:

createField

public TagField createField(FieldKey genericKey,
                            java.lang.String value)
Create Tag Field using generic key

Specified by:
createField in interface Tag
Parameters:
genericKey - is the generic key
value - to store
Returns:

getEncoding

public java.lang.String getEncoding()

getFirstField

public TagField getFirstField(FieldKey genericKey)
Specified by:
getFirstField in interface Tag
Returns:
the first field that matches this generic key

getFields

public java.util.List<TagField> getFields(FieldKey genericKey)
Returns a list of TagField objects whose "id" is the specified one.

Specified by:
getFields in interface Tag
Parameters:
genericKey - The generic field key
Returns:
A list of TagField objects with the given "id".

getFirst

public java.lang.String getFirst(java.lang.String genericKey)
Retrieve the first value that exists for this key id

Specified by:
getFirst in interface Tag
Parameters:
genericKey -
Returns:

getFirst

public java.lang.String getFirst(FieldKey genericKey)
Retrieve the first value that exists for this generic key

Specified by:
getFirst in interface Tag
Parameters:
genericKey -
Returns:

getSubValue

public java.lang.String getSubValue(FieldKey id,
                                    int n,
                                    int m)
The m parameter is effectively ignored

Specified by:
getSubValue in interface Tag
Parameters:
id -
n -
m -
Returns:

getValue

public java.lang.String getValue(FieldKey genericKey,
                                 int index)
Description copied from interface: Tag
Retrieve String value of the nth tag field that exists for this generic key

Specified by:
getValue in interface Tag
Returns:

deleteField

public void deleteField(FieldKey genericKey)
Delete any instance of tag fields with this key

Specified by:
deleteField in interface Tag
Parameters:
genericKey -

deleteField

public void deleteField(java.lang.String id)
Description copied from interface: Tag
Delete any fields with this Flac (Vorbis Comment) id

Specified by:
deleteField in interface Tag

equals

public boolean equals(java.lang.Object obj)
Description copied from class: AbstractTag
Determines whether another datatype is equal to this tag. It just compares if they are the same class, then calls super.equals(obj).

Overrides:
equals in class AbstractTag
Parameters:
obj -
Returns:
true if this and obj are equivalent

iterator

public java.util.Iterator iterator()
Specified by:
iterator in class AbstractTag
Returns:
an iterator to iterate through the fields of the tag

read

public void read(java.nio.ByteBuffer byteBuffer)
          throws TagNotFoundException
Specified by:
read in class AbstractTagItem
Parameters:
byteBuffer -
Throws:
TagNotFoundException

seek

public boolean seek(java.nio.ByteBuffer byteBuffer)
Does a tag of this version exist within the byteBuffer

Specified by:
seek in class AbstractTag
Returns:
whether tag exists within the byteBuffer

write

public void write(java.io.RandomAccessFile file)
           throws java.io.IOException
Write this tag to the file, replacing any tag previously existing

Specified by:
write in class AbstractTag
Parameters:
file -
Throws:
java.io.IOException

createStructure

public void createStructure()
Create structured representation of this item.


getArtworkList

public java.util.List<Artwork> getArtworkList()
Specified by:
getArtworkList in interface Tag
Returns:
a list of all artwork in this file using the format indepedent Artwork class

getFirstArtwork

public Artwork getFirstArtwork()
Specified by:
getFirstArtwork in interface Tag
Returns:
first artwork or null if none exist

createField

public TagField createField(Artwork artwork)
                     throws FieldDataInvalidException
Description copied from interface: Tag
Create artwork field based on the data in artwork

Specified by:
createField in interface Tag
Returns:
suitable tagfield for this format that represents the artwork data
Throws:
FieldDataInvalidException

setField

public void setField(Artwork artwork)
              throws FieldDataInvalidException
Description copied from interface: Tag
Create artwork field based on the data in artwork and then set it in the tag itself

Specified by:
setField in interface Tag
Throws:
FieldDataInvalidException

addField

public void addField(Artwork artwork)
              throws FieldDataInvalidException
Description copied from interface: Tag
Create artwork field based on the data in artwork and then add it to the tag itself

Specified by:
addField in interface Tag
Throws:
FieldDataInvalidException

deleteArtworkField

public void deleteArtworkField()
                        throws KeyNotFoundException
Delete all instance of artwork Field

Specified by:
deleteArtworkField in interface Tag
Throws:
KeyNotFoundException


Copyright © 2005-2010 java.net. All Rights Reserved.