Class MicroBurlapInput


  • public class MicroBurlapInput
    extends Object
    Input stream for Burlap requests, compatible with microedition Java. It only uses classes and types available to J2ME. In particular, it does not have any support for the <double> type.

    MicroBurlapInput does not depend on any classes other than in J2ME, so it can be extracted independently into a smaller package.

    MicroBurlapInput is unbuffered, so any client needs to provide its own buffering.

     InputStream is = ...; // from http connection
     MicroBurlapInput in = new MicroBurlapInput(is);
     String value;
    
     in.startReply();         // read reply header
     value = in.readString(); // read string value
     in.completeReply();      // read reply footer
     
    • Constructor Detail

      • MicroBurlapInput

        public MicroBurlapInput​(InputStream is)
        Creates a new Burlap input stream, initialized with an underlying input stream.
        Parameters:
        is - the underlying input stream.
      • MicroBurlapInput

        public MicroBurlapInput()
        Creates an uninitialized Burlap input stream.
    • Method Detail

      • getMethod

        public String getMethod()
        Returns a call's method.
      • init

        public void init​(InputStream is)
        Initialize the Burlap input stream with a new underlying stream. Applications can use init(InputStream) to reuse MicroBurlapInput to save garbage collection.
      • startCall

        public void startCall()
                       throws IOException
        Starts reading the call

        A successful completion will have a single value:

         <burlap:call>
         <method>method</method>
         
        Throws:
        IOException
      • completeCall

        public void completeCall()
                          throws IOException
        Completes reading the call.
         </burlap:call>
         
        Throws:
        IOException
      • readReply

        public Object readReply​(Class expectedClass)
                         throws Exception
        Reads a reply as an object. If the reply has a fault, throws the exception.
        Throws:
        Exception
      • startReply

        public boolean startReply()
                           throws IOException
        Starts reading the reply.

        A successful completion will have a single value. An unsuccessful one will have a fault:

         <burlap:reply>
         
        Returns:
        true if success, false for fault.
        Throws:
        IOException
      • completeReply

        public void completeReply()
                           throws IOException
        Completes reading the reply.
         </burlap:reply>
         
        Throws:
        IOException
      • readBoolean

        public boolean readBoolean()
                            throws IOException
        Reads a boolean value from the input stream.
        Throws:
        IOException
      • readInt

        public int readInt()
                    throws IOException
        Reads an integer value from the input stream.
        Throws:
        IOException
      • readLong

        public long readLong()
                      throws IOException
        Reads a long value from the input stream.
        Throws:
        IOException
      • readUTCDate

        public long readUTCDate()
                         throws IOException
        Reads a date value from the input stream.
        Throws:
        IOException
      • readLocalDate

        public long readLocalDate()
                           throws IOException
        Reads a date value from the input stream.
        Throws:
        IOException
      • readString

        public String readString()
                          throws IOException
        Reads a string value from the input stream.

        The two valid possibilities are either a <null> or a <string>. The string value is encoded in utf-8, and understands the basic XML escapes: "&123;", "<", ">", "'", """.

         <null></null>
         <string>a utf-8 encoded string</string>
         
        Throws:
        IOException
      • readBytes

        public byte[] readBytes()
                         throws IOException
        Reads a byte array from the input stream.

        The two valid possibilities are either a <null> or a <base64>.

        Throws:
        IOException
      • readType

        public String readType()
                        throws IOException
        Reads a type value from the input stream.
         <type>a utf-8 encoded string</type>
         
        Throws:
        IOException
      • readLength

        public int readLength()
                       throws IOException
        Reads a length value from the input stream. If the length isn't specified, returns -1.
         <length>integer</length>
         
        Throws:
        IOException
      • readMap

        public Object readMap​(Class expectedClass,
                              String type)
                       throws IOException
        Reads an object from the input stream.
        Parameters:
        expectedClass - the calling routine's expected class
        type - the type from the stream
        Throws:
        IOException
      • readList

        public Object readList​(Class expectedClass,
                               String type,
                               int length)
                        throws IOException
        Reads a list object from the input stream.
        Parameters:
        expectedClass - the calling routine's expected class
        type - the type from the stream
        length - the expected length, -1 for unspecified length
        Throws:
        IOException
      • parseInt

        protected int parseInt()
                        throws IOException
        Parses an integer value from the stream.
        Throws:
        IOException
      • parseLong

        protected long parseLong()
                          throws IOException
        Parses a long value from the stream.
        Throws:
        IOException
      • parseString

        protected String parseString()
                              throws IOException
        Parses a string value from the stream. string buffer is used for the result.
        Throws:
        IOException
      • parseTag

        protected boolean parseTag()
                            throws IOException
        Parses a tag. Returns true if it's a start tag.
        Throws:
        IOException
      • expectedChar

        protected IOException expectedChar​(String expect,
                                           int actualChar)