Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.javax.sdp.fields;
 import javax.sdp.*;
 import java.util.*;
Media field SDP header.

Author(s):
Olivier Deruelle <deruelle@antd.nist.gov>
M. Ranganathan
Version:
JSR141-PUBLIC-REVIEW (subject to change).
 
 public class MediaField extends SDPField implements Media {
     protected String media;
     protected int port;
     protected int nports;
     protected String proto;
     protected Vector formats;
 
     public MediaField() {
         super(.);
          = new Vector();
     }
 
     public String getMedia() {
         return ;
     }
     public int getPort() {
         return ;
     }
     public int getNports() {
         return ;
     }
     public String getProto() {
         return ;
     }
     public Vector getFormats() {
         return ;
     }
    
Set the media member
 
     public void setMedia(String m) {
          = m;
     }
    
Set the port member
 
     public void setPort(int p) {
          = p;
     }
    
Set the nports member
 
     public void setNports(int n) {
          = n;
     }
    
Set the proto member
 
     public void setProto(String p) {
          = p;
     }
    
Set the fmt member
 
     public void setFormats(Vector formats) {
         this. = formats;
     }
    
Returns the type (audio,video etc) of the media defined by this description.

Returns:
the string media type.
Throws:
javax.sdp.SdpParseException
    public String getMediaType() throws SdpParseException {
        return getMedia();
    }

    
Sets the type (audio,video etc) of the media defined by this description.

Parameters:
mediaType to set
Throws:
javax.sdp.SdpException if mediaType is null
    public void setMediaType(String mediaTypethrows SdpException {
        if (mediaType == null)
            throw new SdpException("The mediaType is null");
        else
            setMedia(mediaType);
    }

    
Returns the port of the media defined by this description

Returns:
the integer media port.
Throws:
javax.sdp.SdpParseException
    public int getMediaPort() throws SdpParseException {
        return getPort();
    }

    
Sets the port of the media defined by this description

Parameters:
port to set
Throws:
javax.sdp.SdpException
    public void setMediaPort(int portthrows SdpException {
        if (port < 0)
            throw new SdpException("The port is < 0");
        else
            setPort(port);
    }

    
Returns the number of ports associated with this media description

Returns:
the integer port count.
Throws:
javax.sdp.SdpParseException
    public int getPortCount() throws SdpParseException {
        return getNports();
    }

    
Sets the number of ports associated with this media description.

Parameters:
portCount portCount - the integer port count.
Throws:
javax.sdp.SdpException
    public void setPortCount(int portCountthrows SdpException {
        if (portCount < 0)
            throw new SdpException("The port count is < 0");
        else
            setNports(portCount);
    }

    
Returns the protocol over which this media should be transmitted.

Returns:
the String protocol, e.g. RTP/AVP.
Throws:
javax.sdp.SdpParseException
    public String getProtocol() throws SdpParseException {
        return getProto();
    }

    
Sets the protocol over which this media should be transmitted.

Parameters:
protocol - the String protocol, e.g. RTP/AVP.
Throws:
javax.sdp.SdpException if the protocol is null
    public void setProtocol(String protocolthrows SdpException {
        if (protocol == null)
            throw new SdpException("The protocol is null");
        else
            setProto(protocol);
    }

    
Returns an Vector of the media formats supported by this description. Each element in this Vector will be an String value which matches one of the a=rtpmap: attribute fields of the media description.

Parameters:
create to set
Returns:
the Vector.
Throws:
javax.sdp.SdpException
    public Vector getMediaFormats(boolean createthrows SdpParseException {
        if (!create && .size() == 0)
            return null;
        else
            return ;
    }

    
Adds a media format to the media description. Each element in this Vector should be an String value which matches one of the a=rtpmap: attribute fields of the media description.

Parameters:
mediaFormats the format to add.
Throws:
javax.sdp.SdpException if the vector is null
    public void setMediaFormats(Vector mediaFormatsthrows SdpException {
        if (mediaFormats == null)
            throw new SdpException("The mediaFormats is null");
        this. = mediaFormats;
    }
    private String encodeFormats() {
    StringBuilder retval = new StringBuilder(3 * .size ());
        for (int i = 0; i < .size(); i++) {
            retval.append(.elementAt(i));
            if (i < .size() - 1)
                retval.append(.);
        }
        return retval.toString();
    }

    
Get the string encoded version of this object

Since:
v1.0
    public String encode() {
        String encoded_string;
        encoded_string = ;
        if ( != null)
            encoded_string += .toLowerCase() + . + ;
        // Workaround for Microsoft Messenger contributed by Emil Ivov
        // Leave out the nports parameter as this confuses the messenger.
        if ( > 1)
            encoded_string += . + ;
        if ( != null)
            encoded_string += . + ;
        if ( != null)
            encoded_string += . + encodeFormats();
        encoded_string += .;
        return encoded_string;
    }
    public Object clone() {
        MediaField retval = (MediaFieldsuper.clone();
        if (this. != null)
            retval.formats = (Vectorthis..clone();
        return retval;
    }
New to GrepCode? Check out our FAQ X