Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and - Mailing list pgsql-bugs

From Martin Holz
Subject Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and
Date
Msg-id 200401091212.39206.holz@fiz-chemie.de
Whole thread Raw
In response to Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and  (Kris Jurka <books@ejurka.com>)
Responses Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and
List pgsql-bugs
On Friday 09 January 2004 09:46, Kris Jurka wrote:
> On Wed, 7 Jan 2004, Martin Holz wrote:
> > Hello,
> >
> > org.postgresql.jdbc1.AbstractJdbc1Statement.setBinaryStream()
> > in postgresql 7.4.1 wrongly assumes, that
> > java.io.InputStream.read(byte[] b,int offset,int len )
> > will always read len bytes. InputStream only guarantees to
> > return at least 1 byte per call. The attached patch solves the
> > bug.
>
> Yes, it can even return 0 bytes if it feels like it.

Only if len is 0. From javadoc:
 * If len is zero, then no bytes are read and 0 is returned;
 * otherwise, there is an attempt to read at least one byte. If no
 *  byte is available because the stream is at end of file, the value
 * -1 is returned; otherwise, at least one byte is read and stored
 * into b.

> The odd thing about the javadocs is that they say "The data will be
> read from the stream as needed until end-of-file is reached."  The
> length parameter's comment is "the number of bytes in the stream."

Don't know, which version of Javadoc you use.

http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[],%20int,%20int)
seems pretty clear to me.

> This is strange because it seems to imply that the length argument
> is just for informational purposes and should not be used to limit
> the amount of data actually read from the stream.

As I read the documentation, unless len == 0, at least
1, but not more then len bytes are read.
If no input  is available the method will block. Otherwise the
method will return len bytes if possible,but less if it would
block otherwise.

Martin

--
Martin Holz     <holz@fiz-chemie.de>

Softwareentwicklung / Vernetztes Studium - Chemie
FIZ CHEMIE Berlin
Franklin Str. 11
D-10587 Berlin

pgsql-bugs by date:

Previous
From: Kris Jurka
Date:
Subject: Re: JDBC driver doesn't handle NaN values
Next
From: Martin Holz
Date:
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and