Class 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 Details

  • Constructor Details

    • 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 Details

    • init

      public void init(OutputStream os)
      Initializes the output
      Overrides:
      init in class AbstractHessianOutput
    • call

      public void call(String method, Object[] args) throws IOException
      Writes a complete method call.
      Overrides:
      call in class AbstractHessianOutput
      Throws:
      IOException
    • startCall

      public void startCall(String method) throws IOException
      Starts the method call. Clients would use startCall instead of call if 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 IOException
      Starts the method call. Clients would use startCall instead of call if they wanted finer control over writing the arguments, or needed to write headers.
       <method>method-name</method>
       
      Specified by:
      startCall in class AbstractHessianOutput
      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:
      writeMethod in class AbstractHessianOutput
      Parameters:
      method - the method name to call.
      Throws:
      IOException
    • completeCall

      public void completeCall() throws IOException
      Completes.
       </burlap:call>
       
      Specified by:
      completeCall in class AbstractHessianOutput
      Throws:
      IOException
    • startReply

      public void startReply() throws IOException
      Starts the reply

      A successful completion will have a single value:

       r
       
      Overrides:
      startReply in class AbstractHessianOutput
      Throws:
      IOException
    • completeReply

      public void completeReply() throws IOException
      Completes reading the reply

      A successful completion will have a single value:

       </burlap:reply>
       
      Overrides:
      completeReply in class AbstractHessianOutput
      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:
      writeHeader in class AbstractHessianOutput
      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:
      writeFault in class AbstractHessianOutput
      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:
      writeObject in class AbstractHessianOutput
      Throws:
      IOException
    • writeListBegin

      public boolean writeListBegin(int length, String type) throws IOException
      Writes the list header to the stream. List writers will call writeListBegin followed by the list contents and then call writeListEnd.
       <list>
         <type>java.util.ArrayList</type>
         <length>3</length>
         <int>1</int>
         <int>2</int>
         <int>3</int>
       </list>
       
      Specified by:
      writeListBegin in class AbstractHessianOutput
      Throws:
      IOException
    • writeListEnd

      public void writeListEnd() throws IOException
      Writes the tail of the list to the stream.
      Specified by:
      writeListEnd in class AbstractHessianOutput
      Throws:
      IOException
    • writeMapBegin

      public void writeMapBegin(String type) throws IOException
      Writes the map header to the stream. Map writers will call writeMapBegin followed by the map contents and then call writeMapEnd.
       <map>
         <type>type</type>
         (<key> <value>)*
       </map>
       
      Specified by:
      writeMapBegin in class AbstractHessianOutput
      Throws:
      IOException
    • writeMapEnd

      public void writeMapEnd() throws IOException
      Writes the tail of the map to the stream.
      Specified by:
      writeMapEnd in class AbstractHessianOutput
      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 IOException
      Writes a boolean value to the stream. The boolean will be written with the following syntax:
       <boolean>0</boolean>
       <boolean>1</boolean>
       
      Specified by:
      writeBoolean in class AbstractHessianOutput
      Parameters:
      value - the boolean value to write.
      Throws:
      IOException
    • writeInt

      public void writeInt(int value) throws IOException
      Writes an integer value to the stream. The integer will be written with the following syntax:
       <int>int value</int>
       
      Specified by:
      writeInt in class AbstractHessianOutput
      Parameters:
      value - the integer value to write.
      Throws:
      IOException
    • writeLong

      public void writeLong(long value) throws IOException
      Writes a long value to the stream. The long will be written with the following syntax:
       <long>int value</long>
       
      Specified by:
      writeLong in class AbstractHessianOutput
      Parameters:
      value - the long value to write.
      Throws:
      IOException
    • writeDouble

      public void writeDouble(double value) throws IOException
      Writes a double value to the stream. The double will be written with the following syntax:
       <double>value</double>
       
      Specified by:
      writeDouble in class AbstractHessianOutput
      Parameters:
      value - the double value to write.
      Throws:
      IOException
    • writeUTCDate

      public void writeUTCDate(long time) throws IOException
      Writes a date to the stream.
       <date>iso8901</date>
       
      Specified by:
      writeUTCDate in class AbstractHessianOutput
      Parameters:
      time - the date in milliseconds from the epoch in UTC
      Throws:
      IOException
    • writeNull

      public void writeNull() throws IOException
      Writes a null value to the stream. The null will be written with the following syntax
       <null></null>
       
      Specified by:
      writeNull in class AbstractHessianOutput
      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:
       <string>string-value</string>
       
      If the value is null, it will be written as
       <null></null>
       
      Specified by:
      writeString in class AbstractHessianOutput
      Parameters:
      value - the string value to write.
      Throws:
      IOException
    • writeString

      public void writeString(char[] buffer, int offset, int length) throws IOException
      Writes a string value to the stream using UTF-8 encoding. The string will be written with the following syntax:
       S b16 b8 string-value
       
      If the value is null, it will be written as
       N
       
      Specified by:
      writeString in class AbstractHessianOutput
      Parameters:
      value - the string value to write.
      Throws:
      IOException
    • writeBytes

      public void writeBytes(byte[] buffer) throws IOException
      Writes a byte array to the stream. The array will be written with the following syntax:
       <base64>bytes</base64>
       
      If the value is null, it will be written as
       <null></null>
       
      Specified by:
      writeBytes in class AbstractHessianOutput
      Parameters:
      value - the string value to write.
      Throws:
      IOException
    • writeBytes

      public void writeBytes(byte[] buffer, int offset, int length) throws IOException
      Writes a byte array to the stream. The array will be written with the following syntax:
       <base64>bytes</base64>
       
      If the value is null, it will be written as
       <null></null>
       
      Specified by:
      writeBytes in class AbstractHessianOutput
      Parameters:
      value - the string value to write.
      Throws:
      IOException
    • writeByteBufferStart

      public void writeByteBufferStart() throws IOException
      Writes a byte buffer to the stream.
      Specified by:
      writeByteBufferStart in class AbstractHessianOutput
      Throws:
      IOException
    • writeByteBufferPart

      public void writeByteBufferPart(byte[] buffer, int offset, int length) throws IOException
      Writes a byte buffer to the stream.
       b b16 b18 bytes
       
      Specified by:
      writeByteBufferPart in class AbstractHessianOutput
      Throws:
      IOException
    • writeByteBufferEnd

      public void writeByteBufferEnd(byte[] buffer, int offset, int length) throws IOException
      Writes a byte buffer to the stream.
       b b16 b18 bytes
       
      Specified by:
      writeByteBufferEnd in class AbstractHessianOutput
      Throws:
      IOException
    • writeRef

      public void writeRef(int value) throws IOException
      Writes a reference.
       <ref>int</ref>
       
      Specified by:
      writeRef in class AbstractHessianOutput
      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:
      addRef in class AbstractHessianOutput
      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:
      getRef in class AbstractHessianOutput
      Returns:
    • removeRef

      public boolean removeRef(Object obj) throws IOException
      Removes a reference.
      Overrides:
      removeRef in class AbstractHessianOutput
      Throws:
      IOException
    • replaceRef

      public boolean replaceRef(Object oldRef, Object newRef) throws IOException
      Replaces a reference from one object to another.
      Specified by:
      replaceRef in class AbstractHessianOutput
      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 IOException
      Prints 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 IOException
      Prints a char to the stream.
      Parameters:
      v - the char to print.
      Throws:
      IOException
    • print

      protected void print(int v) throws IOException
      Prints an integer to the stream.
      Parameters:
      v - the integer to print.
      Throws:
      IOException
    • print

      protected void print(long v) throws IOException
      Prints a long to the stream.
      Parameters:
      v - the long to print.
      Throws:
      IOException
    • print

      protected void print(double v) throws IOException
      Prints 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