FileDocCategorySizeDatePackage
TIMETextInformationID3V2Frame.javaAPI Docjid3 0.465725Sun Feb 06 18:11:18 GMT 2005org.blinkenlights.jid3.v2

TIMETextInformationID3V2Frame

public class TIMETextInformationID3V2Frame extends TextInformationID3V2Frame
author
paul Text frame containing time information.

Fields Summary
private int
m_iHours
private int
m_iMinutes
Constructors Summary
public TIMETextInformationID3V2Frame(int iHours, int iMinutes)
Constructor.

param
iHours the hour value
param
iMinutes the minute value
throws
ID3Exception if an invalid hour or minute value is specified

        // make sure the values we've been given for hours and minutes are legal
        if ((iHours < 0) || (iHours > 24) || (iMinutes < 0) || (iMinutes > 59))
        {
            throw new ID3Exception("Hours and minutes must each be two digits or less.");
        }
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        NumberFormat oNF = new DecimalFormat("00");
        m_sInformation = oNF.format(iHours) + oNF.format(iMinutes);
        
        m_iHours = iHours;
        m_iMinutes = iMinutes;
    
public TIMETextInformationID3V2Frame(InputStream oIS)

        super(oIS);
        
        // convert information string to ISO-8859-1 encoding before parsing (we only accept ISO-8559-1 chars anyway)
        byte[] abyInformation = null;
        try
        {
            abyInformation = m_sInformation.getBytes("ISO-8859-1");
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception("Encountered a TIME frame in which the time digits cannot be parsed.", e);
        }

        // time must be four characters
        if (abyInformation.length != 4)
        {
            throw new InvalidFrameID3Exception("Encountered a corrupt TIME frame with time string length not equal to four.");
        }
        
        // try to parse hours and minutes (we aren't going to require valid times when reading from a file,
        // but they do have to be numbers)
        try
        {
            byte[] abyHours = { abyInformation[0], abyInformation[1] };
            byte[] abyMinutes = { abyInformation[2], abyInformation[3] };

            m_iHours = Integer.parseInt(new String(abyHours));
            m_iMinutes = Integer.parseInt(new String(abyMinutes));
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception("Encountered a corrupt TIME frame.", e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

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

        if ((oOther == null) || (!(oOther instanceof TIMETextInformationID3V2Frame)))
        {
            return false;
        }
        
        TIMETextInformationID3V2Frame oOtherTIME = (TIMETextInformationID3V2Frame)oOther;
        
        return ((m_iHours == oOtherTIME.m_iHours) &&
                (m_iMinutes == oOtherTIME.m_iMinutes) &&
                m_oTextEncoding.equals(oOtherTIME.m_oTextEncoding) && 
                m_sInformation.equals(oOtherTIME.m_sInformation));
    
protected byte[]getFrameId()

        return "TIME".getBytes();
    
public intgetHours()
Get the hour value.

return
the hour value

        return m_iHours;
    
public intgetMinutes()
Get the minute value.

return
the minute value

        return m_iMinutes;
    
public voidsetTime(int iHours, int iMinutes)
Set the time value.

param
iHours the hour value
param
iMinutes the minute value
throws
ID3Exception if an invalid hour or minute value is specified

        // make sure the values we've been given for hours and minutes are legal
        if ((iHours < 0) || (iHours > 24) || (iMinutes < 0) || (iMinutes > 59))
        {
            throw new ID3Exception("Hours and minutes must each be two digits or less.");
        }
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        NumberFormat oNF = new DecimalFormat("00");
        m_oTextEncoding = TextEncoding.getDefaultTextEncoding();
        m_sInformation = oNF.format(iHours) + oNF.format(iMinutes);
        
        m_iHours = iHours;
        m_iMinutes = iMinutes;
    
public java.lang.StringtoString()

        return "Time (HHMM): [" + m_sInformation + "]";