org.jaudiotagger.tag.id3
Class ID3v22Tag

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.AbstractID3v2Tag
                  extended by org.jaudiotagger.tag.id3.ID3v22Tag
All Implemented Interfaces:
Tag

public class ID3v22Tag
extends AbstractID3v2Tag

Represents an ID3v2.2 tag.

Version:
$Id: ID3v22Tag.java,v 1.50 2009/11/12 15:42:57 paultaylor Exp $
Author:
: Paul Taylor, : Eric Farng

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jaudiotagger.tag.id3.AbstractID3v2Tag
AbstractID3v2Tag.FrameAndSubId
 
Field Summary
protected  boolean compression
          The tag is compressed, although no compression scheme is defined in ID3v22
static byte MAJOR_VERSION
           
static int MASK_V22_COMPRESSION
          Bit mask to indicate tag is compressed, although compression is not actually defined in v22 so just ignored
static int MASK_V22_UNSYNCHRONIZATION
          Bit mask to indicate tag is Unsychronization
static byte RELEASE
           
static byte REVISION
           
protected static java.lang.String TYPE_COMPRESSION
           
protected static java.lang.String TYPE_UNSYNCHRONISATION
           
protected  boolean unsynchronization
          If set all frames in the tag uses unsynchronisation
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractID3v2Tag
duplicateBytes, duplicateFrameId, emptyFrameBytes, FIELD_TAG_FLAG_LENGTH, FIELD_TAG_FLAG_POS, FIELD_TAG_MAJOR_VERSION_LENGTH, FIELD_TAG_MAJOR_VERSION_POS, FIELD_TAG_MINOR_VERSION_LENGTH, FIELD_TAG_MINOR_VERSION_POS, FIELD_TAG_SIZE_LENGTH, FIELD_TAG_SIZE_POS, FIELD_TAGID_LENGTH, FIELD_TAGID_POS, fileReadSize, frameMap, invalidFrameBytes, TAG_HEADER_LENGTH, TAG_ID, TAG_SIZE_INCREMENT, TYPE_BODY, TYPE_DUPLICATEBYTES, TYPE_DUPLICATEFRAMEID, TYPE_EMPTYFRAMEBYTES, TYPE_FILEREADSIZE, TYPE_HEADER, TYPE_INVALIDFRAMEBYTES
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractID3Tag
logger, TAG_RELEASE
 
Fields inherited from class org.jaudiotagger.tag.id3.AbstractTag
TYPE_TAG
 
Constructor Summary
ID3v22Tag()
          Creates a new empty ID3v2_2 tag.
ID3v22Tag(AbstractTag mp3tag)
          Constructs a new tag based upon another tag of different version/type
ID3v22Tag(java.nio.ByteBuffer buffer)
          Deprecated. use ID3v22Tag(ByteBuffer,String) instead
ID3v22Tag(java.nio.ByteBuffer buffer, java.lang.String loggingFilename)
          Creates a new ID3v2_2 datatype.
ID3v22Tag(ID3v22Tag copyObject)
          Copy Constructor, creates a new ID3v2_2 Tag based on another ID3v2_2 Tag
 
Method Summary
protected  void addFrame(AbstractID3v2Frame frame)
           
protected  void copyPrimitives(AbstractID3v2Tag copyObj)
          Copy primitives applicable to v2.2
 TagField createArtworkField(byte[] data, java.lang.String mimeType)
           
 TagField createField(Artwork artwork)
          Create artwork field based on the data in artwork
 ID3v22Frame createFrame(java.lang.String id)
          Create Frame
 void createStructure()
           
 TagField createTagField(ID3v22FieldKey id3Key, java.lang.String value)
          Create Frame for Id3 Key

Only textual data supported at the moment, should only be used with frames that support a simple string argument.

 void deleteTagField(ID3v22FieldKey id3v22FieldKey)
          Delete fields with this id3v22FieldKey
 boolean equals(java.lang.Object obj)
          Is this tag equivalent to another
protected  java.lang.String getAlbumId()
           
protected  java.lang.String getArtistId()
           
 java.util.List<Artwork> getArtworkList()
          
protected  java.lang.String getCommentId()
           
 java.lang.String getFirst(ID3v22FieldKey id3v22FieldKey)
          Retrieve the first value that exists for this id3v22key
protected  AbstractID3v2Tag.FrameAndSubId getFrameAndSubIdFromGenericKey(FieldKey genericKey)
           
protected  java.lang.String getGenreId()
           
protected  ID3Frames getID3Frames()
           
 java.lang.String getIdentifier()
          Get full version
 byte getMajorVersion()
          Retrieve the Major Version
 java.util.Comparator getPreferredFrameOrderComparator()
           
 byte getRelease()
          Retrieve the Release
 byte getRevision()
          Retrieve the Revision
 int getSize()
          Return frame size based upon the sizes of the frames rather than the size including padding recorded in the tag header
protected  java.lang.String getTitleId()
           
protected  java.lang.String getTrackId()
           
protected  java.lang.String getYearId()
           
 boolean isCompression()
           
 boolean isUnsynchronization()
           
 void read(java.nio.ByteBuffer byteBuffer)
          
protected  void readFrames(java.nio.ByteBuffer byteBuffer, int size)
          Read frames from tag
private  void readHeaderFlags(java.nio.ByteBuffer byteBuffer)
          Read tag Header Flags
 int readSize(java.nio.ByteBuffer buffer)
          Read the size of a tag, based on the value written in the tag header
protected  void translateFrame(AbstractID3v2Frame frame)
          This is used when we need to translate a single frame into multiple frames, currently required for TDRC frames.
 void write(java.io.File file, long audioStartLocation)
          Write tag to file.
 void write(java.nio.channels.WritableByteChannel channel)
          Write tag to channel.
private  java.nio.ByteBuffer writeHeaderToBuffer(int padding, int size)
          Write the ID3 header to the ByteBuffer.
 
Methods inherited from class org.jaudiotagger.tag.id3.AbstractID3v2Tag
addField, addField, addField, adjustPadding, calculateTagSize, copyFrameIntoMap, copyFrames, createAlbumField, createArtistField, createCommentField, createField, createGenreField, createLinkedArtworkField, createStructureBody, createStructureHeader, createTitleField, createTrackField, createYearField, delete, deleteArtworkField, deleteField, doCreateTagField, doDeleteTagField, doGetFirst, get, getDuplicateBytes, getDuplicateFrameId, getEmptyFrameBytes, getFieldCount, getFields, getFields, getFileLockForWriting, getFileReadBytes, getFirst, getFirst, getFirstArtwork, getFirstField, getFirstField, getFirstGenre, getFirstTitle, getFirstTrack, getFirstYear, getFrame, getFrameCount, getFrameOfType, getInvalidFrameBytes, getV2TagSizeIfExists, hasCommonFields, hasField, hasFrame, hasFrameAndBody, hasFrameOfType, isEmpty, iterator, loadFrameIntoMap, mergeDuplicateFrames, removeFrame, removeFrameOfType, removeUnsupportedFrames, seek, setEncoding, setField, setField, setField, setFrame, setFrame, write, writeBufferToFile, writeFramesToBuffer
 
Methods inherited from class org.jaudiotagger.tag.id3.AbstractID3Tag
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, toString, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.tag.Tag
toString
 

Field Detail

TYPE_COMPRESSION

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

TYPE_UNSYNCHRONISATION

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

MASK_V22_UNSYNCHRONIZATION

public static final int MASK_V22_UNSYNCHRONIZATION
Bit mask to indicate tag is Unsychronization

See Also:
Constant Field Values

MASK_V22_COMPRESSION

public static final int MASK_V22_COMPRESSION
Bit mask to indicate tag is compressed, although compression is not actually defined in v22 so just ignored

See Also:
Constant Field Values

compression

protected boolean compression
The tag is compressed, although no compression scheme is defined in ID3v22


unsynchronization

protected boolean unsynchronization
If set all frames in the tag uses unsynchronisation


RELEASE

public static final byte RELEASE
See Also:
Constant Field Values

MAJOR_VERSION

public static final byte MAJOR_VERSION
See Also:
Constant Field Values

REVISION

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

ID3v22Tag

public ID3v22Tag()
Creates a new empty ID3v2_2 tag.


ID3v22Tag

public ID3v22Tag(ID3v22Tag copyObject)
Copy Constructor, creates a new ID3v2_2 Tag based on another ID3v2_2 Tag

Parameters:
copyObject -

ID3v22Tag

public ID3v22Tag(AbstractTag mp3tag)
Constructs a new tag based upon another tag of different version/type

Parameters:
mp3tag -

ID3v22Tag

public ID3v22Tag(java.nio.ByteBuffer buffer,
                 java.lang.String loggingFilename)
          throws TagException
Creates a new ID3v2_2 datatype.

Parameters:
buffer -
loggingFilename -
Throws:
TagException

ID3v22Tag

public ID3v22Tag(java.nio.ByteBuffer buffer)
          throws TagException
Deprecated. use ID3v22Tag(ByteBuffer,String) instead

Creates a new ID3v2_2 datatype.

Parameters:
buffer -
Throws:
TagException
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:

copyPrimitives

protected void copyPrimitives(AbstractID3v2Tag copyObj)
Copy primitives applicable to v2.2

Overrides:
copyPrimitives in class AbstractID3v2Tag

getIdentifier

public java.lang.String getIdentifier()
Description copied from class: AbstractID3Tag
Get full version

Overrides:
getIdentifier in class AbstractID3Tag
Returns:
an indentifier of the tag type

getSize

public int getSize()
Return frame size based upon the sizes of the frames rather than the size including padding recorded in the tag header

Overrides:
getSize in class AbstractID3v2Tag
Returns:
size

equals

public boolean equals(java.lang.Object obj)
Description copied from class: AbstractID3v2Tag
Is this tag equivalent to another

Overrides:
equals in class AbstractID3v2Tag
Parameters:
obj -
Returns:
equality

addFrame

protected void addFrame(AbstractID3v2Frame frame)
Specified by:
addFrame in class AbstractID3v2Tag

readSize

public int readSize(java.nio.ByteBuffer buffer)
Read the size of a tag, based on the value written in the tag header

Parameters:
buffer -
Returns:
Throws:
TagException

readHeaderFlags

private void readHeaderFlags(java.nio.ByteBuffer byteBuffer)
                      throws TagException
Read tag Header Flags

Parameters:
byteBuffer -
Throws:
TagException

read

public void read(java.nio.ByteBuffer byteBuffer)
          throws TagException

Specified by:
read in class AbstractTagItem
Parameters:
byteBuffer - file to read from
Throws:
TagException - on any exception generated by this library.

readFrames

protected void readFrames(java.nio.ByteBuffer byteBuffer,
                          int size)
Read frames from tag

Parameters:
byteBuffer -
size -

translateFrame

protected void translateFrame(AbstractID3v2Frame frame)
This is used when we need to translate a single frame into multiple frames, currently required for TDRC frames.

Parameters:
frame -

writeHeaderToBuffer

private java.nio.ByteBuffer writeHeaderToBuffer(int padding,
                                                int size)
                                         throws java.io.IOException
Write the ID3 header to the ByteBuffer.

Parameters:
padding -
size -
Returns:
ByteBuffer
Throws:
java.io.IOException

write

public void write(java.io.File file,
                  long audioStartLocation)
           throws java.io.IOException
Write tag to file.

Overrides:
write in class AbstractID3v2Tag
Throws:
java.io.IOException - TODO should be abstract

write

public void write(java.nio.channels.WritableByteChannel channel)
           throws java.io.IOException
Write tag to channel.

Overrides:
write in class AbstractID3v2Tag
Throws:
java.io.IOException - TODO should be abstract

createStructure

public void createStructure()
Overrides:
createStructure in class AbstractID3v2Tag

isUnsynchronization

public boolean isUnsynchronization()
Returns:
is tag unsynchronized

isCompression

public boolean isCompression()
Returns:
is tag compressed

getArtistId

protected java.lang.String getArtistId()
Specified by:
getArtistId in class AbstractID3v2Tag
Returns:

getAlbumId

protected java.lang.String getAlbumId()
Specified by:
getAlbumId in class AbstractID3v2Tag
Returns:

getTitleId

protected java.lang.String getTitleId()
Specified by:
getTitleId in class AbstractID3v2Tag
Returns:

getTrackId

protected java.lang.String getTrackId()
Specified by:
getTrackId in class AbstractID3v2Tag
Returns:

getYearId

protected java.lang.String getYearId()
Specified by:
getYearId in class AbstractID3v2Tag
Returns:

getCommentId

protected java.lang.String getCommentId()
Specified by:
getCommentId in class AbstractID3v2Tag
Returns:

getGenreId

protected java.lang.String getGenreId()
Specified by:
getGenreId in class AbstractID3v2Tag
Returns:

createFrame

public ID3v22Frame createFrame(java.lang.String id)
Create Frame

Specified by:
createFrame in class AbstractID3v2Tag
Parameters:
id - frameid
Returns:

createTagField

public TagField createTagField(ID3v22FieldKey id3Key,
                               java.lang.String value)
                        throws KeyNotFoundException,
                               FieldDataInvalidException
Create Frame for Id3 Key

Only textual data supported at the moment, should only be used with frames that support a simple string argument.

Parameters:
id3Key -
value -
Returns:
Throws:
KeyNotFoundException
FieldDataInvalidException

getFirst

public java.lang.String getFirst(ID3v22FieldKey id3v22FieldKey)
                          throws KeyNotFoundException
Retrieve the first value that exists for this id3v22key

Parameters:
id3v22FieldKey -
Returns:
Throws:
KeyNotFoundException

deleteTagField

public void deleteTagField(ID3v22FieldKey id3v22FieldKey)
                    throws KeyNotFoundException
Delete fields with this id3v22FieldKey

Parameters:
id3v22FieldKey -
Throws:
KeyNotFoundException

getFrameAndSubIdFromGenericKey

protected AbstractID3v2Tag.FrameAndSubId getFrameAndSubIdFromGenericKey(FieldKey genericKey)
Specified by:
getFrameAndSubIdFromGenericKey in class AbstractID3v2Tag

getID3Frames

protected ID3Frames getID3Frames()
Specified by:
getID3Frames in class AbstractID3v2Tag

getPreferredFrameOrderComparator

public java.util.Comparator getPreferredFrameOrderComparator()
Specified by:
getPreferredFrameOrderComparator in class AbstractID3v2Tag
Returns:
comparator used to order frames in preffrred order for writing to file so that most important frames are written first.

getArtworkList

public java.util.List<Artwork> getArtworkList()

Returns:
a list of all artwork in this file using the format indepedent Artwork class

createField

public TagField createField(Artwork artwork)
                     throws FieldDataInvalidException
Create artwork field based on the data in artwork

Returns:
suitable tagfield for this format that represents the artwork data
Throws:
FieldDataInvalidException

createArtworkField

public TagField createArtworkField(byte[] data,
                                   java.lang.String mimeType)