FileDocCategorySizeDatePackage
URLDataSource.javaAPI DocGlassfish v2 API5072Mon May 14 15:29:52 BST 2007javax.activation

URLDataSource

public class URLDataSource extends Object implements DataSource
The URLDataSource class provides an object that wraps a URL object in a DataSource interface. URLDataSource simplifies the handling of data described by URLs within the JavaBeans Activation Framework because this class can be used to create new DataHandlers. NOTE: The DataHandler object creates a URLDataSource internally, when it is constructed with a URL.
see
javax.activation.DataSource
see
javax.activation.DataHandler

Fields Summary
private URL
url
private URLConnection
url_conn
Constructors Summary
public URLDataSource(URL url)
URLDataSource constructor. The URLDataSource class will not open a connection to the URL until a method requiring it to do so is called.

param
url The URL to be encapsulated in this object.


                                          
       
	this.url = url;
    
Methods Summary
public java.lang.StringgetContentType()
Returns the value of the URL content-type header field. It calls the URL's URLConnection.getContentType method after retrieving a URLConnection object. Note: this method attempts to call the openConnection method on the URL. If this method fails, or if a content type is not returned from the URLConnection, getContentType returns "application/octet-stream" as the content type.

return
the content type.

	String type = null;

	try {
	    if (url_conn == null)
		url_conn = url.openConnection();
	} catch (IOException e) { }
	
	if (url_conn != null)
	    type = url_conn.getContentType();

	if (type == null)
	    type = "application/octet-stream";
	
	return type;
    
public java.io.InputStreamgetInputStream()
The getInputStream method from the URL. Calls the openStream method on the URL.

return
the InputStream.

	return url.openStream();
    
public java.lang.StringgetName()
Calls the getFile method on the URL used to instantiate the object.

return
the result of calling the URL's getFile method.

	return url.getFile();
    
public java.io.OutputStreamgetOutputStream()
The getOutputStream method from the URL. First an attempt is made to get the URLConnection object for the URL. If that succeeds, the getOutputStream method on the URLConnection is returned.

return
the OutputStream.

	// get the url connection if it is available
	url_conn = url.openConnection();
	
	if (url_conn != null) {
	    url_conn.setDoOutput(true);
	    return url_conn.getOutputStream();
	} else
	    return null;
    
public java.net.URLgetURL()
Return the URL used to create this DataSource.

return
The URL.

	return url;