|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.knipp.rritoolkit.Codec
public class Codec
Class that performs the conversion to and from byte data, as required for the exchange with the registry server. The class is thread-safe. Various methods are exposed that represent various steps in the conversion, merely to allow investigation of the intermediate data in case of problems.
Field Summary | |
---|---|
protected java.lang.ThreadLocal<javax.xml.parsers.DocumentBuilder> |
builder
the document builder we are using |
protected ResponseFactory |
factory
the response factory we are using |
private static java.util.regex.Pattern |
kvPattern
pattern to decode a key-value pair |
private static java.util.regex.Pattern |
linePattern
pattern to split a key-value list into lines |
private static java.util.regex.Pattern |
sectionPattern
pattern to decode an individual section name |
private static java.util.regex.Pattern |
sectionsPattern
pattern to decode section names line |
protected boolean |
useXml
whether requests/responses shall be encoded/decoded to/from XML |
private static java.nio.charset.Charset |
utf8Charset
the UTF-8 character set |
Constructor Summary | |
---|---|
Codec()
default constructor. |
|
Codec(ResponseFactory theFactory,
boolean xml)
constructor |
Method Summary | |
---|---|
protected void |
addList(KVList list,
java.lang.StringBuilder sb)
add a key-value list to the given string builder |
org.w3c.dom.Document |
bytesToDoc(byte[] data)
convert the byte array to an DOM document |
java.lang.String |
bytesToString(byte[] data)
interpret the given byte array as a sequence of UTF-8 encoded characters and return it as a string. |
Response |
decodeResponse(byte[] data,
Request req)
convert the given byte sequence to a response object. |
byte[] |
docToBytes(org.w3c.dom.Document doc)
convert the DOM document to a sequence of bytes |
Response |
docToResponse(org.w3c.dom.Document doc,
Request req)
convert the document to a response |
byte[] |
encodeRequest(Request req)
convert the given request to a byte sequence |
protected javax.xml.parsers.DocumentBuilder |
getBuilder()
return the document builder that shall be used for parsing and generating XML |
Response |
listToResponse(KVMultiList list,
Request request)
convert the list to the response instance |
java.lang.String |
listToString(KVList list)
convert a key-value list to a string |
java.lang.String |
listToString(KVMultiList list)
convert a key-value multilist to a string. |
org.w3c.dom.Document |
requestToDoc(Request req)
convert the request to an XML document |
KVList |
requestToList(Request req)
convert the given request to a list |
byte[] |
stringToBytes(java.lang.String text)
return the given string in the UTF-8 representation |
KVMultiList |
stringToList(java.lang.String text)
parse the given string into a key-value list |
boolean |
xmlUsed()
return whether XML is used for encoding |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ResponseFactory factory
protected boolean useXml
protected java.lang.ThreadLocal<javax.xml.parsers.DocumentBuilder> builder
private static final java.util.regex.Pattern linePattern
private static final java.util.regex.Pattern kvPattern
private static final java.util.regex.Pattern sectionsPattern
private static final java.util.regex.Pattern sectionPattern
private static final java.nio.charset.Charset utf8Charset
Constructor Detail |
---|
public Codec(ResponseFactory theFactory, boolean xml)
theFactory
- the response factory to usexml
- whether to operate with XML
(true
) or key-value pairs
(false
)public Codec()
Method Detail |
---|
public byte[] encodeRequest(Request req) throws EncodeException
req
- the request
EncodeException
- if the encoding process failedpublic Response decodeResponse(byte[] data, Request req) throws ResponseParseException
data
- the datareq
- the request, may be null
ResponseParseException
- if problems occurred during the parsing
of the datapublic boolean xmlUsed()
true
if sopublic KVList requestToList(Request req) throws EncodeException
req
- the request
EncodeException
- if the encoding process failedprotected void addList(KVList list, java.lang.StringBuilder sb)
list
- the list to addsb
- the string builder to usepublic java.lang.String listToString(KVList list)
list
- the list
public java.lang.String listToString(KVMultiList list)
list
- the list
public byte[] stringToBytes(java.lang.String text)
text
- the string
public Response listToResponse(KVMultiList list, Request request) throws ResponseParseException
list
- the listrequest
- the request, may be null
if not available
ResponseParseException
- if the response could not be created
based on the inputpublic KVMultiList stringToList(java.lang.String text) throws ResponseParseException
text
- the text to parse
ResponseParseException
- if the parsing failedpublic java.lang.String bytesToString(byte[] data) throws java.io.IOException
data
- the data
java.io.IOException
- if the conversion failedprotected javax.xml.parsers.DocumentBuilder getBuilder()
public org.w3c.dom.Document requestToDoc(Request req) throws EncodeException
req
- the request
EncodeException
- if the encoding failedpublic byte[] docToBytes(org.w3c.dom.Document doc) throws EncodeException
doc
- the document to convert
EncodeException
- if the serialization failedpublic Response docToResponse(org.w3c.dom.Document doc, Request req) throws ResponseParseException
doc
- the documentreq
- the request
ResponseParseException
- if the parsing failedpublic org.w3c.dom.Document bytesToDoc(byte[] data) throws ResponseParseException
data
- the data
ResponseParseException
- if the parsing failed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |