[jdom-interest] determining output length
Noah Levitt
nlevitt at gmail.com
Fri Mar 3 10:35:51 PST 2006
I actually did it using by writing the byte counting output stream
pasted below, running the output through it and looking at size().
Thought I might be missing a better way, but I guess not. :o)
Noah
public class ByteCountingOutputStream extends java.io.OutputStream
{
private int count;
public ByteCountingOutputStream()
{
count = 0;
}
public int size()
{
return count;
}
public void write(byte[] b)
{
count += b.length;
}
public void write(byte[] b, int off, int len)
{
if (off < 0 || len < 0 || off + len > b.length)
throw new IndexOutOfBoundsException();
count += len;
}
public void write(int b)
{
count++;
}
}
2006/3/3, Jason Winnebeck <gillius-ml at gillius.org>:
> I'm not sure if that is possible, but in the worst-case scenario, you
> could write it to a memory buffer, then find the size of that buffer and
> then send that buffer. XMLOutputter takes an OutputStream, and there
> does exist ByteArrayOutputStream.
>
> Jason
>
> Noah Levitt wrote:
> > How is a person supposed to determine the output length when writing
> > out xml with XMLOutputter? This would be handy for setting content
> > length header in http request or response.
> >
> > Noah
> >
> > _______________________________________________
> > To control your jdom-interest membership:
> > http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
>
More information about the jdom-interest
mailing list