cgl.narada.service.time.ntptime
Class NtpTimestamp

java.lang.Object
  extended by cgl.narada.service.time.ntptime.NtpTimestamp

public class NtpTimestamp
extends Object

1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Seconds | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Seconds Fraction (0-padded) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ This class encapsulates the notion of a timestamp as in rfc2030. Logically it is the number of seconds since the beginning of the centure (in UTC time). It is represented as an 8 byte array, the first four bytes representing seconds and the next 4 bytes representing second fractions.


Constructor Summary
NtpTimestamp()
          This constructs a timestamp initialized with the current updated date.
NtpTimestamp(int offset, byte[] data)
          This constructs a timestamp initialized with the data passed.
 
Method Summary
 Date getTime()
          Gets the date associated to this NtpTimestamp.
 long getTimeInMilliSeconds()
          Gets the millisecond value of this NtpTimestamp
 byte[] getTimestampData()
          Returns timestamp data which keeps the time information in byte array format.
 void setTimestamp(Date date)
          Sets the NtpTimestamp with the given Date object
 void setTimestamp(int offset, byte[] data)
          Sets the timestamp with the given byte array and the start offset within the array.
 void setTimestampData(byte[] timestampData)
          Initializes the data of the NtpTimestamp with the given byte array
 String toString()
          Converts the date object to String format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NtpTimestamp

public NtpTimestamp()
This constructs a timestamp initialized with the current updated date. Date is updated using the offset value between the local machine and atomic time servers.


NtpTimestamp

public NtpTimestamp(int offset,
                    byte[] data)
This constructs a timestamp initialized with the data passed.

Parameters:
offset - int - data is read starting from offset value
data - byte [] - byte array that contains timestamp information
Method Detail

getTime

public Date getTime()
Gets the date associated to this NtpTimestamp.

Returns:
Date - Date object of this NtpTimestamp

getTimeInMilliSeconds

public long getTimeInMilliSeconds()
Gets the millisecond value of this NtpTimestamp

Returns:
long - time value in milliseconds

setTimestamp

public void setTimestamp(Date date)
Sets the NtpTimestamp with the given Date object

Parameters:
date - Date - NtpTimestamp is initialized with this Date object

setTimestamp

public void setTimestamp(int offset,
                         byte[] data)
Sets the timestamp with the given byte array and the start offset within the array. Byte array should have size of offset+8 at least.

Parameters:
offset - int - start offset within the given byte array
data - byte [] - contains NtpTimestamp information.

setTimestampData

public void setTimestampData(byte[] timestampData)
Initializes the data of the NtpTimestamp with the given byte array

Parameters:
timestampData - byte [] - data of NtpTimestamp is initialized with this byte array

getTimestampData

public byte[] getTimestampData()
Returns timestamp data which keeps the time information in byte array format.

Returns:
byte [] - data of NtpTimestamp

toString

public String toString()
Converts the date object to String format.

Overrides:
toString in class Object
Returns:
String - String format representing date with fractional part


For comments and suggestions please send e-mail to The NaradaBrokering Project