<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1555" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=904401911-08082006><FONT face=Arial color=#0000ff size=2>This
is an un-necessarily memory-demanding mechanism for doing it. The complete
document is required to be stored in the bytearray, and will need garbage
collection, etc.</FONT></SPAN></DIV>
<DIV><SPAN class=904401911-08082006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=904401911-08082006><FONT face=Arial color=#0000ff size=2>A
faster, and more memory friendly way to do it would be to create a class like
what's at the end, and use it instead of the
ByteArrayOutputStream.</FONT></SPAN></DIV>
<DIV><SPAN class=904401911-08082006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial><FONT size=2><FONT color=#0000ff><SPAN
class=904401911-08082006>Rolf</SPAN><SPAN
class=904401911-08082006></SPAN></FONT></FONT></FONT></DIV>
<DIV><SPAN class=904401911-08082006><B><FONT color=#7f0055>
<P align=left><FONT size=2>import</FONT></B></FONT><FONT size=2>
java.io.IOException;</FONT></P><B><FONT color=#7f0055>
<P align=left><FONT size=2>import</FONT></B></FONT><FONT size=2>
java.io.OutputStream;</FONT></P>
<P align=left><FONT size=2></FONT></P><B><FONT color=#7f0055>
<P align=left><FONT size=2>public</FONT></B></FONT><FONT size=2> <B><FONT
color=#7f0055>final</B></FONT></FONT><FONT size=2> <B><FONT
color=#7f0055>class</B></FONT></FONT><FONT size=2> CountingDevNull<SPAN
class=904401911-08082006>OutputStream</SPAN> <B><FONT
color=#7f0055>extends</B></FONT></FONT><FONT size=2> OutputStream {</FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>private</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>int</B></FONT></FONT><FONT size=2> <FONT
color=#0000c0>count</FONT> = 0;</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2> reset()
{</FONT></P>
<P align=left><FONT size=2><FONT color=#0000c0>count</FONT> = 0;</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>int</B></FONT></FONT><FONT size=2> size()
{</FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>return</FONT></B></FONT><FONT
size=2> <FONT color=#0000c0>count</FONT>;</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2>
write(<B><FONT color=#7f0055>int</B></FONT></FONT><FONT size=2> b) <B><FONT
color=#7f0055>throws</B></FONT></FONT><FONT size=2> IOException {</FONT></P>
<P align=left><FONT size=2><FONT color=#0000c0>count</FONT>++;</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2> close()
<B><FONT color=#7f0055>throws</B></FONT></FONT><FONT size=2> IOException
{</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2> flush()
<B><FONT color=#7f0055>throws</B></FONT></FONT><FONT size=2> IOException
{</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2>
write(<B><FONT color=#7f0055>byte</B></FONT></FONT><FONT size=2>[] b, <B><FONT
color=#7f0055>int</B></FONT></FONT><FONT size=2> off, <B><FONT
color=#7f0055>int</B></FONT></FONT><FONT size=2> len) <B><FONT
color=#7f0055>throws</B></FONT></FONT><FONT size=2> IOException {</FONT></P>
<P align=left><FONT size=2><FONT color=#0000c0>count</FONT> += len;</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2></FONT></P>
<P align=left><B><FONT color=#7f0055><FONT size=2>public</FONT></B></FONT><FONT
size=2> <B><FONT color=#7f0055>void</B></FONT></FONT><FONT size=2>
write(<B><FONT color=#7f0055>byte</B></FONT></FONT><FONT size=2>[] b) <B><FONT
color=#7f0055>throws</B></FONT></FONT><FONT size=2> IOException {</FONT></P>
<P align=left><FONT size=2><FONT color=#0000c0>count</FONT> += b.<FONT
color=#0000c0>length</FONT>;</FONT></P>
<P align=left><FONT size=2>}</FONT></P>
<P align=left><FONT size=2>}</FONT></P></SPAN></DIV>
<DIV><SPAN class=904401911-08082006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B>
jdom-interest-bounces@jdom.org [mailto:jdom-interest-bounces@jdom.org]<B>On
Behalf Of </B>Søren Faltz<BR><B>Sent:</B> Tuesday, August 08, 2006 6:09
AM<BR><B>To:</B> jdom-interest@jdom.org<BR><B>Subject:</B> Re: [jdom-interest]
How many bytes is my JDOM Document<BR><BR></FONT></DIV>
<DIV>I am determing the size this way</DIV>
<DIV> </DIV>
<DIV>
<P>String s;<BR> int contentLength=0;</P>
<P> try {<BR> s =
convertDocumentToString(doc);<BR>
<BR> ByteArrayOutputStream bout = new
ByteArrayOutputStream();<BR> ObjectOutputStream
objOut = new ObjectOutputStream(bout);<BR>
<BR> objOut.writeObject
(s);<BR> contentLength = bout.size();</P>
<P>
objOut.flush();<BR> bout.flush();
</P><BR><BR> </DIV>
<DIV><SPAN class=gmail_quote>2006/8/4, Paul Libbrecht <<A
href="mailto:paul@activemath.org">paul@activemath.org</A>>:</SPAN>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Print
it to a stream that only counts but otherwise discards ? It's easy<BR>to
write such a stream... just subclass outputstream.write(byte) and<BR>maybe
.write(byte[],start,len) and count...<BR><BR>I don't think there's a way
without outputting.<BR><BR>paul<BR><BR>Søren Faltz wrote:<BR>> I want to
find out how many bytes my document is. <BR>> An easy way would be to
stream the document to disk, and then call<BR>> File.size()<BR>> but
is there any way to find out without saving the document to disk<BR>>
first??<BR><BR><BR><BR></BLOCKQUOTE></DIV><BR></BLOCKQUOTE></BODY></HTML>
<BR>
<P>This email and any files transmitted with it are confidential and proprietary to Algorithmics Incorporated and its affiliates ("Algorithmics"). If received in error, use is prohibited. Please destroy, and notify sender. Sender does not waive confidentiality or privilege. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. Algorithmics does not accept liability for any errors or omissions. Any commitment intended to bind Algorithmics must be reduced to writing and signed by an authorized signatory.</P>