FileDocCategorySizeDatePackage
LINKID3V2Frame.javaAPI Docjid3 0.467600Sun Feb 06 18:11:24 GMT 2005org.blinkenlights.jid3.v2

LINKID3V2Frame

public class LINKID3V2Frame extends ID3V2Frame
Frame containing linked frame information.
author
paul

Fields Summary
private byte[]
m_abyFrameIdentifier
private String
m_sURL
private String
m_sAdditionalData
Constructors Summary
public LINKID3V2Frame(byte[] abyFrameIdentifier, String sURL, String sAdditionalData)
Constructor

param
abyFrameIdentifier the frame identifier of the frame linked to
param
sURL a reference to the location of the linked frame
param
sAdditionalData any additional data which may be needed to retrieve the linked frame
throws
ID3Exception if a frame identifier of four bytes is not specified, or if the URL is not specified

    
                                                                
          
         
    
        if (abyFrameIdentifier == null)
        {
            throw new ID3Exception("LINK frame requires frame identifier.");
        }
        if (abyFrameIdentifier.length != 4)
        {
            throw new ID3Exception("Frame identifiers must be four bytes in length in LINK frame.");
        }
        m_abyFrameIdentifier = abyFrameIdentifier;
        if ((sURL == null) || (sURL.length() == 0))
        {
            throw new ID3Exception("LINK frame requires an URL.");
        }
        m_sURL = sURL;
        m_sAdditionalData = sAdditionalData;
    
public LINKID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // frame identifier (this is probably wrong... it should probably be four
            // bytes.. if anyone ever uses this (?) it might break
            m_abyFrameIdentifier = new byte[4];
            oFrameDataID3DIS.readFully(m_abyFrameIdentifier);
            
            // url
            m_sURL = oFrameDataID3DIS.readStringToNull();
            
            // id and additional data
            if (oFrameDataID3DIS.available() > 0)
            {
                byte[] abyAdditionalData = new byte[oFrameDataID3DIS.available()];
                oFrameDataID3DIS.readFully(abyAdditionalData);
                m_sAdditionalData = new String(abyAdditionalData);
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitLINKID3V2Frame(this);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof LINKID3V2Frame)))
        {
            return false;
        }
        
        LINKID3V2Frame oOtherLINK = (LINKID3V2Frame)oOther;
        
        return ( Arrays.equals(m_abyFrameIdentifier, oOtherLINK.m_abyFrameIdentifier) &&
                 (((m_sURL == null) && (oOtherLINK.m_sURL == null)) || m_sURL.equals(oOtherLINK.m_sURL)) &&
                 m_sAdditionalData.equals(oOtherLINK.m_sAdditionalData) );
    
public java.lang.StringgetAdditionalData()
Get any additional link-related data in this frame.

return
any additional link-related data

        return m_sAdditionalData;
    
protected byte[]getFrameId()

        return "LINK".getBytes();
    
public byte[]getFrameIdentifier()
Get the frame identifier of the linked frame.

return
the frame identifier bytes (which should be of length four)

        return m_abyFrameIdentifier;
    
public java.lang.StringgetLinkUrl()
Get the URL pointing to the location of the file containing the linked frame.

return
the location url

        return m_sURL;
    
public voidsetContents(byte[] abyFrameIdentifier, java.lang.String sURL, java.lang.String sAdditionalData)
Set the contents of this frame.

param
abyFrameIdentifier the frame identifier of the frame linked to
param
sURL a reference to the location of the linked frame
param
sAdditionalData any additional data which may be needed to retrieve the linked frame
throws
ID3Exception if a frame identifier of four bytes is not specified, or if the URL is not specified
throws
ID3Exception if this frame is in a tag with another LINK frame which would have the same contents

        byte[] abyOrigFrameIdentifier = m_abyFrameIdentifier;
        String sOrigURL = m_sURL;
        String sOrigAdditionalData = m_sAdditionalData;
        
        if (abyFrameIdentifier == null)
        {
            throw new ID3Exception("LINK frame requires frame identifier.");
        }
        if (abyFrameIdentifier.length != 4)
        {
            throw new ID3Exception("Frame identifiers must be four bytes in length in LINK frame.");
        }
        if ((sURL == null) || (sURL.length() == 0))
        {
            throw new ID3Exception("LINK frame requires an URL.");
        }

        m_abyFrameIdentifier = abyFrameIdentifier;
        m_sURL = sURL;
        m_sAdditionalData = sAdditionalData;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_abyFrameIdentifier = abyOrigFrameIdentifier;
            m_sURL = sOrigURL;
            m_sAdditionalData = sOrigAdditionalData;
            
            throw e;
        }
    
public java.lang.StringtoString()

        StringBuffer sbOutput = new StringBuffer();
        sbOutput.append("Link: Frame identifier=[" + ID3Util.convertBytesToHexString(m_abyFrameIdentifier, true) +
                        "], URL=[" + m_sURL + "], Additional data=[" + m_sAdditionalData + "]");
        
        return sbOutput.toString();
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // frame identifier
        oIDOS.write(m_abyFrameIdentifier);
        
        // url
        oIDOS.write(m_sURL.getBytes());
        oIDOS.writeUnsignedByte(0);
        
        // additional data
        oIDOS.write(m_sAdditionalData.getBytes());