How to get the length of inputStream

Hi,Could someone tell me how to get length of inputStream?The inputStream is generated on the fly and will be written into database.I can use temporary FileInputStream to get the length. But it looks awful. Do we have any elegant way?Thanks in advance.
[287 byte] By [helenhelena] at [2007-11-26 18:13:20]
# 1

Are you referring to PreparedStatement's:

void setBinaryStream(int parameterIndex, InputStream x, int length)

That length is a pain. If needed, I use ByteArrayOutput/InputStream in this case.

DrLaszloJamfa at 2007-7-9 5:46:22 > top of Java-index,Java Essentials,Java Programming...
# 2

You can't know how many bytes you will read from an InputStream, in general, until you read them. It's possible that a particular subclass could give you this information but you can't expect all subclasses to do that.

If you're asking because you need a number to give to PreparedStatement.setBinaryStream, have you tried passing zero for that parameter? Or Integer.MAX_VALUE?

DrClapa at 2007-7-9 5:46:22 > top of Java-index,Java Essentials,Java Programming...