I am trying to decode an EXI encoded string using Open EXI I am getting below exception. Please help.
java.io.EOFException
at org.openexi.proc.io.BodyBitInputStream.getEightBits(Unknown Source)
at org.openexi.proc.io.BitPackedScanner.readEightBitsUnsigned(Unknown Source)
at org.openexi.proc.io.Scanner.readUnsignedInteger(Unknown Source)
at org.openexi.proc.io.Scanner.readLiteralString(Unknown Source)
at org.openexi.proc.io.Scanner.readURI(Unknown Source)
at org.openexi.proc.io.SimpleScanner.readQName(Unknown Source)
at org.openexi.proc.io.SimpleScanner.doElementWildcardAny(Unknown Source)
at org.openexi.proc.io.SimpleScanner.nextEvent(Unknown Source)
at org.openexi.sax.EXIReader.parse(Unknown Source)
at org.openexi.sax.EXIReader.parse(Unknown Source)
at com.exirelated.UserDefinedEXIDecoder.decode(UserDefinedEXIDecoder.java:42)
at com.ethernetservice.SimpleQueue.someMethod(SimpleQueue.java:52)
at com.ethernetservice.SimpleQueue.run(SimpleQueue.java:42)
at java.lang.Thread.run(Unknown Source)
Packet Used :
String XML = "<START><DATA><IE>0.0000</IE><AE>4.319000</AE><PMAC>AA:BB:CC:DD:EE:FF:GG:HH</PMAC></DATA><MAC>AA:BB:CC:DD:EE:FF:GG:HH</MAC></START>";
Last edit: dileep 2013-03-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It appears that you are converting encoded bytes into a Java String by toString() method. Please avoid that conversion, instead, feed the resulting bytes into the decoder directly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I am trying to decode an EXI encoded string using Open EXI I am getting below exception. Please help.
java.io.EOFException
at org.openexi.proc.io.BodyBitInputStream.getEightBits(Unknown Source)
at org.openexi.proc.io.BitPackedScanner.readEightBitsUnsigned(Unknown Source)
at org.openexi.proc.io.Scanner.readUnsignedInteger(Unknown Source)
at org.openexi.proc.io.Scanner.readLiteralString(Unknown Source)
at org.openexi.proc.io.Scanner.readURI(Unknown Source)
at org.openexi.proc.io.SimpleScanner.readQName(Unknown Source)
at org.openexi.proc.io.SimpleScanner.doElementWildcardAny(Unknown Source)
at org.openexi.proc.io.SimpleScanner.nextEvent(Unknown Source)
at org.openexi.sax.EXIReader.parse(Unknown Source)
at org.openexi.sax.EXIReader.parse(Unknown Source)
at com.exirelated.UserDefinedEXIDecoder.decode(UserDefinedEXIDecoder.java:42)
at com.ethernetservice.SimpleQueue.someMethod(SimpleQueue.java:52)
at com.ethernetservice.SimpleQueue.run(SimpleQueue.java:42)
at java.lang.Thread.run(Unknown Source)
I am using the following code :
System.out.println("Packet to be encoded "+packet);
String decodePacket = null;
GrammarCache grammarCache;
short options = GrammarOptions.DEFAULT_OPTIONS;
ByteArrayOutputStream outpu = new ByteArrayOutputStream();
try {
SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory
.newInstance();
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
TransformerHandler transformerHandler = saxTransformerFactory
.newTransformerHandler();
EXIReader reader = new EXIReader();
grammarCache = new GrammarCache(null, options);
reader.setEXISchema(grammarCache);
transformerHandler.setResult(new StreamResult(outpu));
reader.setContentHandler(transformerHandler);
reader.parse(new InputSource((new ByteArrayInputStream(packet.getBytes()))));
decodePacket = outpu.toString();
} catch (Exception e) {
e.printStackTrace();
}
For Encoding :
String encodedPacket=null;
GrammarCache grammarCache;
ByteArrayOutputStream outpu=new ByteArrayOutputStream();
short options = GrammarOptions.DEFAULT_OPTIONS;
try{ Transmogrifier transmogrifier = new Transmogrifier(); grammarCache = new GrammarCache(null, options); transmogrifier.setEXISchema(grammarCache); transmogrifier.setOutputStream(outpu); transmogrifier.encode(new InputSource(new ByteArrayInputStream(packet.getBytes()))); encodedPacket=outpu.toString(); }catch(Exception e){ e.printStackTrace(); }Packet Used :
String XML = "<START><DATA><IE>0.0000</IE><AE>4.319000</AE><PMAC>AA:BB:CC:DD:EE:FF:GG:HH</PMAC></DATA><MAC>AA:BB:CC:DD:EE:FF:GG:HH</MAC></START>";
Last edit: dileep 2013-03-23
It appears that you are converting encoded bytes into a Java String by toString() method. Please avoid that conversion, instead, feed the resulting bytes into the decoder directly.