001: /*
002: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024: package com.sun.mmedia.rtsp;
025:
026: import java.io.IOException;
027:
028: /**
029: * Encapsulates an RTSP URL of the form rtsp://host:port/file.
030: *
031: * @author Marc Owerfeldt
032: * @created June 7, 2003
033: */
034: public class RtspUrl {
035: /**
036: * The RTSP URL.
037: */
038: private String url;
039:
040: /**
041: * Constructor for the RtspUrl object
042: *
043: * @param url The RTSP URL to be parsed.
044: * @exception IOException Thows an IOException if the URL cannot
045: * be parsed as a valid RTP URL.
046: */
047: public RtspUrl(String url) throws IOException {
048: this .url = url;
049:
050: if (url.length() < 7) {
051: throw new IOException("Malformed URL");
052: }
053:
054: if (!url.startsWith("rtsp://")) {
055: throw new IOException("Malformed URL");
056: }
057: }
058:
059: /**
060: * Gets the file attribute of the RtspUrl object.
061: *
062: * @return The file value
063: */
064: public String getFile() {
065: String str = url.substring(7);
066:
067: int start = str.indexOf('/');
068:
069: String file = "";
070:
071: if (start != -1) {
072: file = str.substring(start + 1);
073: }
074:
075: return file;
076: }
077:
078: /**
079: * Gets the host attribute of the RtspUrl object.
080: *
081: * @return The host value
082: */
083: public String getHost() {
084: String host = null;
085:
086: String str = url.substring(7);
087:
088: int end = str.indexOf(':');
089:
090: if (end == -1) {
091: end = str.indexOf('/');
092:
093: if (end == -1) {
094: host = str;
095: } else {
096: host = str.substring(0, end);
097: }
098: } else {
099: host = str.substring(0, end);
100: }
101:
102: return host;
103: }
104:
105: /**
106: * Gets the port attribute of the RtspUrl object
107: *
108: * @return The port value
109: */
110: public int getPort() {
111: int port = 554;
112: // default port for RTSP
113:
114: String str = url.substring(7);
115:
116: int start = str.indexOf(':');
117:
118: if (start != -1) {
119: int end = str.indexOf('/');
120:
121: port = Integer.parseInt(str.substring(start + 1, end));
122: }
123:
124: return port;
125: }
126: }
|