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 Jakarta Activation because this class can be used to create new DataHandlers. NOTE: The DataHandler object creates a UR
| 28 | * @see javax.activation.DataHandler |
| 29 | */ |
| 30 | public class URLDataSource implements DataSource { |
| 31 | private URL url = null; |
| 32 | private URLConnection url_conn = null; |
| 33 | |
| 34 | /** |
| 35 | * URLDataSource constructor. The URLDataSource class will |
| 36 | * not open a connection to the URL until a method requiring it |
| 37 | * to do so is called. |
| 38 | * |
| 39 | * @param url The URL to be encapsulated in this object. |
| 40 | */ |
| 41 | public URLDataSource(URL url) { |
| 42 | this.url = url; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the value of the URL content-type header field. |
| 47 | * It calls the URL's <code>URLConnection.getContentType</code> method |
| 48 | * after retrieving a URLConnection object. |
| 49 | * <i>Note: this method attempts to call the <code>openConnection</code> |
| 50 | * method on the URL. If this method fails, or if a content type is not |
| 51 | * returned from the URLConnection, getContentType returns |
| 52 | * "application/octet-stream" as the content type.</i> |
| 53 | * |
| 54 | * @return the content type. |
| 55 | */ |
| 56 | public String getContentType() { |
| 57 | String type = null; |
| 58 | |
| 59 | try { |
| 60 | if (url_conn == null) |
| 61 | url_conn = url.openConnection(); |
| 62 | } catch (IOException e) { } |
| 63 | |
| 64 | if (url_conn != null) |
| 65 | type = url_conn.getContentType(); |
| 66 | |
| 67 | if (type == null) |
| 68 | type = "application/octet-stream"; |
| 69 | |
| 70 | return type; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Calls the <code>getFile</code> method on the URL used to |
| 75 | * instantiate the object. |
| 76 | * |
| 77 | * @return the result of calling the URL's getFile method. |
| 78 | */ |
| 79 | public String getName() { |
| 80 | return url.getFile(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * The getInputStream method from the URL. Calls the |
| 85 | * <code>openStream</code> method on the URL. |
| 86 | * |
| 87 | * @return the InputStream. |
nothing calls this directly
no outgoing calls
no test coverage detected