|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.wm.util.coder.Coder
public abstract class Coder
This class is an abstract class that contains methods for transforming an encoded set of data to a Values 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 a Values object and to encode a Values object into a file, byte array or OutputStream.
This class is used to store and fetch Values 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.
Codable
,
IDataCodable
,
StringCodable
,
ValuesCodable
Constructor Summary | |
---|---|
Coder()
|
Method Summary | |
---|---|
abstract Values |
decode(java.io.InputStream is)
Decodes the data in the specified InputStream to a Values object. |
Values |
decodeFromBytes(byte[] b)
Decodes the data in the specified byte [] to a Values object. |
abstract void |
encode(java.io.OutputStream os,
Values data)
Encodes the contents of a specified Values object and writes the encoded data to an OutputStream. |
byte[] |
encodeToBytes(Values data)
Encodes the specified Values 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. |
Values |
readFromFile(java.io.File f)
Decodes the contents of the specified File and puts it in a Values object. |
static byte[] |
readFully(java.io.InputStream is)
Decodes an InputStream into a byte [] using the format defined by the derived class. |
void |
writeToFile(java.io.File f,
Values v)
Encodes the specified Values 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 |
---|
public Coder()
Method Detail |
---|
public abstract Values decode(java.io.InputStream is) throws java.io.IOException, InvalidDatatypeException
Note: If you extend this class, you must implement this method.
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.
java.io.IOException
- If an error occurs while reading the InputStream or writing to the
Values object.
InvalidDatatypeException
- If the content of InputStream cannot an be properly
parsed and decoded.decodeFromBytes(byte[])
,
readFromFile(java.io.File)
public Values decodeFromBytes(byte[] b) throws java.io.IOException
b
- The byte [] that contains that data that this method will decode.
java.io.IOException
- If an error occurs while reading the byte [], parsing its contents, or
writing to the Values object.decode(java.io.InputStream)
,
readFromFile(java.io.File)
public abstract void encode(java.io.OutputStream os, Values data) throws java.io.IOException, InvalidDatatypeException
os
- The OutputStream to which you want the encoded data written.data
- The Values object whose data you want to encode.
java.io.IOException
- If an error occurs while reading data from the Values object or
writing data to the OutputStream.
InvalidDatatypeException
- If the data in the Values object cannot be encoded (i.e.,
the Values object contains an object type that is not supported by the specific
implementation of encode that you are using.)encodeToBytes(com.wm.util.Values)
,
writeToFile(java.io.File, com.wm.util.Values)
public byte[] encodeToBytes(Values data) throws java.io.IOException
data
- The Values object whose data you want to encode.
java.io.IOException
- If an error occurs while reading data from the Values object or
writing data to the byte [].encode(java.io.OutputStream, com.wm.util.Values)
,
writeToFile(java.io.File, com.wm.util.Values)
public abstract java.lang.String getContentType()
public Values readFromFile(java.io.File f) throws java.io.IOException
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.)
java.io.IOException
- If an error occurs while reading data from the file, parsing its contents, or
writing it to the Values object.decode(java.io.InputStream)
,
decodeFromBytes(byte[])
,
writeToFile(java.io.File, com.wm.util.Values)
public static byte[] readFully(java.io.InputStream is) throws java.io.IOException
is
- The InputStream that you want to decode.
java.io.IOException
- If an error occurs while reading data from the InputStream or writing
data to the byte [].public void writeToFile(java.io.File f, Values v) throws java.io.IOException
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 Values object whose data you want to encode.
java.io.IOException
- If an error occurs while reading data from the Values object or
writing data to the file.encode(java.io.OutputStream, com.wm.util.Values)
,
encodeToBytes(com.wm.util.Values)
,
readFromFile(java.io.File)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |