I'm working on a Java program that needs to send an image (preferably in PNG format, though I could perhaps use another format if necessary) over the network. The logical way to do this is, of course, to first send the length of the PNG image data, then the data itself. Problem: I don't see any method in `ImageIO` or anywhere else that will give me the length of the image data. Does this exist somewhere in the Java 1.6 standard library?

I know I could just write it to a `ByteArrayOutputStream` and get the length of the resulting array, but before resorting that I wanted to make sure I'm not missing something built in. And besides, that makes an extra copy of the image data, which I'd rather not do if it's not necessary.