net.sourceforge.jsdp
Class Time

java.lang.Object
  extended by net.sourceforge.jsdp.Time
All Implemented Interfaces:
Serializable, Cloneable, Field

public class Time
extends Object
implements Field

A Time represents a t=<field value> field contained in a SDP message. A time field specifies the start and stop times for a SDP announce.

Since:
0.1.0
Version:
1.0
Author:
Claudio Di Vita
See Also:
Serialized Form

Field Summary
static long NTP_CONSTANT
          Constant used to translate between NTP time used in SDP and "native" Java time.
protected  long start
          The session start time
protected  long stop
          The session stop time
 
Fields inherited from interface net.sourceforge.jsdp.Field
ATTRIBUTE_FIELD, BANDWITH_FIELD, CONNECTION_FIELD, EMAIL_FIELD, END_OF_FIELD, INFORMATION_FIELD, KEY_FIELD, MEDIA_FIELD, ORIGIN_FIELD, PHONE_FIELD, REPEAT_TIME_FIELD, SESSION_NAME_FIELD, TIME_FIELD, TIMEZONE_FIELD, URI_FIELD, VERSION_FIELD
 
Constructor Summary
Time()
          Creates a new Time.
Time(Date start, Date stop)
          Creates a new Time.
Time(long start, long stop)
          Creates a new Time.
 
Method Summary
 Object clone()
          Returns a clone of this field.
static Date getDateFromNtp(long ntpTime)
          Returns a Date object for a given NTP date value.
static long getNTP(Date date)
          Transform a Date in a long containing the corresponding NTP value.
 Date getStartTime()
          Returns the start time of the session.
 Date getStopTime()
          Returns the stop time of the session.
 char getType()
          Returns the type character for the field.
static boolean isValidNTP(String input)
          Indicates if a string represents a valid NTP value.
 boolean isZero()
          Returns whether the start and stop times were set to zero (in NTP).
static Time parse(String field)
          Parse an input string and constructs the equivalent time field.
 void setStartTime(Date start)
          Sets the start time of the session.
 void setStartTime(long start)
          Sets the start time of the session.
 void setStopTime(Date stop)
          Sets the stop time of the session.
 void setStopTime(long stop)
          Sets the stop time of the session.
 void setZero()
          Sets the start and stop times to zero (in NTP).
 String toString()
          Returns a string representation of the field.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NTP_CONSTANT

public static final long NTP_CONSTANT
Constant used to translate between NTP time used in SDP and "native" Java time. NTP time is defined as the number of seconds relative to midnight, January 1, 1900 and Java time is measured in number of milliseconds since midnight, January 1, 1970 UTC (see System.currentTimeMillis()).

The value of this constant is 2208988800L. It can be used to convert between NTP and Java time using the following formulas:

The Network Time Protocol (NTP) is defined in RFC 1305.

See Also:
Constant Field Values

start

protected long start
The session start time


stop

protected long stop
The session stop time

Constructor Detail

Time

public Time()
Creates a new Time. The session start and stop time are set to zero.


Time

public Time(Date start,
            Date stop)
     throws SDPException
Creates a new Time.

Parameters:
start - the session start time
stop - the session stop time
Throws:
SDPException - if the NTP representation of the session start and/or stop time are negative

Time

public Time(long start,
            long stop)
     throws SDPException
Creates a new Time.

Parameters:
start - the session start time
stop - the session stop time
Throws:
SDPException - if the session start or stop time are negative
Method Detail

getDateFromNtp

public static Date getDateFromNtp(long ntpTime)
Returns a Date object for a given NTP date value.

Parameters:
ntpTime - the NTP date value
Returns:
a new Date instance that represents the given NTP date value

getNTP

public static long getNTP(Date date)
Transform a Date in a long containing the corresponding NTP value.

Parameters:
date - the Date to transform
Returns:
the NTP value of the given date

isValidNTP

public static boolean isValidNTP(String input)
Indicates if a string represents a valid NTP value.

Parameters:
input - the string to test
Returns:
true if the specified string represents a valid NTP value, false otherwise

parse

public static Time parse(String field)
                  throws SDPParseException
Parse an input string and constructs the equivalent time field.

Parameters:
field - the string to parse
Returns:
a new Time instance
Throws:
SDPParseException - if an error occurs while parsing

clone

public Object clone()
Returns a clone of this field.

Specified by:
clone in interface Field
Overrides:
clone in class Object
Returns:
a clone of this field

getStartTime

public Date getStartTime()
Returns the start time of the session.

Returns:
the start time of the session

getStopTime

public Date getStopTime()
Returns the stop time of the session.

Returns:
the stop time of the session

getType

public char getType()
Returns the type character for the field.

Specified by:
getType in interface Field
Returns:
the field type character: t

isZero

public boolean isZero()
Returns whether the start and stop times were set to zero (in NTP).

Returns:
true if the start and stop times are set to zero, false otherwise

setStartTime

public void setStartTime(Date start)
                  throws SDPException
Sets the start time of the session.

Parameters:
start - the start time
Throws:
SDPException - if the date is null or if his NTP representation is negative

setStartTime

public void setStartTime(long start)
                  throws SDPException
Sets the start time of the session.

Parameters:
start - The start time
Throws:
SDPException - If the start time is negative

setStopTime

public void setStopTime(Date stop)
                 throws SDPException
Sets the stop time of the session.

Parameters:
stop - the stop time
Throws:
SDPException - if the date is null or his NTP representation is negative

setStopTime

public void setStopTime(long stop)
                 throws SDPException
Sets the stop time of the session.

Parameters:
stop - the stop time
Throws:
SDPException - if the stop time is negative

setZero

public void setZero()
Sets the start and stop times to zero (in NTP).


toString

public String toString()
Returns a string representation of the field. The representation has the form: t=<start time> <stop time>.

Specified by:
toString in interface Field
Overrides:
toString in class Object
Returns:
the string representation of the field


Copyright © 2004-2008. All Rights Reserved.