[Beepcore-java-users] reading from InputDataStream ends prematurely
Status: Beta
Brought to you by:
huston
From: Lukas Z. <zb...@ht...> - 2005-12-07 09:31:28
|
Hi I was wondering if someone knows the following problem and if a workaround was found for it. At the recipient site of a channel connection, I read the InputDataStream as follows (containing XML): public class MyRequestHandler implements RequestHandler { public void receiveMSG(MessageMSG message) { InputDataStream input = message.getDataStream(); byte[] rawData = read(input); message.sendNul(); //parse XML... } public static byte[] read(InputDataStream stream) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); do { BufferSegment b = stream.waitForNextSegment(); if (b == null) { continue; } out.write(b.getData()); } while (!stream.isComplete()); out.flush(); return out.toByteArray(); } } When the sender site sends many messages in a short time (channel.sendMSG(..) called at a high rate), it results in an incomplete reading at the recipient site from the InputDataStream delivered by the MessageMSG instance. I.e. it prematurely ends in method read() and finally results in an XML parsing exception (since not all data and XML, respectively, are read). Does anyone know that problem? Is it a bug in Java beepcore or am I reading the InputDataStream the wrong way? I do have ensured that only one thread executes receiveMSG() at a time. Another interesting issue: Does it matter if sendNul() is called before or after reading the InputDataStream? Thanks for any thoughts... -- Lukas |