FileDocCategorySizeDatePackage
ID3V2Tag.javaAPI Docjid3 0.4614232Thu Oct 27 03:12:20 BST 2005org.blinkenlights.jid3.v2

ID3V2Tag

public abstract class ID3V2Tag extends ID3Tag
author
paul Base class representing all ID3 V2 tags.

Fields Summary
protected boolean
m_bUnsynchronizationUsedFlag
Flag indicating whether unsynchronization is used in this tag or not.
protected boolean
m_bExtendedHeaderFlag
Flag indicating whether the extended header is present or not.
protected boolean
m_bExperimentalFlag
Flag indicating this tag should be considered experimental.
protected boolean
m_bCRCDataFlag
Flag indicating whether a CRC value exists in the extended header.
protected Map
m_oFrameIdToFrameMap
Mapping from frame ID to list containing frames. For frames that can only be used once.
private static int
s_iDefaultPaddingLength
Default padding for ID3 v2 frames, if not specified. 16 bytes, because Winamp does not read the last frame when there isn't at least 6 bytes of padding following it in a tag.
protected int
m_iPaddingLength
Value specifying the amount of padding which is appended to the frames in this tag.
Constructors Summary
public ID3V2Tag(boolean bUnsynchronizationUsedFlag, boolean bExtendedHeaderFlag, boolean bExperimentalFlag)
Construct an ID3 V2 tag, specifying flag values.

param
bUnsynchronizationUsedFlag specify whether unsynchronization is to be used in this tag or not
param
bExtendedHeaderFlag specify whether the extended header will be present or not
param
bExperimentalFlag specify whether this tag is to be considered experimental or not


                                                        
      
                     
                     
    
        m_bUnsynchronizationUsedFlag = bUnsynchronizationUsedFlag;
        m_bExtendedHeaderFlag = bExtendedHeaderFlag;
        m_bExperimentalFlag = bExperimentalFlag;
        m_oFrameIdToFrameMap = new HashMap();
        //HACK: Default padding of 16 bytes, because Winamp doesn't seem to see the last frame in a v2 tag
        //      when there is less than 6 bytes of padding.  (???)
        m_iPaddingLength = s_iDefaultPaddingLength;
    
Methods Summary
public abstract booleancontainsAtLeastOneFrame()
Check if this tag contains at least one frame. An ID3V2 tag requires at least one frame to be written.

return
true if this tag contains at least one frame, and false otherwise

public abstract java.lang.StringgetAlbum()
Convenience method for retrieving album title directly from tag.

return
the album title currently set
throws
ID3Exception

public abstract java.lang.StringgetArtist()
Convenience method for retrieving artist directly from tag.

return
the artist value currently set
throws
ID3Exception

public booleangetCRC()
Get the current CRC status for the extended header in this frame.

return
true if the extended header is enabled, and the CRC flag is also enabled, or false otherwise

        return m_bCRCDataFlag;
    
public abstract java.lang.StringgetComment()
Convenience method for retrieving the comment directly from tag.

return
the comment currently set
throws
ID3Exception

public static intgetDefaultPaddingLength()
Get the default padding length currently set for newly created tags.

return
the current padding length

        return s_iDefaultPaddingLength;
    
public booleangetExtendedHeader()
Get the current extended header status for this tag.

return
the current status of the extended header flag

        return m_bExtendedHeaderFlag;
    
public abstract java.lang.StringgetGenre()
Convenience method for retrieving the genre directly from tag.

return
the genre currently set
throws
ID3Exception

public intgetPaddingLength()
Get the padding length currently set for this tag.

return
the current padding length

        return m_iPaddingLength;
    
public ID3V2Frame[]getSingleFrames()
Get all frames set in this tag which can only be stored once in the tag. This method exists to aid in testing.

        return (ID3V2Frame[])m_oFrameIdToFrameMap.values().toArray(new ID3V2Frame[0]);
    
public abstract java.lang.StringgetTitle()
Convenience method for retrieving song title directly from tag.

return
the song title currently set
throws
ID3Exception

public abstract intgetTotalTracks()
Convenience method for retrieving total number of tracks directly from tag.

return
the total number of tracks currently set
throws
ID3Exception if total number of tracks was not set

public abstract intgetTrackNumber()
Convenience method for retrieving track number directly from tag.

return
the track number currently set
throws
ID3Exception if not track number was set

public booleangetUnsynchronization()
Get the current unsynchronization status for this tag.

return
the current status of the unsynchronization flag

        return m_bUnsynchronizationUsedFlag;
    
public abstract intgetYear()
Convenience method for retrieving year directly from tag.

return
the year currently set
throws
ID3Exception if no year was set

public static org.blinkenlights.jid3.v2.ID3V2Tagread(java.io.InputStream oIS)
Read a tag from an input stream.

param
oIS the input stream from which to read a tag
return
the tag read
throws
ID3Exception if an error occurs while reading the tag

        try
        {
            ID3DataInputStream oID3DIS = new ID3DataInputStream(oIS);
            
            // check which version of v2 tags we have
            int iMinorVersion = oID3DIS.readUnsignedByte();
            int iPatchVersion = oID3DIS.readUnsignedByte();
                    
            if (iMinorVersion == 3)
            {
                // there is a tag, we must read it
                ID3V2Tag oID3V2Tag = ID3V2_3_0Tag.internalRead(oID3DIS);
                
                return oID3V2Tag;
            }
            else
            {
                //TODO: If we're going to support >2.3.0 tags, do that here.
                return null;
            }
        }
        catch (ID3Exception e)
        {
            throw e;
        }
        catch (Exception e)
        {
            throw new ID3Exception("Error reading tag.", e);
        }
    
public abstract voidsanityCheck()

public abstract voidsetAlbum(java.lang.String sAlbum)
Convenience method for setting album title directly from tag.

param
sAlbum the album title
throws
ID3Exception

public abstract voidsetArtist(java.lang.String sArtist)
Convenience method for setting artist directly from tag.

param
sArtist the artist name
throws
ID3Exception

public voidsetCRC(boolean bCRCUsed)
Set the CRC flag (extended header must be enabled before this flag can be set.

param
bCRCUsed an indication of whether a CRC value should be included in the extended header of this tag

        if ( ! m_bExtendedHeaderFlag)
        {
            throw new ID3Exception("The CRC flag cannot be set unless the extended header flag is set first.");
        }
        
        m_bCRCDataFlag = bCRCUsed;
    
public abstract voidsetComment(java.lang.String sComment)
Convenience method for setting comment directly from tag.

param
sComment the comment
throws
ID3Exception

public static voidsetDefaultPaddingLength(int iPaddingLength)
Set the default padding length to be added at the end of newly created tags. NOTE: When read by Winamp, it seems the last frame in a v2 tag is not seen, unless there are at least six bytes of padding at the end of the tag. For this reason, the default padding at the end of v2 tags is set to 16. This value can be modified if desired, but be aware of this observation regarding Winamp.

param
iPaddingLength the padding length to use
throws
ID3Exception if the padding length value is negative

        if (iPaddingLength < 0)
        {
            throw new ID3Exception("Padding length in ID3 V2 tag cannot be negative.");
        }
        
        s_iDefaultPaddingLength = iPaddingLength;
    
public voidsetExtendedHeader(boolean bExtendedHeaderUsed)
Set the extended header flag for this tag.

param
bExtendedHeaderUsed an indication of whether the extended header should be included in this tag

        m_bExtendedHeaderFlag = bExtendedHeaderUsed;
    
public abstract voidsetGenre(java.lang.String sGenre)
Convenience method for setting genre directly from tag.

param
sGenre the genre (free-form)
throws
ID3Exception

public voidsetPaddingLength(int iPaddingLength)
Set the padding length to be added at the end of this tag. NOTE: When read by Winamp, it seems the last frame in a v2 tag is not seen, unless there are at least six bytes of padding at the end of the tag. For this reason, the default padding at the end of v2 tags is set to 16. This value can be modified if desired, but be aware of this observation regarding Winamp.

param
iPaddingLength the padding length to use
throws
ID3Exception if the padding length value is negative

        if (iPaddingLength < 0)
        {
            throw new ID3Exception("Padding length in ID3 V2 tag cannot be negative.");
        }
        
        m_iPaddingLength = iPaddingLength;
    
public abstract voidsetTitle(java.lang.String sTitle)
Convenience method for setting song title directly from tag.

param
sTitle the song title
throws
ID3Exception

public abstract voidsetTrackNumber(int iTrackNumber)
Convenience method for setting track number directly from tag.

param
iTrackNumber the track number
throws
ID3Exception

public abstract voidsetTrackNumber(int iTrackNumber, int iTotalTracks)
Convenience method for setting track number and total number of tracks directly from tag.

param
iTrackNumber the track number
param
iTotalTracks the total number of tracks
throws
ID3Exception

public voidsetUnsynchronization(boolean bUnsynchronizationUsed)
Set the unsynchronization status.

param
bUnsynchronizationUsed an indication of whether unsynchronization should be used when writing this tag

        m_bUnsynchronizationUsedFlag = bUnsynchronizationUsed;
    
public abstract voidsetYear(int iYear)
Convenience method for setting year directly from tag.

return
the year of the recording
throws
ID3Exception

public java.lang.StringtoString()

        StringBuffer sbText = new StringBuffer();
        sbText.append("Unsynchronization: " + m_bUnsynchronizationUsedFlag +
                      "\nExtended header: " + m_bExtendedHeaderFlag +
                      "\nExperimental: " + m_bExperimentalFlag +
                      "\nCRC: " + m_bCRCDataFlag +
                      "\nPadding length: " + + m_iPaddingLength +
                      "\nNum frames: " + m_oFrameIdToFrameMap.size());
        Iterator oIter = m_oFrameIdToFrameMap.keySet().iterator();
        while(oIter.hasNext())
        {
            String sFrameId = (String)oIter.next();
            sbText.append("\n" + ((ID3V2Frame)m_oFrameIdToFrameMap.get(sFrameId)));
        }
        
        return sbText.toString();
    
public abstract voidwrite(java.io.OutputStream oOS)
Write this tag to an output stream.

param
oOS the output stream to which this tag is to be written
throws
ID3Exception if an error occurs while writing