Class XTalkTransporter

    • Constructor Detail

      • XTalkTransporter

        public XTalkTransporter()
    • Method Detail

      • fromStream

        public KeyValuePair fromStream​(InputStream is,
                                       Frame f)
                                throws IOException,
                                       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:
        IOException - -
        EOFException - -
      • fromStreamWork

        public KeyValuePair fromStreamWork​(InputStream is,
                                           Frame f)
                                    throws 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:
        IOException - if the versions don't match, or have unexpected element marker
      • consumeRootChildren

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

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

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

        public static String consumeString​(InputStream is)
                                    throws 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:
        IOException - if key is longer than limit
      • consumeCharacters

        public static int consumeCharacters​(InputStream is,
                                            byte[] byteBuf,
                                            char[] charBuf,
                                            int bytesToRead)
                                     throws 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:
        IOException - passthru
      • stringToBin

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

        public static void stringToBin​(String str,
                                       OutputStream os,
                                       byte[] buffer)
                                throws 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:
        IOException - passthru
      • writeInt

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

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

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

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