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

Discussion in 'Java' started by maurora, Nov 26, 2006.

  1. maurora

    maurora Guest

    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

    Thank you very much for your help.

    maurora, Nov 26, 2006
    1. Advertisements

  2. maurora wrote:
    Do you mean this one? <>

    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.
    Andrew Thompson, Nov 26, 2006
    1. Advertisements

  3. maurora

    sgoo Guest

    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

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

    Then you can call:
    CountingBytesInputStream cbis = new
    KXML k = new KXML(cbls);

    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);
    sgoo, Nov 26, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.