FileDocCategorySizeDatePackage
TXXXTextInformationID3V2Frame.javaAPI Docjid3 0.466653Sun Feb 06 18:11:16 GMT 2005org.blinkenlights.jid3.v2

TXXXTextInformationID3V2Frame

public class TXXXTextInformationID3V2Frame extends TextInformationID3V2Frame
author
paul Text frame containing user-defined infromation.

Fields Summary
private String
m_sDescription
Constructors Summary
public TXXXTextInformationID3V2Frame(String sDescription, String sInformation)
Constructor.

param
sDescription a description of the information being stored
param
sInformation the information being stored
throws
ID3Exception if either the description or information are empty


                                   
        
         
    
        super(sInformation);
        
        if ((sDescription == null) || (sDescription.length() == 0))
        {
            throw new ID3Exception("Description required for TXXX frame.");
        }
        if ((sInformation == null) || (sInformation.length() == 0))
        {
            throw new ID3Exception("Information required for TXXX frame.");
        }
        
        m_sDescription = sDescription;
    
public TXXXTextInformationID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);

            // text encoding
            m_oTextEncoding = TextEncoding.getTextEncoding(oFrameDataID3DIS.readUnsignedByte());

            // description (read to null)
            m_sDescription = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
            
            // information
            byte[] abyInformation = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(abyInformation);
            m_sInformation = new String(abyInformation, m_oTextEncoding.getEncodingString());
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof TXXXTextInformationID3V2Frame)))
        {
            return false;
        }
        
        TXXXTextInformationID3V2Frame oOtherTXXX = (TXXXTextInformationID3V2Frame)oOther;
        
        return (m_oTextEncoding.equals(oOtherTXXX.m_oTextEncoding) &&
                m_sDescription.equals(oOtherTXXX.m_sDescription) &&
                m_sInformation.equals(oOtherTXXX.m_sInformation));
    
public java.lang.StringgetDescription()
Get the description of the information stored in this frame.

return
the description of the information stored in this frame

        return m_sDescription;
    
protected byte[]getFrameId()

        return "TXXX".getBytes();
    
public java.lang.StringgetInformation()
Get the information stored in this frame.

return
the information stored in this frame

        return m_sInformation;
    
public voidsetDescriptionAndInformation(java.lang.String sDescription, java.lang.String sInformation)
Set the description of the information to be stored in this frame, along with the actual information.

param
sDescription a description of the information being stored
param
sInformation the information being stored
throws
ID3Exception if either the description or information are empty, or if this TXXX frame is stored in a tag where there is another TXXX frame with the same description

        String sOrigDescription = m_sDescription;
        String sOrigInformation = m_sInformation;
        TextEncoding oOrigTextEncoding = m_oTextEncoding;
        
        if ((sDescription == null) || (sDescription.length() == 0))
        {
            throw new ID3Exception("Description required for TXXX frame.");
        }
        if ((sInformation == null) || (sInformation.length() == 0))
        {
            throw new ID3Exception("Information required for TXXX frame.");
        }

        m_sDescription = sDescription;
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = sInformation;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sDescription = sOrigDescription;
            m_sInformation = sOrigInformation;
            m_oTextEncoding = oOrigTextEncoding;
            
            throw e;
        }
    
public java.lang.StringtoString()

        return "User-defined text: Description=[" + m_sDescription + "], Information=[" + m_sInformation + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        oIDOS.write(m_sDescription.getBytes(m_oTextEncoding.getEncodingString()));
        // null separating description from information string
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        oIDOS.write(m_sInformation.getBytes(m_oTextEncoding.getEncodingString()));