tags:

views:

40

answers:

2

How can i get the size of an Document object?

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        InputStream iStr = urlConnection.getInputStream();
        doc = db.parse(iStr);

        ???? --> Log.i("Bytes",String.valueOf(doc.get????));
A: 

How about converting the document to string using asXml() and using String.length()?

Seffi
asXml() is not available in android sdk, uses : org.w3c.dom.Document
michel
+1  A: 

One way to implement this would be to write a custom subclass of FilterInputStream that counts the bytes that are read from the stream. (The class would be analogous to LineNumberInputStream ...)

Then wrap the URL stream with your filter:

InputStream iStr = new ByteNumberInputStream(urlConnection.getInputStream());

Finally when you are done reading/parsing the stream, call some method on your filter object to fetch the byte count.

Stephen C