Class XTalkTransporter

  • All Implemented Interfaces:
    FrameTransporter

    public class XTalkTransporter
    extends java.lang.Object
    implements FrameTransporter
    Implements XTalk marshalling of Frames.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attributesToBin​(java.io.OutputStream os, Attributes attributes, byte[] workbuf)  
      static int consumeCharacters​(java.io.InputStream is, byte[] byteBuf, char[] charBuf, int bytesToRead)
      Consume the string of bytesToRead utf-8 bytes.
      void consumeChildren​(java.io.InputStream is, Frame f, int field_count, int marker, byte[] buffer, char[] cbuffer)  
      KeyValuePair consumeRootChildren​(java.io.InputStream is, Frame f, byte[] buffer, char[] cbuffer)  
      KeyValuePair consumeRootElement​(java.io.InputStream is, Frame f, byte[] buffer, char[] cbuffer)  
      static java.lang.String consumeString​(java.io.InputStream is)
      Consume a string from the input stream.
      static java.lang.String consumeString​(java.io.InputStream is, byte[] buffer, char[] cbuffer)  
      void elementToBin​(java.io.OutputStream os, Frame f, byte[] workbuf)  
      KeyValuePair fromStream​(java.io.InputStream is, Frame f)
      Parse the data-stream according to the XTalk protocol.
      KeyValuePair fromStreamWork​(java.io.InputStream is, Frame f)
      Once we know that this is an XTalk document, perform XTalk parsing.
      KeyValuePair fromStreamWork​(java.io.InputStream is, Frame f, byte[] buffer, char[] cbuffer)  
      protected void ignorePI​(java.io.InputStream is)  
      static void readFully​(byte[] b, int length, java.io.InputStream in)  
      static void readFully​(byte[] b, java.io.InputStream in)  
      static int readInt​(java.io.InputStream in)  
      static void stringToBin​(char[] str, int begin, int len, java.io.OutputStream os)  
      static void stringToBin​(char[] str, int begin, int len, java.io.OutputStream os, byte[] buffer)  
      static void stringToBin​(java.lang.String str, java.io.OutputStream os)
      Sends a string over, without the type byte.
      static void stringToBin​(java.lang.String str, java.io.OutputStream os, byte[] buffer)
      Sends a string as utf8, using the temporary buffer if it is big enough to avoid allocating new memory.
      void toStream​(java.io.OutputStream os, Frame f)
      Populate the (empty) frame from the stream contents.
      static void writeInt​(int write_me, java.io.OutputStream out)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XTalkTransporter

        public XTalkTransporter()
    • Method Detail

      • fromStream

        public KeyValuePair fromStream​(java.io.InputStream is,
                                       Frame f)
                                throws java.io.IOException,
                                       java.io.EOFException
        Parse the data-stream according to the XTalk protocol.
        Specified by:
        fromStream in interface FrameTransporter
        Parameters:
        is - input stream
        f - frame
        Returns:
        If the first tag belongs to the Vinci namespace, then this tag/value combination is returned. Otherwise returns null. Should there be a non-null return, then the value object of the KeyValuePair can be either FrameLeaf or Frame.
        Throws:
        java.io.IOException - -
        java.io.EOFException - -
      • fromStreamWork

        public KeyValuePair fromStreamWork​(java.io.InputStream is,
                                           Frame f)
                                    throws java.io.IOException
        Once we know that this is an XTalk document, perform XTalk parsing.
        Parameters:
        is - input stream
        f - frame
        Returns:
        the key value pair
        Throws:
        java.io.IOException - if the versions don't match, or have unexpected element marker
      • fromStreamWork

        public KeyValuePair fromStreamWork​(java.io.InputStream is,
                                           Frame f,
                                           byte[] buffer,
                                           char[] cbuffer)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • ignorePI

        protected void ignorePI​(java.io.InputStream is)
                         throws java.io.IOException
        Parameters:
        is - the input stream
        Throws:
        java.io.IOException - passthru
      • consumeRootChildren

        public KeyValuePair consumeRootChildren​(java.io.InputStream is,
                                                Frame f,
                                                byte[] buffer,
                                                char[] cbuffer)
                                         throws java.io.IOException
        Parameters:
        is - the input stream
        f - frame
        buffer - -
        cbuffer - -
        Returns:
        key value
        Throws:
        java.io.IOException - passthru
      • consumeRootElement

        public KeyValuePair consumeRootElement​(java.io.InputStream is,
                                               Frame f,
                                               byte[] buffer,
                                               char[] cbuffer)
                                        throws java.io.IOException
        Parameters:
        is - the input stream
        f - the Frame
        buffer - -
        cbuffer - -
        Returns:
        key value
        Throws:
        java.io.IOException - passthru
      • consumeChildren

        public void consumeChildren​(java.io.InputStream is,
                                    Frame f,
                                    int field_count,
                                    int marker,
                                    byte[] buffer,
                                    char[] cbuffer)
                             throws java.io.IOException
        Parameters:
        is - input stream
        f - frame
        field_count - field count
        marker - marker
        buffer - -
        cbuffer - -
        Throws:
        java.io.IOException - passthru
      • consumeString

        public static java.lang.String consumeString​(java.io.InputStream is)
                                              throws java.io.IOException
        Consume a string from the input stream. TODO: Make a faster version that exploits work buffers to reduce allocations to a single string object.
        Parameters:
        is - input stream
        Returns:
        the string
        Throws:
        java.io.IOException - if key is longer than limit
      • consumeString

        public static java.lang.String consumeString​(java.io.InputStream is,
                                                     byte[] buffer,
                                                     char[] cbuffer)
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • consumeCharacters

        public static int consumeCharacters​(java.io.InputStream is,
                                            byte[] byteBuf,
                                            char[] charBuf,
                                            int bytesToRead)
                                     throws java.io.IOException
        Consume the string of bytesToRead utf-8 bytes. assumes buffers are big enough to hold bytesToRead bytes/chars
        Parameters:
        is - input stream
        byteBuf - a byte buffer
        charBuf - a character buffer
        bytesToRead - the number of bytes to read
        Returns:
        the length of the converted characters
        Throws:
        java.io.IOException - passthru
      • toStream

        public void toStream​(java.io.OutputStream os,
                             Frame f)
                      throws java.io.IOException
        Description copied from interface: FrameTransporter
        Populate the (empty) frame from the stream contents.
        Specified by:
        toStream in interface FrameTransporter
        Parameters:
        os - output stream
        f - frame
        Throws:
        java.io.IOException - passthru
      • elementToBin

        public void elementToBin​(java.io.OutputStream os,
                                 Frame f,
                                 byte[] workbuf)
                          throws java.io.IOException
        Parameters:
        os - output stream
        f - frame
        workbuf - -
        Throws:
        java.io.IOException - passthru
      • stringToBin

        public static void stringToBin​(java.lang.String str,
                                       java.io.OutputStream os)
                                throws java.io.IOException
        Sends a string over, without the type byte.
        Parameters:
        str - the string to send
        os - the output stream
        Throws:
        java.io.IOException - passthru
      • stringToBin

        public static void stringToBin​(java.lang.String str,
                                       java.io.OutputStream os,
                                       byte[] buffer)
                                throws java.io.IOException
        Sends a string as utf8, using the temporary buffer if it is big enough to avoid allocating new memory.
        Parameters:
        str - the string to send
        os - the output stream
        buffer - a buffer
        Throws:
        java.io.IOException - passthru
      • stringToBin

        public static void stringToBin​(char[] str,
                                       int begin,
                                       int len,
                                       java.io.OutputStream os)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • stringToBin

        public static void stringToBin​(char[] str,
                                       int begin,
                                       int len,
                                       java.io.OutputStream os,
                                       byte[] buffer)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeInt

        public static void writeInt​(int write_me,
                                    java.io.OutputStream out)
                             throws java.io.IOException
        Parameters:
        write_me - the integer to write
        out - the output stream
        Throws:
        java.io.IOException - passthru
      • readInt

        public static int readInt​(java.io.InputStream in)
                           throws java.io.IOException
        Parameters:
        in - the input stream
        Returns:
        the integer
        Throws:
        java.io.IOException - if any of the pieces read are negative
      • readFully

        public static void readFully​(byte[] b,
                                     java.io.InputStream in)
                              throws java.io.IOException
        Parameters:
        b - the byte array to read into
        in - the input stream
        Throws:
        java.io.IOException - passthru
      • readFully

        public static void readFully​(byte[] b,
                                     int length,
                                     java.io.InputStream in)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • attributesToBin

        public void attributesToBin​(java.io.OutputStream os,
                                    Attributes attributes,
                                    byte[] workbuf)
                             throws java.io.IOException
        Parameters:
        os - the output stream
        attributes - attributes
        workbuf - a working buffer
        Throws:
        java.io.IOException - passthru