|
WebObjects 5.2.3 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface provides for converting data from any of the Java primitive types to a series of XML elements. There are also facilities for converting a Java object in a XML element which then includes sub XML elements.
The major difference from java.io.ObjectOutput
is that each of the
method in this interface takes an extra parameter key
, which will be appear
as the data of the attribute "key" in the XML element written out.
This key can then be used in XSLT to transform the tag name of the XML element. For example:
Thus,6.25 --->6.25
key
has to be a proper XML attribute value. For example, it cannot be a
String of the null character, \U0000. And if you want to use it in XSLT to become a tag name,
then it has to be a proper XML tag name. For example, there must not be whitespaces.
There are also a few utility methods that are not found in java.io.ObjectOutput
.
Method Summary | |
boolean |
disableReferenceForString()
Disables the use of references for repeated Strings in XML output. |
int |
disableReferenceForString(int length)
See disableReferenceForString() for details first. |
boolean |
enableReferenceForString()
Enables the use of references for repeated Strings in XML output. |
boolean |
setUseBase64ForBinaryData(boolean on)
Sets the output mode for binary data (essentially array of bytes) to be either using the Base64 encoding or a simple series of numbers (-128 to 127) delimited by a space. |
boolean |
useBase64ForBinaryData()
Gets the previously set output mode for binary data. |
boolean |
useReferenceForString()
Gets the previously set output behavior for a java.lang.String object. |
void |
write(byte[] buf,
int off,
int len,
String key)
Writes a sub array of bytes. |
void |
write(byte[] buf,
String key)
Writes an array of bytes. |
void |
write(int val,
String key)
Writes a byte. |
void |
writeBoolean(boolean val,
String key)
Writes a boolean. |
void |
writeByte(int val,
String key)
Writes an 8 bit byte. |
void |
writeBytes(String str,
String key)
Writes a String as a sequence of bytes. |
void |
writeChar(int val,
String key)
Writes a 16 bit char. |
void |
writeChars(String str,
String key)
Writes a String as a sequence of chars. |
void |
writeComment(String comment)
Writes a comment to the XML output. |
void |
writeDouble(double val,
String key)
Writes a 64 bit double. |
void |
writeFloat(float val,
String key)
Writes a 32 bit float. |
void |
writeInt(int val,
String key)
Writes a 32 bit int. |
void |
writeLong(long val,
String key)
Writes a 64 bit long. |
void |
writeObject(Object object,
String key)
Writes the specified object as XML data. |
void |
writeRootComment(String comment,
boolean before)
Writes a comment to the XML output. |
void |
writeShort(int val,
String key)
Writes a 16 bit short. |
void |
writeUTF(String str,
String key)
Primitive data write of this String in UTF format. |
Method Detail |
public boolean disableReferenceForString()
id
attribute by default:
<string id="39" xml:space="preserve">Well Done!</string>And any repeating output of the same String will just use the
idRef
attribute feature:
<string idRef="39" />This saves space in the output and more importantly maintain the integrity of the objects during deserialization: the two Strings are the same object.
However, sometimes you are just concerned about the data itself and want to see the content of the repeated string without following its reference. You can either use the writeUTF method or use this method to globally treat all Strings as different objects. Thus, if you are not using references for String, subsequent output of the same string looks like this:
<string id="40" xml:space="preserve">Well Done!</string>
true
if the previous behavior is to use references for Strings;
false otherwiseenableReferenceForString()
,
disableReferenceForString(int)
public int disableReferenceForString(int length)
The parameter length
allows you to further fine tune the disabled effect.
It tells NSXMLObjectOutput to revert back to default behavior when length of the string
exceeds the length
so that long strings will not waste space in the output.
For example, when the length is 100, only strings of length 100 or less are written out
as they out, without the use of references.
length
- the length by which NSXMLObjectOutput reverts to default behavior; -1 means
there is no length consideration
enableReferenceForString()
,
disableReferenceForString()
public boolean enableReferenceForString()
id
attribute by default:
<string id="39" xml:space="preserve">Well Done!</string>And any repeating output of the same String will just use the
idRef
attribute feature:
<string idRef="39" />This saves space in the output and more importantly maintain the integrity of the objects during deserialization: the two Strings are the same object.
This is the default behavior.
true
if the previous behavior is to use references for Strings;
false otherwisedisableReferenceForString()
,
disableReferenceForString(int)
public boolean setUseBase64ForBinaryData(boolean on)
on
- output mode is Base64 if it is true
true
useBase64ForBinaryData()
public boolean useBase64ForBinaryData()
true
.
setUseBase64ForBinaryData(boolean)
public boolean useReferenceForString()
true
.
enableReferenceForString()
,
disableReferenceForString()
,
disableReferenceForString(int)
public void write(int val, String key)
val
- the byte to be written to the streamkey
- this will appear as the data of the attribute "key"public void write(byte[] buf, String key) throws IOException
buf
- the data to be writtenkey
- this will appear as the data of the attribute "key"
IOException
- if I/O errors occur while writing to the underlying
streampublic void write(byte[] buf, int off, int len, String key) throws IOException
buf
- the data to be writtenoff
- the start offset in the datalen
- the number of bytes that are writtenkey
- this will appear as the data of the attribute "key"
IOException
- if I/O errors occur while writing to the underlying
streampublic void writeBoolean(boolean val, String key)
val
- the boolean to be writtenkey
- this will appear as the data of the attribute "key"public void writeByte(int val, String key)
val
- the byte value to be writtenkey
- this will appear as the data of the attribute "key"public void writeBytes(String str, String key) throws IOException
str
is cast into a byte (and hence information could be lost), the encoding specified
by the user (using NSXMLOutputFormat) is used to convert each character to a
certain number of bytes.
str
- the String of bytes to be writtenkey
- this will appear as the data of the attribute "key"
IOException
- Any exception thrown by the underlying
OutputStream.public void writeChar(int val, String key)
val
- the char value to be writtenkey
- this will appear as the data of the attribute "key"public void writeChars(String str, String key) throws IOException
str
- the String of chars to be writtenkey
- this will appear as the data of the attribute "key"
IOException
- if I/O errors occur while writing to the underlying
streampublic void writeComment(String comment)
comment
- the comment to be written outwriteRootComment(java.lang.String, boolean)
public void writeDouble(double val, String key)
val
- the double value to be writtenkey
- this will appear as the data of the attribute "key"public void writeFloat(float val, String key)
val
- the float value to be writtenkey
- this will appear as the data of the attribute "key"public void writeInt(int val, String key)
val
- the integer value to be writtenkey
- this will appear as the data of the attribute "key"public void writeLong(long val, String key)
val
- the long value to be writtenkey
- this will appear as the data of the attribute "key"public void writeObject(Object object, String key) throws IOException
Exceptions are thrown for problems with the OutputStream and for classes that should not be serialized. All exceptions are fatal to the OutputStream, which is left in an indeterminate state, and it is up to the caller to ignore or recover the stream state.
object
- the object to be written outkey
- this will appear as the data of the attribute "key"
InvalidClassException
- Something is wrong with a class used by
serialization.
NotSerializableException
- Some object to be serialized does not
implement the java.io.Serializable interface.
IOException
- Any exception thrown by the underlying
OutputStream.public void writeRootComment(String comment, boolean before)
comment
- the comment to be written outbefore
- if true, the comment is right before the root element; otherwise, it
is right after the root elementwriteComment(java.lang.String)
public void writeShort(int val, String key)
val
- the short value to be writtenkey
- this will appear as the data of the attribute "key"public void writeUTF(String str, String key)
str
- the String in UTF formatkey
- this will appear as the data of the attribute "key"
|
Last updated Thu Oct 21 15:04:16 PDT 2004. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |