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

COMMID3V2Frame

public class COMMID3V2Frame extends ID3V2Frame
author
paul Frame containing comments.

Fields Summary
private TextEncoding
m_oTextEncoding
private String
m_sLanguage
private String
m_sShortDescription
private String
m_sActualText
Constructors Summary
public COMMID3V2Frame(String sLanguage, String sShortDescription, String sActualText)
Constructor.

param
sLanguage three letter language code for this comment
param
sShortDescription a short description of this comment (null or zero-length string for no description)
param
sActualText the actual text of the comment
throws
ID3Exception if the language code is not three characters in length
throws
ID3Exception if the actual text is null

    
                                                              
          
         
    
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("Language string in COMM frame must have length of 3.");
        }
        m_sLanguage = sLanguage;
        m_sShortDescription = sShortDescription;
        if (m_sShortDescription == null)
        {
            m_sShortDescription = "";
        }
        if (sActualText == null)
        {
            throw new ID3Exception("Comment text is required in COMM frame.");
        }
        m_sActualText = sActualText;
    
public COMMID3V2Frame(InputStream oIS)

        // Parse out the text encoding and text string from the raw data
        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // text encoding
            byte byTextEncoding = (byte)oFrameDataID3DIS.readUnsignedByte();
            m_oTextEncoding = TextEncoding.getTextEncoding(byTextEncoding);
            
            // language
            byte[] abyLanguage = new byte[3];
            oFrameDataID3DIS.readFully(abyLanguage);
            m_sLanguage = new String(abyLanguage);
            
            // short description (read to null)
            m_sShortDescription = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
            
            // actual comment
            byte[] abyActualText = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(abyActualText);
            m_sActualText = new String(abyActualText, m_oTextEncoding.getEncodingString());
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof COMMID3V2Frame)))
        {
            return false;
        }
        
        COMMID3V2Frame oOtherCOMM = (COMMID3V2Frame)oOther;
        
        return ((m_oTextEncoding.equals(oOtherCOMM.m_oTextEncoding)) &&
                m_sLanguage.equals(oOtherCOMM.m_sLanguage) &&
                m_sShortDescription.equals(oOtherCOMM.m_sShortDescription) &&
                m_sActualText.equals(oOtherCOMM.m_sActualText));
    
public java.lang.StringgetActualText()
Get the actual text of the comment.

return
the actual text of the comment

        return m_sActualText;
    
protected byte[]getFrameId()

        return "COMM".getBytes();
    
public java.lang.StringgetLanguage()
Get the language of this comment.

return
a three letter code defining the language used

        return m_sLanguage;
    
public java.lang.StringgetShortDescription()
Get the short description of this comment.

return
the short description of this comment

        return m_sShortDescription;
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the short description and actual text in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public voidsetComment(java.lang.String sLanguage, java.lang.String sShortDescription, java.lang.String sActualText)
Set the language of this comment.

param
sLanguage three letter language code for this comment
param
sShortDescription a short description of this comment (null or zero-length string for no description)
param
sActualText the actual text of the comment
throws
ID3Exception if the language code is not three characters in length
throws
ID3Exception if the actual text is null
throws
ID3Exception if this frame is in a tag with another COMM frame which would have the same language and short description

        TextEncoding oOrigTextEncoding = m_oTextEncoding;
        String sOrigLanguage = m_sLanguage;
        String sOrigShortDescription = m_sShortDescription;
        String sOrigActualText = m_sActualText;
        
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("Language string in COMM frame must have length of 3.");
        }
        if (sActualText == null)
        {
            throw new ID3Exception("Comment text is required in COMM frame.");
        }
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sLanguage = sLanguage;
        m_sShortDescription = sShortDescription;
        if (m_sShortDescription == null)
        {
            m_sShortDescription = "";
        }
        m_sActualText = sActualText;
        
        // try this update, and reverse it if it generates an error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sLanguage = sOrigLanguage;
            m_sShortDescription = sShortDescription;
            m_sActualText = sOrigActualText;
            m_oTextEncoding = oOrigTextEncoding;
            
            throw e;
        }
    
public voidsetLanguage(java.lang.String sLanguage)
Set the language of this comment.

param
sLanguage the language of the comment

        String sOrigLanguage = m_sLanguage;
        
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("Language string in COMM frame must have length of 3.");
        }
        m_sLanguage = sLanguage;

        // try this update, and reverse it if it generates an error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sLanguage = sOrigLanguage;
            
            throw e;
        }
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the short description and actual text in this frame.

param
oTextEncoding the text encoding to be used for this frame

        if (oTextEncoding == null)
        {
            throw new NullPointerException("Text encoding cannot be null.");
        }
        m_oTextEncoding = oTextEncoding;
    
public java.lang.StringtoString()

        return "Comment: Language=[" + m_sLanguage + "], Short description=[" +
               m_sShortDescription + "], Actual text=[" + m_sActualText + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // text encoding
        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        // language
        oIDOS.write(m_sLanguage.getBytes());
        // short description
        if (m_sShortDescription != null)
        {
            oIDOS.write(m_sShortDescription.getBytes(m_oTextEncoding.getEncodingString()));
        }
        // null separating description from picture data
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        // actual text of comment
        oIDOS.write(m_sActualText.getBytes(m_oTextEncoding.getEncodingString()));