Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.activation
Class FileTypeMappedURLDataSource

java.lang.Object
  extended by javax.activation.URLDataSource
      extended by ch.randelshofer.activation.FileTypeMappedURLDataSource
All Implemented Interfaces:
javax.activation.DataSource

public class FileTypeMappedURLDataSource
extends javax.activation.URLDataSource

An extension to URLDataSource which tries to guess the content type of the URL by using the default FileTypeMap when the URLConnection returns 'content/unknown' or 'application/octet-stream'.

Version:
1.0 2002-02-12
Author:
Werner Randelshofer

Constructor Summary
FileTypeMappedURLDataSource(java.net.URL url)
          FileTypeMappedURLDataSource constructor.
 
Method Summary
 java.lang.String getContentType()
          Returns the value of the URL content-type header field.
 
Methods inherited from class javax.activation.URLDataSource
getInputStream, getName, getOutputStream, getURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileTypeMappedURLDataSource

public FileTypeMappedURLDataSource(java.net.URL url)
FileTypeMappedURLDataSource constructor.

The FileTypedMappedURLDataSource class will not open a connection to the URL until a method requiring it to do so is called.

Parameters:
url - The URL to be encapsulated in this object.
Method Detail

getContentType

public java.lang.String getContentType()
Returns the value of the URL content-type header field. It calls the URL's URLConnection.getContentType method after retrieving a URLConnection object.

If this gives not a satisfactory result (either 'content/unknown' or 'application/octet-stream') then this method uses the currently installed FileTypeMap to guess the content type.

Specified by:
getContentType in interface javax.activation.DataSource
Overrides:
getContentType in class javax.activation.URLDataSource
Returns:
The MIME type.

Copyright 2012-02-25 Werner Randelshofer