Package com.caucho.burlap.io
Class BurlapOutput
- java.lang.Object
-
- com.caucho.hessian.io.AbstractHessianOutput
-
- com.caucho.burlap.io.AbstractBurlapOutput
-
- com.caucho.burlap.io.BurlapOutput
-
public class BurlapOutput extends AbstractBurlapOutput
Output stream for Burlap requests, compatible with microedition Java. It only uses classes and types available in JDK.Since BurlapOutput does not depend on any classes other than in the JDK, it can be extracted independently into a smaller package.
BurlapOutput is unbuffered, so any client needs to provide its own buffering.
OutputStream os = ...; // from http connection BurlapOutput out = new BurlapOutput(os); String value; out.startCall("hello"); // start hello call out.writeString("arg1"); // write a string argument out.completeCall(); // complete the call
-
-
Field Summary
Fields Modifier and Type Field Description protected OutputStreamos-
Fields inherited from class com.caucho.hessian.io.AbstractHessianOutput
_serializerFactory
-
-
Constructor Summary
Constructors Constructor Description BurlapOutput()Creates an uninitialized Burlap output stream.BurlapOutput(OutputStream os)Creates a new Burlap output stream, initialized with an underlying output stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddRef(Object object)If the object has already been written, just write its ref.voidcall(String method, Object[] args)Writes a complete method call.voidcompleteCall()Completes.voidcompleteReply()Completes reading the replyintgetRef(Object obj)voidinit(OutputStream os)Initializes the outputprotected voidprint(char v)Prints a char to the stream.protected voidprint(double v)Prints a double to the stream.protected voidprint(int v)Prints an integer to the stream.protected voidprint(long v)Prints a long to the stream.protected voidprint(String s)Prints a string as ascii to the stream.voidprintDate(Calendar calendar)Prints a date.voidprintString(char[] v, int offset, int length)Prints a string to the stream, encoded as UTF-8voidprintString(String v)Prints a string to the stream, encoded as UTF-8voidprintString(String v, int offset, int length)Prints a string to the stream, encoded as UTF-8booleanremoveRef(Object obj)Removes a reference.booleanreplaceRef(Object oldRef, Object newRef)Replaces a reference from one object to another.voidstartCall()Starts the method call.voidstartCall(String method)Starts the method call.voidstartReply()Starts the replyvoidwriteBoolean(boolean value)Writes a boolean value to the stream.voidwriteByteBufferEnd(byte[] buffer, int offset, int length)Writes a byte buffer to the stream.voidwriteByteBufferPart(byte[] buffer, int offset, int length)Writes a byte buffer to the stream.voidwriteByteBufferStart()Writes a byte buffer to the stream.voidwriteBytes(byte[] buffer)Writes a byte array to the stream.voidwriteBytes(byte[] buffer, int offset, int length)Writes a byte array to the stream.voidwriteDouble(double value)Writes a double value to the stream.voidwriteFault(String code, String message, Object detail)Writes a fault.voidwriteHeader(String name)Writes a header name.voidwriteInt(int value)Writes an integer value to the stream.booleanwriteListBegin(int length, String type)Writes the list header to the stream.voidwriteListEnd()Writes the tail of the list to the stream.voidwriteLong(long value)Writes a long value to the stream.voidwriteMapBegin(String type)Writes the map header to the stream.voidwriteMapEnd()Writes the tail of the map to the stream.voidwriteMethod(String method)Writes the method for a call.voidwriteNull()Writes a null value to the stream.voidwriteObject(Object object)Writes any object to the output stream.voidwriteRef(int value)Writes a reference.voidwriteRemote(String type, String url)Writes a remote object reference to the stream.voidwriteString(char[] buffer, int offset, int length)Writes a string value to the stream using UTF-8 encoding.voidwriteString(String value)Writes a string value to the stream using UTF-8 encoding.voidwriteUTCDate(long time)Writes a date to the stream.-
Methods inherited from class com.caucho.burlap.io.AbstractBurlapOutput
startCall
-
Methods inherited from class com.caucho.hessian.io.AbstractHessianOutput
close, findSerializerFactory, flush, getSerializerFactory, resetReferences, setSerializerFactory, setUnshared, writeByteStream, writeClassFieldLength, writeObjectBegin, writeObjectEnd, writeReply
-
-
-
-
Field Detail
-
os
protected OutputStream os
-
-
Constructor Detail
-
BurlapOutput
public BurlapOutput(OutputStream os)
Creates a new Burlap output stream, initialized with an underlying output stream.- Parameters:
os- the underlying output stream.
-
BurlapOutput
public BurlapOutput()
Creates an uninitialized Burlap output stream.
-
-
Method Detail
-
init
public void init(OutputStream os)
Initializes the output- Overrides:
initin classAbstractHessianOutput
-
call
public void call(String method, Object[] args) throws IOException
Writes a complete method call.- Overrides:
callin classAbstractHessianOutput- Throws:
IOException
-
startCall
public void startCall(String method) throws IOException
Starts the method call. Clients would usestartCallinstead ofcallif they wanted finer control over writing the arguments, or needed to write headers.<burlap:call> <method>method-name</method>
- Parameters:
method- the method name to call.- Throws:
IOException
-
startCall
public void startCall() throws IOExceptionStarts the method call. Clients would usestartCallinstead ofcallif they wanted finer control over writing the arguments, or needed to write headers.<method>method-name</method>
- Specified by:
startCallin classAbstractHessianOutput- Parameters:
method- the method name to call.- Throws:
IOException
-
writeMethod
public void writeMethod(String method) throws IOException
Writes the method for a call.<method>value</method>
- Specified by:
writeMethodin classAbstractHessianOutput- Parameters:
method- the method name to call.- Throws:
IOException
-
completeCall
public void completeCall() throws IOExceptionCompletes.</burlap:call>
- Specified by:
completeCallin classAbstractHessianOutput- Throws:
IOException
-
startReply
public void startReply() throws IOExceptionStarts the replyA successful completion will have a single value:
r
- Overrides:
startReplyin classAbstractHessianOutput- Throws:
IOException
-
completeReply
public void completeReply() throws IOExceptionCompletes reading the replyA successful completion will have a single value:
</burlap:reply>
- Overrides:
completeReplyin classAbstractHessianOutput- Throws:
IOException
-
writeHeader
public void writeHeader(String name) throws IOException
Writes a header name. The header value must immediately follow.<header>foo</header><int>value</int>
- Overrides:
writeHeaderin classAbstractHessianOutput- Throws:
IOException
-
writeFault
public void writeFault(String code, String message, Object detail) throws IOException
Writes a fault. The fault will be written as a descriptive string followed by an object:<fault> <string>code <string>the fault code <string>message <string>the fault mesage <string>detail <map>t\x00\xnnjavax.ejb.FinderException ... </map> </fault>- Overrides:
writeFaultin classAbstractHessianOutput- Parameters:
code- the fault code, a three digit- Throws:
IOException
-
writeObject
public void writeObject(Object object) throws IOException
Writes any object to the output stream.- Specified by:
writeObjectin classAbstractHessianOutput- Throws:
IOException
-
writeListBegin
public boolean writeListBegin(int length, String type) throws IOExceptionWrites the list header to the stream. List writers will callwriteListBeginfollowed by the list contents and then callwriteListEnd.<list> <type>java.util.ArrayList</type> <length>3</length> <int>1</int> <int>2</int> <int>3</int> </list>
- Specified by:
writeListBeginin classAbstractHessianOutput- Throws:
IOException
-
writeListEnd
public void writeListEnd() throws IOExceptionWrites the tail of the list to the stream.- Specified by:
writeListEndin classAbstractHessianOutput- Throws:
IOException
-
writeMapBegin
public void writeMapBegin(String type) throws IOException
Writes the map header to the stream. Map writers will callwriteMapBeginfollowed by the map contents and then callwriteMapEnd.<map> <type>type</type> (<key> <value>)* </map>
- Specified by:
writeMapBeginin classAbstractHessianOutput- Throws:
IOException
-
writeMapEnd
public void writeMapEnd() throws IOExceptionWrites the tail of the map to the stream.- Specified by:
writeMapEndin classAbstractHessianOutput- Throws:
IOException
-
writeRemote
public void writeRemote(String type, String url) throws IOException
Writes a remote object reference to the stream. The type is the type of the remote interface.<remote> <type>test.account.Account</type> <string>http://caucho.com/foo;ejbid=bar</string> </remote>
- Throws:
IOException
-
writeBoolean
public void writeBoolean(boolean value) throws IOExceptionWrites a boolean value to the stream. The boolean will be written with the following syntax:<boolean>0</boolean> <boolean>1</boolean>
- Specified by:
writeBooleanin classAbstractHessianOutput- Parameters:
value- the boolean value to write.- Throws:
IOException
-
writeInt
public void writeInt(int value) throws IOExceptionWrites an integer value to the stream. The integer will be written with the following syntax:<int>int value</int>
- Specified by:
writeIntin classAbstractHessianOutput- Parameters:
value- the integer value to write.- Throws:
IOException
-
writeLong
public void writeLong(long value) throws IOExceptionWrites a long value to the stream. The long will be written with the following syntax:<long>int value</long>
- Specified by:
writeLongin classAbstractHessianOutput- Parameters:
value- the long value to write.- Throws:
IOException
-
writeDouble
public void writeDouble(double value) throws IOExceptionWrites a double value to the stream. The double will be written with the following syntax:<double>value</double>
- Specified by:
writeDoublein classAbstractHessianOutput- Parameters:
value- the double value to write.- Throws:
IOException
-
writeUTCDate
public void writeUTCDate(long time) throws IOExceptionWrites a date to the stream.<date>iso8901</date>
- Specified by:
writeUTCDatein classAbstractHessianOutput- Parameters:
time- the date in milliseconds from the epoch in UTC- Throws:
IOException
-
writeNull
public void writeNull() throws IOExceptionWrites a null value to the stream. The null will be written with the following syntax<null></null>
- Specified by:
writeNullin classAbstractHessianOutput- Parameters:
value- the string value to write.- Throws:
IOException
-
writeString
public void writeString(String value) throws IOException
Writes a string value to the stream using UTF-8 encoding. The string will be written with the following syntax:If the value is null, it will be written as<string>string-value</string>
<null></null>
- Specified by:
writeStringin classAbstractHessianOutput- Parameters:
value- the string value to write.- Throws:
IOException
-
writeString
public void writeString(char[] buffer, int offset, int length) throws IOExceptionWrites a string value to the stream using UTF-8 encoding. The string will be written with the following syntax:If the value is null, it will be written asS b16 b8 string-value
N
- Specified by:
writeStringin classAbstractHessianOutput- Parameters:
value- the string value to write.- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] buffer) throws IOExceptionWrites a byte array to the stream. The array will be written with the following syntax:If the value is null, it will be written as<base64>bytes</base64>
<null></null>
- Specified by:
writeBytesin classAbstractHessianOutput- Parameters:
value- the string value to write.- Throws:
IOException
-
writeBytes
public void writeBytes(byte[] buffer, int offset, int length) throws IOExceptionWrites a byte array to the stream. The array will be written with the following syntax:If the value is null, it will be written as<base64>bytes</base64>
<null></null>
- Specified by:
writeBytesin classAbstractHessianOutput- Parameters:
value- the string value to write.- Throws:
IOException
-
writeByteBufferStart
public void writeByteBufferStart() throws IOExceptionWrites a byte buffer to the stream.- Specified by:
writeByteBufferStartin classAbstractHessianOutput- Throws:
IOException
-
writeByteBufferPart
public void writeByteBufferPart(byte[] buffer, int offset, int length) throws IOExceptionWrites a byte buffer to the stream.b b16 b18 bytes
- Specified by:
writeByteBufferPartin classAbstractHessianOutput- Throws:
IOException
-
writeByteBufferEnd
public void writeByteBufferEnd(byte[] buffer, int offset, int length) throws IOExceptionWrites a byte buffer to the stream.b b16 b18 bytes
- Specified by:
writeByteBufferEndin classAbstractHessianOutput- Throws:
IOException
-
writeRef
public void writeRef(int value) throws IOExceptionWrites a reference.<ref>int</ref>
- Specified by:
writeRefin classAbstractHessianOutput- Parameters:
value- the integer value to write.- Throws:
IOException
-
addRef
public boolean addRef(Object object) throws IOException
If the object has already been written, just write its ref.- Specified by:
addRefin classAbstractHessianOutput- Parameters:
object- the object to add as a reference.- Returns:
- true if we're writing a ref.
- Throws:
IOException
-
getRef
public int getRef(Object obj)
- Specified by:
getRefin classAbstractHessianOutput- Returns:
-
removeRef
public boolean removeRef(Object obj) throws IOException
Removes a reference.- Overrides:
removeRefin classAbstractHessianOutput- Throws:
IOException
-
replaceRef
public boolean replaceRef(Object oldRef, Object newRef) throws IOException
Replaces a reference from one object to another.- Specified by:
replaceRefin classAbstractHessianOutput- Throws:
IOException
-
printString
public void printString(String v) throws IOException
Prints a string to the stream, encoded as UTF-8- Parameters:
v- the string to print.- Throws:
IOException
-
printString
public void printString(String v, int offset, int length) throws IOException
Prints a string to the stream, encoded as UTF-8- Parameters:
v- the string to print.- Throws:
IOException
-
printString
public void printString(char[] v, int offset, int length) throws IOExceptionPrints a string to the stream, encoded as UTF-8- Parameters:
v- the string to print.- Throws:
IOException
-
printDate
public void printDate(Calendar calendar) throws IOException
Prints a date.- Parameters:
date- the date to print.- Throws:
IOException
-
print
protected void print(char v) throws IOExceptionPrints a char to the stream.- Parameters:
v- the char to print.- Throws:
IOException
-
print
protected void print(int v) throws IOExceptionPrints an integer to the stream.- Parameters:
v- the integer to print.- Throws:
IOException
-
print
protected void print(long v) throws IOExceptionPrints a long to the stream.- Parameters:
v- the long to print.- Throws:
IOException
-
print
protected void print(double v) throws IOExceptionPrints a double to the stream.- Parameters:
v- the double to print.- Throws:
IOException
-
print
protected void print(String s) throws IOException
Prints a string as ascii to the stream. Used for tags, etc. that are known to the ascii.- Parameters:
s- the ascii string to print.- Throws:
IOException
-
-