net.sourceforge.jsdp
Class SDPFactory

java.lang.Object
  extended by net.sourceforge.jsdp.SDPFactory

public class SDPFactory
extends Object

The SDPFactory enables to encode and decode SDP messages.

Since:
1.0
Author:
Claudio Di Vita

Field Summary
static String DEFAULT_CHARSET
          The default charset used for session description encoding: UTF-8
 
Constructor Summary
SDPFactory()
           
 
Method Summary
static Attribute createAttribute(String name)
          Returns a new Attribute
static Attribute createAttribute(String name, String value)
          Returns a new Attribute
static Bandwith createBandwith(String modifier, int value)
          Returns a new Bandwith.
static Connection createConnection(String resource)
          Returns a new Connection.
static Email createEmail(String info)
          Returns a new Email.
static Information createInformation(String value)
          Returns a new Information.
static Key createKey(String method, String key)
          Returns a new Key.
static Media createMedia(String media, int port, int portsCount, String protocol, String format)
          Returns a new Media.
static Media createMedia(String media, int port, String protocol, String format)
          Returns a new Media.
static Origin createOrigin()
          Returnss a new Origin.
static Origin createOrigin(long sessionVersion, String address)
          Returns a new Origin.
static Origin createOrigin(String address)
          Returns a new Origin.
static Origin createOrigin(String user, long sessionID, long sessionVersion, String address)
          Returns a new Origin.
static Origin createOrigin(String user, long sessionVersion, String address)
          Returns a new Origin.
static Phone createPhone(String number)
          Returns a new Phone.
static RepeatTime createRepeatTime(long repeatInterval, long activeDuration, long offset)
          Returns a new RepeatTime.
static RepeatTime createRepeatTime(long repeatInterval, long activeDuration, long[] offsets)
          Returns a new RepeatTime.
static SessionDescription createSessionDescription()
          Returns a new, empty, SessionDescrition.
static SessionName createSessionName()
          Returns a new SessionName.
static SessionName createSessionName(String value)
          Returns a new SessionName.
static Time createTime()
          Returns a new Time.
static Time createTime(Date start, Date stop)
          Returns a new Time.
static Time createTime(long start, long stop)
          Returns a new Time.
static TimeZone createTimeZone(Date time, long offset)
          Returns a new TimeZone.
static Uri createUri(String url)
          Returns a new Uri.
static Uri createUri(URL url)
          Creates a new Uri.
static Version createVersion()
          Returns a Version.
static void encode(SessionDescription sd, OutputStream stream)
          Write a SessionDescription to an output stream, using the default enconding.
static void encode(SessionDescription sd, String encoding, OutputStream stream)
          Write a SessionDescription to an output stream, using a specified encoding.
static SessionDescription parseSessionDescription(File file)
          Reads data from a file and constructs the equivalent SessionDescription.
static SessionDescription parseSessionDescription(InputStream stream)
          Reads data from a stream and constructs the equivalent SessionDescription.
static SessionDescription parseSessionDescription(String input)
          Parse an input string and constructs the equivalent SessionDescription.
static SessionDescription parseSessionDescription(String[] fields)
          Parse the strings contained in an array and constructs the equivalent SessionDescription.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
The default charset used for session description encoding: UTF-8

See Also:
Constant Field Values
Constructor Detail

SDPFactory

public SDPFactory()
Method Detail

createAttribute

public static Attribute createAttribute(String name)
                                 throws SDPException
Returns a new Attribute

Parameters:
name - the attribute name
Returns:
a new Attribute instance
Throws:
SDPException - if the name specified is not valid

createAttribute

public static Attribute createAttribute(String name,
                                        String value)
                                 throws SDPException
Returns a new Attribute

Parameters:
name - the attribute name
value - the attribute value
Returns:
a new Attribute instance
Throws:
SDPException - if the name or the value specified are not valid

createBandwith

public static Bandwith createBandwith(String modifier,
                                      int value)
                               throws SDPException
Returns a new Bandwith.

Parameters:
modifier - the bandwith modifier
value - the bandwith value in kbits/second
Returns:
a new Bandwith instance
Throws:
SDPException - if the modifier is unknown, or the value is negative

createConnection

public static Connection createConnection(String resource)
                                   throws SDPException
Returns a new Connection.

Parameters:
resource - the network address on which media can be received. The address type associated with this connection depends by address value
Returns:
a new Connection instance
Throws:
SDPException - if the network address is not valid

createEmail

public static Email createEmail(String info)
                         throws SDPException
Returns a new Email.

Parameters:
info - the contact information
Returns:
a new Email instance
Throws:
SDPException - if the contact information are not valid

createInformation

public static Information createInformation(String value)
                                     throws SDPException
Returns a new Information.

Parameters:
value - the information about the session
Returns:
a new Information instance
Throws:
SDPException - if the characters of the information are not allowed

createKey

public static Key createKey(String method,
                            String key)
                     throws SDPException
Returns a new Key.

Parameters:
method - the encryption method
key - the encryption key
Returns:
a new Key instance
Throws:
SDPException - if the encryption method is not allowed, or the encryption key is not valid for the specified method

createMedia

public static Media createMedia(String media,
                                int port,
                                int portsCount,
                                String protocol,
                                String format)
                         throws SDPException
Returns a new Media.

Parameters:
media - the media type
port - the transport port to which the media stream will be sent
portsCount - the number of transport ports where the media stream will be sent
protocol - the transport protocol
format - the media default format
Returns:
a new Media instance
Throws:
SDPException - if the parameters are not valid

createMedia

public static Media createMedia(String media,
                                int port,
                                String protocol,
                                String format)
                         throws SDPException
Returns a new Media.

Parameters:
media - the media type
port - the transport port to which the media stream will be sent
protocol - the transport protocol
format - the media default format
Returns:
a new Media instance
Throws:
SDPException - if the parameters are not valid

createOrigin

public static Origin createOrigin()
                           throws SDPException
Returnss a new Origin. The values are sets as follows:

o=<user> <current time as NTP> <current time as NTP> <localhost name>

The <user> value is the name of the OS user that invokes this method.

Returns:
a new Origin instance
Throws:
SDPException - if no IP address for the local host could be found, or the current user name contains characters that are not allowed

createOrigin

public static Origin createOrigin(long sessionVersion,
                                  String address)
                           throws SDPException
Returns a new Origin. The session id was generated automatically using NTP and the user value is set with the name of the OS user that invokes this method.

Parameters:
sessionVersion - the session version
address - the session originator host address
Returns:
a new Origin instance
Throws:
SDPException - if one or more parameter provided are not valid

createOrigin

public static Origin createOrigin(String address)
                           throws SDPException
Returns a new Origin. Both session identifier and session version were generated automatically using NTP and the user value is set with the name of the OS user that invokes this method.

Parameters:
address - the session originator host address
Returns:
a new Origin instance
Throws:
SDPException - if the address is not valid

createOrigin

public static Origin createOrigin(String user,
                                  long sessionID,
                                  long sessionVersion,
                                  String address)
                           throws SDPException
Returns a new Origin.

Parameters:
user - the name of the session originator
sessionID - the session identifier
sessionVersion - the session version
address - the session originator host address
Returns:
a new Origin instance
Throws:
SDPException - if one or more parameter provided are not valid

createOrigin

public static Origin createOrigin(String user,
                                  long sessionVersion,
                                  String address)
                           throws SDPException
Returns a new Origin.

Parameters:
user - the name of the session originator
sessionVersion - the session version
address - the session originator host address
Returns:
a new Origin instance
Throws:
SDPException - if one or more parameter provided are not valid

createPhone

public static Phone createPhone(String number)
                         throws SDPException
Returns a new Phone.

Parameters:
number - the phone number
Returns:
a new Phone instance
Throws:
SDPException - if the phone number is not valid

createRepeatTime

public static RepeatTime createRepeatTime(long repeatInterval,
                                          long activeDuration,
                                          long offset)
                                   throws SDPException
Returns a new RepeatTime.

Parameters:
repeatInterval - the repeat interval
activeDuration - the active duration
offset - the offset
Returns:
a new RepeatTime instance
Throws:
SDPException - if the parameters are not valid

createRepeatTime

public static RepeatTime createRepeatTime(long repeatInterval,
                                          long activeDuration,
                                          long[] offsets)
                                   throws SDPException
Returns a new RepeatTime.

Parameters:
repeatInterval - the repeat interval
activeDuration - the active duration
offsets - the offsets
Returns:
a new RepeatTime instance
Throws:
SDPException - if the parameters are not valid

createSessionDescription

public static SessionDescription createSessionDescription()
                                                   throws SDPException
Returns a new, empty, SessionDescrition. The session values are set as follows:

v=0
o=<user> <current time as NTP> <current time as NTP> <localhost name>
s=-
t=0 0

The <user> value is the name of the OS user that invokes this method.

Returns:
a new SessionDescription
Throws:
SDPException - if there is a problem while constructing the SessionDescription

createSessionName

public static SessionName createSessionName()
Returns a new SessionName. The name value is set to -.

Returns:
a new SessionName instance

createSessionName

public static SessionName createSessionName(String value)
                                     throws SDPException
Returns a new SessionName.

Parameters:
value - the name of the session
Returns:
a new SessionName instance
Throws:
SDPException - if the characters of the session name are not allowed

createTime

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

Returns:
a new Time instance

createTime

public static Time createTime(Date start,
                              Date stop)
                       throws SDPException
Returns a new Time.

Parameters:
start - the session start time
stop - the session stop time
Returns:
a new Time instance
Throws:
SDPException - if the NTP representation of the session start and/or stop time are negative

createTime

public static Time createTime(long start,
                              long stop)
                       throws SDPException
Returns a new Time.

Parameters:
start - the session start time
stop - the session stop time
Returns:
a new Time instance
Throws:
SDPException - if the session start or stop time are negative

createTimeZone

public static TimeZone createTimeZone(Date time,
                                      long offset)
                               throws SDPException
Returns a new TimeZone.

Parameters:
time - the adjustment time
offset - the offset
Returns:
a new TimeZone instance
Throws:
SDPException - if the NTP representation of the adjustment time is negative

createUri

public static Uri createUri(String url)
                     throws SDPException
Returns a new Uri.

Parameters:
url - the uri value
Returns:
a new Uri instance
Throws:
SDPException - if the value specified is a not valid uri

createUri

public static Uri createUri(URL url)
Creates a new Uri.

Parameters:
url - the resource url
Returns:
a new Uri instance

createVersion

public static Version createVersion()
Returns a Version.

Returns:
a Version instance

encode

public static void encode(SessionDescription sd,
                          OutputStream stream)
                   throws IOException
Write a SessionDescription to an output stream, using the default enconding.

Parameters:
sd - the session description to write
stream - the stream where write to
Throws:
IOException - if an I/O error occurs

encode

public static void encode(SessionDescription sd,
                          String encoding,
                          OutputStream stream)
                   throws IOException
Write a SessionDescription to an output stream, using a specified encoding.

Parameters:
sd - the session description to write
encoding - the charset encoding to use
stream - the stream where write to
Throws:
IOException - if an I/O error occurs

parseSessionDescription

public static SessionDescription parseSessionDescription(File file)
                                                  throws SDPParseException,
                                                         IOException
Reads data from a file and constructs the equivalent SessionDescription.

Parameters:
file - the source file
Returns:
a SessionDescription that contains the data readed from the source file
Throws:
SDPParseException - if an error occurs while parsing
IOException - if an I/O error occurs

parseSessionDescription

public static SessionDescription parseSessionDescription(InputStream stream)
                                                  throws SDPParseException,
                                                         IOException
Reads data from a stream and constructs the equivalent SessionDescription.

Parameters:
stream - the input stream
Returns:
a SessionDescription that contains the data readed from the stream
Throws:
SDPParseException - if an error occurs while parsing
IOException - if an I/O error occurs

parseSessionDescription

public static SessionDescription parseSessionDescription(String input)
                                                  throws SDPParseException
Parse an input string and constructs the equivalent SessionDescription.

Parameters:
input - the string to parse
Returns:
a new SessionDescription
Throws:
SDPParseException - if an error occurs while parsing

parseSessionDescription

public static SessionDescription parseSessionDescription(String[] fields)
                                                  throws SDPParseException
Parse the strings contained in an array and constructs the equivalent SessionDescription. Each array element represents a SDP field, so the order of the elements is important.

Parameters:
fields - the string array that stores the SDP fields
Returns:
a new SessionDescription
Throws:
SDPParseException - if an error occurs while parsing


Copyright © 2004-2008. All Rights Reserved.