The [docs](http://docs.oracle.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html#size()) seem to indicate that it returns the number of valid bytes in the stream (which is what we want), and the [source](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/ByteArrayOutputStream.java#160) seems to verify this claim.