How can I know how many bytes had been received from an InputStream?

M

maurora

Hi all,

I use KXML to parser xml file (InputStream) by TCP protocol. I want to
display the percent of received bytes of the whole xml file. But I
cannnot find any method in InputStream or KXML which can tell me that
data.

Thank you very much for your help.

Sincerely,
Maurora
 
A

Andrew Thompson

maurora wrote:
....
I use KXML ..

Do you mean this one? <http://kxml.sourceforge.net/>

I saw one link that suggested it was geared to
J2ME - though I cannot see 'J2Me' on the
sourceforge page. Is it oriented to J2ME?

(If it is that one, note they have a mailing list amongst
the links on the left - might be a good place for more
specialised help.)

Andrew T.
 
S

sgoo

Haven't played with this KXML. Does it have a constructor that takes an
InputStream type as an argument? If so, you can create your own version
of CountingBytesInputStream which acts as a filter. Something like
this:

class CountingBytesInputStream extends FilterInputStream {
... // implements methods that call super's methods
int getCount() {
...
}
}

Then you can call:
CountingBytesInputStream cbis = new
CountingBytesInputStream(inStream);
KXML k = new KXML(cbls);
....
System.err.println(clbs.getCount());

You can even add a callback into this class. For example, the
constructor can be
CountingBytesInputStream(Updater u, InputStream stream) {
this.updater = u;
}

And then you can call it in the overriden read methods like this
int read(...) {
.....
if (count % 1024 == 0) updater.notify(count);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top