com.sun.jimi.util
Class DataType

java.lang.Object
  |
  +--com.sun.jimi.util.DataType

public class DataType
extends java.lang.Object

This class provides a data type identification in the form of a string. Clients of this class are responsible for mapping that identifier string to something useful.

If the getID(InputStream is) method is used then the client is responsible for passing an input stream which can be reset to restore the data consumed by this class in an attempt to identify the specified source.

Currently this class currently only supports type identification via filename extension.

PROJECTED OPERATION IS BELOW This class retreives data from the designated source and checks for matches against expressions stored in a configuration file to locate the file ID. See external specification for format of the file and field contents etc.

The configuration file is an ascii text file which is currently maintained by editing the file with a text editor. This will change in the future to allow applications to register there own fileTypes and expressions for specific clients.


Field Summary
static int MAX_REWIND
          This is the maximum number of bytes that this class will take to identify file in any situation.
 
Constructor Summary
DataType()
           
DataType(java.lang.String client)
          This constructor will find the highes version ID for the client.
DataType(java.lang.String client, int version)
           
 
Method Summary
protected static java.lang.String getExtension(java.lang.String str)
           
static java.lang.String getID(java.io.InputStream is)
           
static java.lang.String getID(java.lang.String fileName)
          currently just calls getIDe() to ID files by filename extension
static java.lang.String getID(java.net.URL url)
          currently just calls getIDe() to ID files by filename extension
static java.lang.String getIDe(java.lang.String fileName)
           
static java.lang.String getIDe(java.net.URL url)
           
static void putMapping(java.lang.String extension, java.lang.String typeID)
          Add or Overide a mapping of filename extension to String type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_REWIND

public static int MAX_REWIND
This is the maximum number of bytes that this class will take to identify file in any situation. Therefore this constant could be used by clients to wrap input Streams with buffered input streams sufficient to reset to the beggining of input data after identification.
Constructor Detail

DataType

public DataType(java.lang.String client,
                int version)
Parameters:
client - ID of the client for which file ID is required.
version - the version of the client for which the ID is required.

DataType

public DataType(java.lang.String client)
This constructor will find the highes version ID for the client.
Parameters:
client - ID of the client for which file ID is required.

DataType

public DataType()
Method Detail

putMapping

public static void putMapping(java.lang.String extension,
                              java.lang.String typeID)
Add or Overide a mapping of filename extension to String type.
Parameters:
extension - filename extension
typeID - id string of the type of the file to be returned for filenames with the assocciatted extension.

getExtension

protected static java.lang.String getExtension(java.lang.String str)
Returns:
the string following the last "." in the input string. If no "." in string the return null string.

getIDe

public static java.lang.String getIDe(java.lang.String fileName)
Returns:
a string ID of the file based only on the filename extension. This returns an empty string if no match is found.

getIDe

public static java.lang.String getIDe(java.net.URL url)
See Also:
getIDe

getID

public static java.lang.String getID(java.lang.String fileName)
                              throws java.io.IOException
currently just calls getIDe() to ID files by filename extension

getID

public static java.lang.String getID(java.net.URL url)
                              throws java.io.IOException
currently just calls getIDe() to ID files by filename extension

getID

public static java.lang.String getID(java.io.InputStream is)
                              throws java.io.IOException