Package org.apache.vinci.transport
Class XTalkTransporter
java.lang.Object
org.apache.vinci.transport.XTalkTransporter
- All Implemented Interfaces:
FrameTransporter
Implements XTalk marshalling of Frames.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
static final byte
static final byte[]
static final byte
static final byte
static final byte
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
attributesToBin
(OutputStream os, Attributes attributes, byte[] workbuf) static int
consumeCharacters
(InputStream is, byte[] byteBuf, char[] charBuf, int bytesToRead) Consume the string of bytesToRead utf-8 bytes. assumes buffers are big enough to hold bytesToRead bytes/charsvoid
consumeChildren
(InputStream is, Frame f, int field_count, int marker, byte[] buffer, char[] cbuffer) consumeRootChildren
(InputStream is, Frame f, byte[] buffer, char[] cbuffer) consumeRootElement
(InputStream is, Frame f, byte[] buffer, char[] cbuffer) static String
Consume a string from the input stream.static String
consumeString
(InputStream is, byte[] buffer, char[] cbuffer) void
elementToBin
(OutputStream os, Frame f, byte[] workbuf) fromStream
(InputStream is, Frame f) Parse the data-stream according to the XTalk protocol.fromStreamWork
(InputStream is, Frame f) Once we know that this is an XTalk document, perform XTalk parsing.fromStreamWork
(InputStream is, Frame f, byte[] buffer, char[] cbuffer) protected void
ignorePI
(InputStream is) static void
readFully
(byte[] b, int length, InputStream in) static void
readFully
(byte[] b, InputStream in) static int
readInt
(InputStream in) static void
stringToBin
(char[] str, int begin, int len, OutputStream os) static void
stringToBin
(char[] str, int begin, int len, OutputStream os, byte[] buffer) static void
stringToBin
(String str, OutputStream os) Sends a string over, without the type byte.static void
stringToBin
(String str, 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
(OutputStream os, Frame f) Populate the (empty) frame from the stream contents.static void
writeInt
(int write_me, OutputStream out)
-
Field Details
-
DOCUMENT_MARKER
public static final byte DOCUMENT_MARKER- See Also:
-
ELEMENT_MARKER
public static final byte ELEMENT_MARKER- See Also:
-
PI_MARKER
public static final byte PI_MARKER- See Also:
-
STRING_MARKER
public static final byte STRING_MARKER- See Also:
-
VERSION_CODE
public static final byte VERSION_CODE- See Also:
-
HEADER
public static final byte[] HEADER
-
-
Constructor Details
-
XTalkTransporter
public XTalkTransporter()
-
-
Method Details
-
fromStream
Parse the data-stream according to the XTalk protocol.- Specified by:
fromStream
in interfaceFrameTransporter
- Parameters:
is
- input streamf
- 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
Once we know that this is an XTalk document, perform XTalk parsing.- Parameters:
is
- input streamf
- frame- Returns:
- the key value pair
- Throws:
IOException
- if the versions don't match, or have unexpected element marker
-
fromStreamWork
public KeyValuePair fromStreamWork(InputStream is, Frame f, byte[] buffer, char[] cbuffer) throws IOException - Throws:
IOException
-
ignorePI
- Parameters:
is
- the input stream- Throws:
IOException
- passthru
-
consumeRootChildren
public KeyValuePair consumeRootChildren(InputStream is, Frame f, byte[] buffer, char[] cbuffer) throws IOException - Parameters:
is
- the input streamf
- framebuffer
- -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 streamf
- the Framebuffer
- -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 streamf
- framefield_count
- field countmarker
- markerbuffer
- -cbuffer
- -- Throws:
IOException
- passthru
-
consumeString
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
-
consumeString
public static String consumeString(InputStream is, byte[] buffer, char[] cbuffer) throws IOException - Throws:
IOException
-
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 streambyteBuf
- a byte buffercharBuf
- a character bufferbytesToRead
- the number of bytes to read- Returns:
- the length of the converted characters
- Throws:
IOException
- passthru
-
toStream
Description copied from interface:FrameTransporter
Populate the (empty) frame from the stream contents.- Specified by:
toStream
in interfaceFrameTransporter
- Parameters:
os
- output streamf
- frame- Throws:
IOException
- passthru
-
elementToBin
- Parameters:
os
- output streamf
- frameworkbuf
- -- Throws:
IOException
- passthru
-
stringToBin
Sends a string over, without the type byte.- Parameters:
str
- the string to sendos
- the output stream- Throws:
IOException
- passthru
-
stringToBin
Sends a string as utf8, using the temporary buffer if it is big enough to avoid allocating new memory.- Parameters:
str
- the string to sendos
- the output streambuffer
- a buffer- Throws:
IOException
- passthru
-
stringToBin
- Throws:
IOException
-
stringToBin
public static void stringToBin(char[] str, int begin, int len, OutputStream os, byte[] buffer) throws IOException - Throws:
IOException
-
writeInt
- Parameters:
write_me
- the integer to writeout
- the output stream- Throws:
IOException
- passthru
-
readInt
- Parameters:
in
- the input stream- Returns:
- the integer
- Throws:
IOException
- if any of the pieces read are negative
-
readFully
- Parameters:
b
- the byte array to read intoin
- the input stream- Throws:
IOException
- passthru
-
readFully
- Throws:
IOException
-
attributesToBin
public void attributesToBin(OutputStream os, Attributes attributes, byte[] workbuf) throws IOException - Parameters:
os
- the output streamattributes
- attributesworkbuf
- a working buffer- Throws:
IOException
- passthru
-