/**
* Construct an appropriate external representation of the object
* and write it to a file.
* Errors are returned by throwing an IOException containing the
* cause of the problem as its message.
* <P>
* DataType is responsible for validating that the given text
* text from a Popup JTextArea can be converted to an object.
* This text-to-object conversion is the same as validateAndConvertInPopup,
* which may be used internally by the object to do the validation.
* <P>
* The DataType object must flush and close the output stream before returning.
* Typically it will create another object (e.g. an OutputWriter), and
* that is the object that must be flushed and closed.
*/
/**
* Construct an appropriate external representation of the object
* and write it to a file.
* Errors are returned by throwing an IOException containing the
* cause of the problem as its message.
* <P>
* DataType is responsible for validating that the given text
* text from a Popup JTextArea can be converted to an object.
* This text-to-object conversion is the same as validateAndConvertInPopup,
* which may be used internally by the object to do the validation.
* <P>
* The DataType object must flush and close the output stream before returning.
* Typically it will create another object (e.g. an OutputWriter), and
* that is the object that must be flushed and closed.
*
* <P>
* File is assumed to be and ASCII string of digits
* representing a value of this data type.
*/
public void exportObject(FileOutputStream outStream, String text) throws IOException {
Byte[] bBytes = BinaryDisplayConverter.convertToBytes(text, BinaryDisplayConverter.HEX, false);
// check that the text is a valid representation
StringBuffer messageBuffer = new StringBuffer();
validateAndConvertInPopup(text, null, messageBuffer);
if (messageBuffer.length() > 0) {
// there was an error in the conversion
throw new IOException(new String(messageBuffer));
}
// Convert Bytes to bytes
byte[] bytes = new byte[bBytes.length];
for (int i = 0; i < bytes.length; i++)
bytes[i] = bBytes[i].byteValue();
// just send the text to the output file
outStream.write(bytes);
outStream.flush();
outStream.close();
}
|