FileDocCategorySizeDatePackage
USLTID3V2Frame.javaAPI Docjid3 0.468407Sun Feb 06 18:11:17 GMT 2005org.blinkenlights.jid3.v2

USLTID3V2Frame

public class USLTID3V2Frame extends ID3V2Frame
Frame containing unsynchronized lyrics/text transcription.
author
paul

Fields Summary
private TextEncoding
m_oTextEncoding
private String
m_sLanguage
private String
m_sContentDescriptor
private String
m_sLyrics
Constructors Summary
public USLTID3V2Frame(String sLanguage, String sContentDescriptor, String sLyrics)

    
          
         
    
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        if (sLanguage.length() != 3)
        {
            throw new ID3Exception("Language string length must be 3.");
        }
        m_sLanguage = sLanguage;
        m_sContentDescriptor = sContentDescriptor;
        m_sLyrics = sLyrics;
        if (m_sLyrics == null)
        {
            m_sLyrics = "";
        }
    
public USLTID3V2Frame(InputStream oIS)

        // Parse out the text encoding and text string from the raw data
        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);
            
            // content descriptor (read to null)
            m_sContentDescriptor = oFrameDataID3DIS.readStringToNull(m_oTextEncoding);
            
            // lyrics
            byte[] abyLyrics = new byte[oFrameDataID3DIS.available()];
            oFrameDataID3DIS.readFully(abyLyrics);
            m_sLyrics = new String(abyLyrics, m_oTextEncoding.getEncodingString());
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof USLTID3V2Frame)))
        {
            return false;
        }
        
        USLTID3V2Frame oOtherUSLT = (USLTID3V2Frame)oOther;

        return (m_oTextEncoding.equals(oOtherUSLT.m_oTextEncoding) &&
                m_sLanguage.equals(oOtherUSLT.m_sLanguage) &&
                m_sContentDescriptor.equals(oOtherUSLT.m_sContentDescriptor) &&
                m_sLyrics.equals(oOtherUSLT.m_sLyrics));
    
public java.lang.StringgetContentDescriptor()
Get the content descriptor for this frame.

return
the content descriptor

        return m_sContentDescriptor;
    
protected byte[]getFrameId()

        return "USLT".getBytes();
    
public java.lang.StringgetLanguage()
Get the language used in this frame.

return
a three letter language code

        return m_sLanguage;
    
public java.lang.StringgetLyrics()
Get the lyrics for this frame.

return
the lyrics

        return m_sLyrics;
    
public TextEncodinggetTextEncoding()
Get the text encoding used for the content descriptor and lyrics in this frame.

return
the text encoding to be used for this frame

        return m_oTextEncoding;
    
public voidsetContentDescriptor(java.lang.String sContentDescriptor)
Set the content descriptor for this frame.

param
sContentDescriptor the content descriptor for this frame
throws
ID3Exception if the content descriptor is null, or if this frame is in a tag which contains another USLT frame with the same language and content descriptor

        String sOrigContentDescriptor = m_sContentDescriptor;
        
        if (sContentDescriptor == null)
        {
            throw new ID3Exception("Content descriptor is required for USLT frame.");
        }

        m_sContentDescriptor = sContentDescriptor;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sContentDescriptor = sOrigContentDescriptor;
            
            throw e;
        }
    
public voidsetLanguage(java.lang.String sLanguage)
Set the language used in this frame.

param
sLanguage a three letter language code
throws
ID3Exception if the language is null or not three characters in length or if this frame is in a tag which contains another USLT frame with the same language and content descriptor

        String sOrigLanguage = m_sLanguage;
        
        if ((sLanguage == null) || (sLanguage.length() != 3))
        {
            throw new ID3Exception("A three character length language code is required in USLT frame.");
        }

        m_sLanguage = sLanguage;
        
        // try this update, and reverse it if it generates and error
        try
        {
            notifyID3Observers();
        }
        catch (ID3Exception e)
        {
            m_sLanguage = sOrigLanguage;
            
            throw e;
        }
    
public voidsetLyrics(java.lang.String sLyrics)
Set the lyrics for this frame.

param
sLyrics the lyrics for this frame

        if (sLyrics == null)
        {
            m_sLyrics = "";
        }
        m_sLyrics = sLyrics;
    
public voidsetTextEncoding(TextEncoding oTextEncoding)
Set the text encoding to be used for the content descriptor and lyrics 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 "Unsychronized lyrics: Language=[" + m_sLanguage + "], Content descriptor=[" +
               m_sContentDescriptor + "], Lyrics=[" + m_sLyrics + "]";
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // text encoding
        oIDOS.writeUnsignedByte(m_oTextEncoding.getEncodingValue());
        // language
        oIDOS.write(m_sLanguage.getBytes());
        // content descriptor
        if (m_sContentDescriptor != null)
        {
            oIDOS.write(m_sContentDescriptor.getBytes(m_oTextEncoding.getEncodingString()));
        }
        // null separating content descriptor from lyrics
        if (m_oTextEncoding.equals(TextEncoding.ISO_8859_1))
        {
            oIDOS.writeUnsignedByte(0);
        }
        else
        {
            oIDOS.writeUnsignedByte(0);
            oIDOS.writeUnsignedByte(0);
        }
        // lyrics
        oIDOS.write(m_sLyrics.getBytes(m_oTextEncoding.getEncodingString()));