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

ETCOID3V2Frame

public class ETCOID3V2Frame extends ID3V2Frame
author
paul Frame containing event timing codes.

Fields Summary
private TimestampFormat
m_oTimestampFormat
private SortedMap
m_oTimeToEventMap
Constructors Summary
public ETCOID3V2Frame(TimestampFormat oTimestampFormat)
Constructor.

param
oTimestampFormat the format for timestamps, whether by millisecond or frame count
throws
ID3Exception if oTimestampFormat object is null

    
                             
      
         
    
        if (oTimestampFormat == null)
        {
            throw new ID3Exception("Timestamp format required in ETCO frame.");
        }
        m_oTimestampFormat = oTimestampFormat;
        m_oTimeToEventMap = new TreeMap();
    
public ETCOID3V2Frame(InputStream oIS)

        // Parse out the text encoding and text string from the raw data
        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // timestamp format
            m_oTimestampFormat = new TimestampFormat((byte)oFrameDataID3DIS.readUnsignedByte());
            
            // read events and timestamps to end
            m_oTimeToEventMap = new TreeMap();
            while (oFrameDataID3DIS.available() > 0)
            {
                byte byTypeOfEvent = (byte)oFrameDataID3DIS.readUnsignedByte();
                EventType oEventType = new EventType(byTypeOfEvent);
                int iTimestamp = oFrameDataID3DIS.readBE32();
                
                addEvent(new Event(oEventType, iTimestamp));
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitETCOID3V2Frame(this);
    
public voidaddEvent(org.blinkenlights.jid3.v2.ETCOID3V2Frame$Event oEvent)
Add an event to the list. Note, only one event per exact time can be defined. An event set at a time for which another event already is set will overwrite the existing one.

param
oEvent the event being set

        m_oTimeToEventMap.put(new Integer(oEvent.getTimestamp()), oEvent);
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof ETCOID3V2Frame)))
        {
            return false;
        }
        
        ETCOID3V2Frame oOtherETCO = (ETCOID3V2Frame)oOther;
        
        return (m_oTimestampFormat.equals(oOtherETCO.m_oTimestampFormat) &&
                m_oTimeToEventMap.equals(oOtherETCO.m_oTimeToEventMap));
    
public org.blinkenlights.jid3.v2.ETCOID3V2Frame$EventgetEvent(int iTimestamp)
Get the event which has been set for a given time.

return
the event set for the given time, or null if no event has been set for that time
throws
ID3Exception if the timestamp specified is negative

        if (iTimestamp < 0)
        {
            throw new ID3Exception("Negative timestamps are not valid in ETCO frames.");
        }
        
        return (Event)m_oTimeToEventMap.get(new Integer(iTimestamp));
    
public org.blinkenlights.jid3.v2.ETCOID3V2Frame$Event[]getEvents()
Get all events which have been set. Events are returned in sorted order by timestamp.

return
an array of Events which have been set

        return (Event[])m_oTimeToEventMap.values().toArray(new Event[0]);
    
protected byte[]getFrameId()

        return "ETCO".getBytes();
    
public org.blinkenlights.jid3.v2.ETCOID3V2Frame$TimestampFormatgetTimestampFormat()
Get the set timestamp format.

return
the currently set timestamp format

        return m_oTimestampFormat;
    
public org.blinkenlights.jid3.v2.ETCOID3V2Frame$EventremoveEvent(org.blinkenlights.jid3.v2.ETCOID3V2Frame$Event oEvent)
Remove the event set for a specific time.

return
the event which was previously set for the given time, or null if no even was set for that time

        return (Event)m_oTimeToEventMap.remove(new Integer(oEvent.getTimestamp()));
    
public java.lang.StringtoString()

        StringBuffer sbOutput = new StringBuffer();
        sbOutput.append("Event Timing Codes: Timestamp format = " + m_oTimestampFormat.getValue());
        sbOutput.append(", Events = ");
        Iterator oIter = m_oTimeToEventMap.values().iterator();
        while (oIter.hasNext())
        {
            Event oEvent = (Event)oIter.next();
            sbOutput.append(oEvent.getEventType().getValue() + ":" + oEvent.getTimestamp() + " ");
        }

        return sbOutput.toString();
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        // timestamp format
        oIDOS.writeUnsignedByte(m_oTimestampFormat.getValue());

        // events
        Iterator oIter = m_oTimeToEventMap.values().iterator();
        while (oIter.hasNext())
        {
            Event oEvent = (Event)oIter.next();
            oIDOS.writeUnsignedByte(oEvent.getEventType().getValue());
            oIDOS.writeBE32(oEvent.getTimestamp());
        }