com.wm.util.coder
Class IDataCoder

java.lang.Object
  extended by com.wm.util.coder.IDataCoder
Direct Known Subclasses:
IDataXMLCoder

public abstract class IDataCoder
extends java.lang.Object

This class is an abstract class that contains methods for transforming an encoded set of data to an IData object. You can extend this class to define a derived class that specifies the format and the content type to decode a file, byte array or an InputStream into an IData object and to encode an IData object into a file, byte array or OutputStream.

This class is used to store and fetch IData objects to and from disk into a format specified by the derived class.

Note: If you extend this class, you must implement the following methods: decode, encode and getContentType.

See Also:
Coder, IDataXMLCoder, IData

Constructor Summary
IDataCoder()
           
 
Method Summary
abstract  IData decode(java.io.InputStream is)
          Decodes the data in the specified InputStream to an IData object.
 IData decodeFromBytes(byte[] b)
          Decodes the data in the specified byte [] to an IData object.
abstract  void encode(java.io.OutputStream os, IData data)
          Encodes the contents of a specified IData object and writes the encoded data to an OutputStream.
 byte[] encodeToBytes(IData data)
          Encodes the specified IData object and writes the encoded data to a byte [].
abstract  java.lang.String getContentType()
          Returns a String containing the name of the content type that is in use by this instance of Coder.
 IData readFromFile(java.io.File f)
          Decodes the contents of the specified File and puts it in an IData object.
 void writeToFile(java.io.File f, IData v)
          Encodes the specified IData object and writes the encoded data to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDataCoder

public IDataCoder()
Method Detail

decode

public abstract IData decode(java.io.InputStream is)
                      throws java.io.IOException,
                             InvalidDatatypeException
Decodes the data in the specified InputStream to an IData object. This abstract method lets you to build customized processes for converting encoded data (such as an XML document) to IData objects.

Note: If you extend this class, you must implement this method.

Parameters:
is - The InputStream that this method will decode. The data in this object must be encoded in the way that your implementation of decode expects.
Returns:
The IData object that is produced by decoding the InputStream in is.
Throws:
java.io.IOException - If an error occurs while reading the InputStream or writing to the IData object.
InvalidDatatypeException - If the content of InputStream cannot an be properly parsed and decoded.
See Also:
decodeFromBytes(byte[]), readFromFile(java.io.File)

decodeFromBytes

public IData decodeFromBytes(byte[] b)
                      throws java.io.IOException
Decodes the data in the specified byte [] to an IData object.

Parameters:
b - The byte [] that contains that data that this method will decode.
Returns:
The IData object produced by decoding the data in b.
Throws:
java.io.IOException - If an error occurs while reading the byte [], parsing its contents, or writing to the IData object.
See Also:
decode(java.io.InputStream), readFromFile(java.io.File)

encode

public abstract void encode(java.io.OutputStream os,
                            IData data)
                     throws java.io.IOException,
                            InvalidDatatypeException
Encodes the contents of a specified IData object and writes the encoded data to an OutputStream. This abstract method allows you to build additional, customized implementations to accommodate other encoding schemes.

Parameters:
os - The OutputStream to which you want the encoded data written.
data - The IData object whose data you want to encode.
Throws:
java.io.IOException - If an error occurs while reading data from the IData object or writing data to the OutputStream.
InvalidDatatypeException - If the data in the IData object cannot be encoded (i.e., the IData object contains an object type that is not supported by the specific implementation of encode that you are using).
See Also:
encodeToBytes(com.wm.data.IData), writeToFile(java.io.File, com.wm.data.IData)

encodeToBytes

public byte[] encodeToBytes(IData data)
                     throws java.io.IOException
Encodes the specified IData object and writes the encoded data to a byte [].

Parameters:
data - The IData object whose data you want to encode.
Returns:
A byte [] containing the encoded data.
Throws:
java.io.IOException - If an error occurs while reading data from the IData object or writing data to the byte [].
See Also:
encode(java.io.OutputStream, com.wm.data.IData), writeToFile(java.io.File, com.wm.data.IData)

getContentType

public abstract java.lang.String getContentType()
Returns a String containing the name of the content type that is in use by this instance of Coder. Classes that extend the Coder class support one or more content types.

Returns:
A String specifying the current content type.

readFromFile

public IData readFromFile(java.io.File f)
                   throws java.io.IOException
Decodes the contents of the specified File and puts it in an IData object. This method allows you to build a customized process for converting an encoded data file (such as an XML document) to an IData object.

Parameters:
f - A File representing the file that you want to decode. (The data in the file must be encoded in the way that the specific implementation of decode that you are using expects.)
Returns:
The IData object produced by decoding the file specified in f.
Throws:
java.io.IOException - If an error occurs while reading data from the file, parsing its contents, or writing it to the IData object.
See Also:
decode(java.io.InputStream), decodeFromBytes(byte[]), writeToFile(java.io.File, com.wm.data.IData)

writeToFile

public void writeToFile(java.io.File f,
                        IData v)
                 throws java.io.IOException
Encodes the specified IData object and writes the encoded data to a file.

Parameters:
f - A File representing the file to which you want the encoded data written. If this file does not exist, it will be created. If the file already exists, it will be overwritten.
v - The IData object whose data you want to encode.
Throws:
java.io.IOException - If an error occurs while reading data from the IData object or writing data to the file.
See Also:
encode(java.io.OutputStream, com.wm.data.IData), encodeToBytes(com.wm.data.IData), \