2 Replies Latest reply: Feb 12, 2007 4:24 PM by DrClap RSS

    How to get the length of inputStream

    807606
      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.
        • 1. Re: How to get the length of inputStream
          807606
          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.
          • 2. Re: How to get the length of inputStream
            DrClap
            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?