org.jaudiotagger.tag.id3
Class ID3v23Tag

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.ID3v23Tag
All Implemented Interfaces:
Tag

public class ID3v23Tag
extends AbstractID3v2Tag

Represents an ID3v2.3 tag.

Version:
$Id: ID3v23Tag.java,v 1.52 2009/11/12 15:42:58 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
private  int crc32
          Crcdata Checksum in extended header
protected  boolean crcDataFlag
          CRC Checksum calculated
protected  boolean experimental
          Experiemntal tag
protected  boolean extended
          Contains extended header
protected static int FIELD_TAG_EXT_SIZE_LENGTH
           
static byte MAJOR_VERSION
           
static int MASK_V23_CRC_DATA_PRESENT
          ID3v2.3 Extended Header bit mask
static int MASK_V23_EMBEDDED_INFO_FLAG
          ID3v2.3 RBUF frame bit mask
static int MASK_V23_EXPERIMENTAL
          ID3v2.3 Header bit mask
static int MASK_V23_EXTENDED_HEADER
          ID3v2.3 Header bit mask
static int MASK_V23_UNSYNCHRONIZATION
          ID3v2.3 Header bit mask
private  int paddingSize
          Tag padding
static byte RELEASE
           
static byte REVISION
           
protected static int TAG_EXT_HEADER_CRC_LENGTH
           
protected static int TAG_EXT_HEADER_DATA_LENGTH
           
protected static int TAG_EXT_HEADER_LENGTH
           
protected static java.lang.String TYPE_CRCDATA
           
protected static java.lang.String TYPE_EXPERIMENTAL
           
protected static java.lang.String TYPE_EXTENDED
           
protected static java.lang.String TYPE_PADDINGSIZE
           
protected static java.lang.String TYPE_UNSYNCHRONISATION
           
protected  boolean unsynchronization
          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
ID3v23Tag()
          Creates a new empty ID3v2_3 datatype.
ID3v23Tag(AbstractTag mp3tag)
          Constructs a new tag based upon another tag of different version/type
ID3v23Tag(java.nio.ByteBuffer buffer)
          Deprecated. use ID3v23Tag(ByteBuffer,String) instead
ID3v23Tag(java.nio.ByteBuffer buffer, java.lang.String loggingFilename)
          Creates a new ID3v2_3 datatype.
ID3v23Tag(ID3v23Tag copyObject)
          Copy Constructor, creates a new ID3v2_3 Tag based on another ID3v2_3 Tag
 
Method Summary
protected  void addFrame(AbstractID3v2Frame frame)
           
protected  void copyPrimitives(AbstractID3v2Tag copyObj)
          Copy primitives applicable to v2.3
 TagField createArtworkField(byte[] data, java.lang.String mimeType)
          Create Artwork
 TagField createField(Artwork artwork)
          Create artwork field based on the data in artwork
 ID3v23Frame createFrame(java.lang.String id)
          Create Frame of correct ID3 version with the specified id
 void createStructure()
          For representing the MP3File in an XML Format
 TagField createTagField(ID3v23FieldKey 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(ID3v23FieldKey id3v23FieldKey)
          Delete fields with this id3v23FieldKey
 boolean equals(java.lang.Object obj)
          Is Tag Equivalent to another tag
protected  java.lang.String getAlbumId()
           
protected  java.lang.String getArtistId()
           
 java.util.List<Artwork> getArtworkList()
          
protected  java.lang.String getCommentId()
           
 int getCrc32()
           
 java.lang.String getFirst(ID3v23FieldKey id3v23FieldKey)
          Retrieve the first value that exists for this id3v23key
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
 int getPaddingSize()
           
 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 tags rather than the physical no of bytes between start of ID3Tag and start of Audio Data.
protected  java.lang.String getTitleId()
           
protected  java.lang.String getTrackId()
           
protected  java.lang.String getYearId()
           
 boolean isUnsynchronization()
           
 void read(java.nio.ByteBuffer buffer)
          
private  void readExtendedHeader(java.nio.ByteBuffer buffer, int size)
          Read the optional extended header
protected  void readFrames(java.nio.ByteBuffer byteBuffer, int size)
          Read the frames

Read from byteBuffer upto size

private  void readHeaderFlags(java.nio.ByteBuffer buffer)
          Read 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 v24 TDRC frames.
 void write(java.io.File file, long audioStartLocation)
          Write tag to file

TODO:we currently never write the Extended header , but if we did the size calculation in this method would be slightly incorrect

 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, wait, wait, wait
 
Methods inherited from interface org.jaudiotagger.tag.Tag
toString
 

Field Detail

TYPE_CRCDATA

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

TYPE_EXPERIMENTAL

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

TYPE_EXTENDED

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

TYPE_PADDINGSIZE

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

TYPE_UNSYNCHRONISATION

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

TAG_EXT_HEADER_LENGTH

protected static int TAG_EXT_HEADER_LENGTH

TAG_EXT_HEADER_CRC_LENGTH

protected static int TAG_EXT_HEADER_CRC_LENGTH

FIELD_TAG_EXT_SIZE_LENGTH

protected static int FIELD_TAG_EXT_SIZE_LENGTH

TAG_EXT_HEADER_DATA_LENGTH

protected static int TAG_EXT_HEADER_DATA_LENGTH

MASK_V23_UNSYNCHRONIZATION

public static final int MASK_V23_UNSYNCHRONIZATION
ID3v2.3 Header bit mask

See Also:
Constant Field Values

MASK_V23_EXTENDED_HEADER

public static final int MASK_V23_EXTENDED_HEADER
ID3v2.3 Header bit mask

See Also:
Constant Field Values

MASK_V23_EXPERIMENTAL

public static final int MASK_V23_EXPERIMENTAL
ID3v2.3 Header bit mask

See Also:
Constant Field Values

MASK_V23_CRC_DATA_PRESENT

public static final int MASK_V23_CRC_DATA_PRESENT
ID3v2.3 Extended Header bit mask

See Also:
Constant Field Values

MASK_V23_EMBEDDED_INFO_FLAG

public static final int MASK_V23_EMBEDDED_INFO_FLAG
ID3v2.3 RBUF frame bit mask

See Also:
Constant Field Values

crcDataFlag

protected boolean crcDataFlag
CRC Checksum calculated


experimental

protected boolean experimental
Experiemntal tag


extended

protected boolean extended
Contains extended header


crc32

private int crc32
Crcdata Checksum in extended header


paddingSize

private int paddingSize
Tag padding


unsynchronization

protected boolean unsynchronization
All frames in the tag uses unsynchronisation


compression

protected boolean compression
The tag is compressed


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

ID3v23Tag

public ID3v23Tag()
Creates a new empty ID3v2_3 datatype.


ID3v23Tag

public ID3v23Tag(ID3v23Tag copyObject)
Copy Constructor, creates a new ID3v2_3 Tag based on another ID3v2_3 Tag

Parameters:
copyObject -

ID3v23Tag

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

Parameters:
mp3tag -

ID3v23Tag

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

Parameters:
buffer -
loggingFilename -
Throws:
TagException

ID3v23Tag

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

Creates a new ID3v2_3 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:

getCrc32

public int getCrc32()
Returns:
Cyclic Redundancy Check 32 Value

copyPrimitives

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

Overrides:
copyPrimitives in class AbstractID3v2Tag

addFrame

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

translateFrame

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

Parameters:
frame -

getIdentifier

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

Overrides:
getIdentifier in class AbstractID3Tag
Returns:
textual tag identifier

getSize

public int getSize()
Return frame size based upon the sizes of the tags rather than the physical no of bytes between start of ID3Tag and start of Audio Data.

TODO this is incorrect, because of subclasses

Overrides:
getSize in class AbstractID3v2Tag
Returns:
size of tag

equals

public boolean equals(java.lang.Object obj)
Is Tag Equivalent to another tag

Overrides:
equals in class AbstractID3v2Tag
Parameters:
obj -
Returns:
true if tag is equivalent to another

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 buffer)
                      throws TagException
Read header flags

Log info messages for falgs that have been set and log warnings when bits have been set for unknown flags

Parameters:
buffer -
Throws:
TagException

readExtendedHeader

private void readExtendedHeader(java.nio.ByteBuffer buffer,
                                int size)
Read the optional extended header

Parameters:
buffer -
size -

read

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

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

readFrames

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

Read from byteBuffer upto size

Parameters:
byteBuffer -
size -

writeHeaderToBuffer

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

TODO Calculate the CYC Data Check TODO Reintroduce Extended Header

Parameters:
padding - is the size of the padding portion of the tag
size - is the size of the body data
Returns:
ByteBuffer
Throws:
java.io.IOException

write

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

TODO:we currently never write the Extended header , but if we did the size calculation in this method would be slightly incorrect

Overrides:
write in class AbstractID3v2Tag
Parameters:
file - The file to write to
Throws:
java.io.IOException

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()
For representing the MP3File in an XML Format

Overrides:
createStructure in class AbstractID3v2Tag

isUnsynchronization

public boolean isUnsynchronization()
Returns:
is tag unsynchronized

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 ID3v23Frame createFrame(java.lang.String id)
Description copied from class: AbstractID3v2Tag
Create Frame of correct ID3 version with the specified id

Specified by:
createFrame in class AbstractID3v2Tag
Returns:

createTagField

public TagField createTagField(ID3v23FieldKey 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(ID3v23FieldKey id3v23FieldKey)
                          throws KeyNotFoundException
Retrieve the first value that exists for this id3v23key

Parameters:
id3v23FieldKey -
Returns:
Throws:
KeyNotFoundException

deleteTagField

public void deleteTagField(ID3v23FieldKey id3v23FieldKey)
                    throws KeyNotFoundException
Delete fields with this id3v23FieldKey

Parameters:
id3v23FieldKey -
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 preferred 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)
Create Artwork

Parameters:
data -
mimeType - of the image
Returns:
See Also:
PictureTypes

getPaddingSize

public int getPaddingSize()