FileDocCategorySizeDatePackage
URLDataSource.javaAPI DocJMF 2.1.1e4284Mon May 12 12:20:42 BST 2003javax.media.protocol

URLDataSource

public class URLDataSource extends PullDataSource
A default data-source created directly from a URL using URLConnection.

Fields Summary
protected URLConnection
conn
protected ContentDescriptor
contentType
protected URLSourceStream[]
sources
protected boolean
connected
Constructors Summary
protected URLDataSource()
Implemented by subclasses.

    
public URLDataSource(URL url)
Construct a URLDataSource directly from a URL.

	setLocator(new MediaLocator(url));
	connected = false;
    
Methods Summary
public voidconnect()
Initialize the connection with the source.

exception
IOException Thrown if there are problems setting up the connection.

	
	// Make the connect.
	conn = getLocator().getURL().openConnection();
	conn.connect();
	connected = true;

	// Figure out the content type.
	String mimeType = conn.getContentType();
	if( mimeType == null) {
	    mimeType = ContentDescriptor.CONTENT_UNKNOWN;
	}
	contentType = new ContentDescriptor(
			   ContentDescriptor.mimeTypeToPackageName(mimeType));

	// Create a source stream.
	sources = new URLSourceStream[1];
	sources[0] = new URLSourceStream(conn, contentType);
	
    
public voiddisconnect()
Disconnect the source.

	if(connected) {
	    try {
		sources[0].close();
	    } catch(IOException e) {
		// There really isn't anything we can do
		// if close throws an exception.
		// so we'll eat it.
	    }
	    connected = false;
	}
    
public java.lang.StringgetContentType()
Return the content type name.

return
The content type name.

       // $jdr: We could probably get away with
       // not doing anything here, and connecting on
       // creation, given that this protocol is pretty
       // "connection-less".
       if( !connected) {
	   throw new java.lang.Error("Source is unconnected.");
       }
       return contentType.getContentType();
    
public java.lang.ObjectgetControl(java.lang.String controlName)
Returns null, because this source doesn't provide any controls.

	return null;
    
public java.lang.Object[]getControls()
Returns an empty array, because this source doesn't provide any controls.

return
empty Object array.

	return new Object[0];
    
public javax.media.TimegetDuration()
Returns Duration.DURATION_UNKNOWN. The duration is not available from an InputStream.

return
Duration.DURATION_UNKNOWN.

	return Duration.DURATION_UNKNOWN;
    
public javax.media.protocol.PullSourceStream[]getStreams()

	// $jdr: Is this necessary? See getContentType().
	if( !connected) {
	    throw new java.lang.Error("Unconnected source.");
	}
	return sources;
    
public voidstart()

       // Nothing to do here either.
    
public voidstop()
Stops the

       // sure.