FileDocCategorySizeDatePackage
USERID3V2Frame.javaAPI Docjid3 0.466385Sun Feb 06 18:11:15 GMT 2005org.blinkenlights.jid3.v2

USERID3V2Frame

public class USERID3V2Frame extends ID3V2Frame
Frame containing terms of use information.
author
paul

Fields Summary
private TextEncoding
m_oTextEncoding
private String
m_sLanguage
private String
m_sTermsOfUse
Constructors Summary
public USERID3V2Frame(String sLanguage, String sTermsOfUse)
Creates a new instance of USERID3V2Frame.

param
sLanguage a three character code specifying the language of the terms of use
param
sTermsOfUse the terms of use for this recording or file
throws
ID3Exception if the language is not in a valid format, or if the terms of use are not specified

    
                                                            
        
         
    
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("Language must be a three character length string in USER frame.");
        }
        m_sLanguage = sLanguage;
        if ((sTermsOfUse == null) || (sTermsOfUse.length() == 0))
        {
            throw new ID3Exception("Terms of use are required in USER frame.");
        }
        m_sTermsOfUse = sTermsOfUse;
    
public USERID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // text encoding
            m_oTextEncoding = TextEncoding.getTextEncoding(oFrameDataID3DIS.readUnsignedByte());
            // language
            byte[] abyLanguage = new byte[3];
            oFrameDataID3DIS.readFully(abyLanguage);
            m_sLanguage = new String(abyLanguage);
            // terms of use (to end of frame)
            byte[] abyTermsOfUse = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(abyTermsOfUse);
            m_sTermsOfUse = new String(abyTermsOfUse, m_oTextEncoding.getEncodingString());
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof USERID3V2Frame)))
        {
            return false;
        }
        
        USERID3V2Frame oOtherUSER = (USERID3V2Frame)oOther;
        
        return (m_oTextEncoding.equals(oOtherUSER.m_oTextEncoding) &&
                m_sLanguage.equals(oOtherUSER.m_sLanguage) &&
                m_sTermsOfUse.equals(oOtherUSER.m_sTermsOfUse));
    
protected byte[]getFrameId()

        return "USER".getBytes();
    
public java.lang.StringgetLanguage()
Get the language of the terms of use.

return
the three letter language code

        return m_sLanguage;
    
public java.lang.StringgetTermsOfUse()
Get the terms of use for this file.

return
the terms of use

        return m_sTermsOfUse;
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the terms of use in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public voidsetTermsOfUse(java.lang.String sLanguage, java.lang.String sTermsOfUse)
Set the terms of use.

param
sLanguage a three character code specifying the language of the terms of use
param
sTermsOfUse the terms of use for this recording or file
throws
ID3Exception if the language is not in a valid format, or if the terms of use are not specified

        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("Language must be a three character length string in USER frame.");
        }
        m_sLanguage = sLanguage;
        if ((sTermsOfUse == null) || (sTermsOfUse.length() == 0))
        {
            throw new ID3Exception("Terms of use are required in USER frame.");
        }
        m_sTermsOfUse = sTermsOfUse;
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the terms of use 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 "Terms of use: Language=[" + m_sLanguage +
               "], Terms of use=[" + m_sTermsOfUse + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        oIDOS.write(m_oTextEncoding.getEncodingValue()); // text encoding
        oIDOS.write(m_sLanguage.getBytes());   // language
        oIDOS.write(m_sTermsOfUse.getBytes(m_oTextEncoding.getEncodingString()));  // terms of use