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

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