Skip site navigation (1) Skip section navigation (2)

Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and

From: Martin Holz <holz(at)fiz-chemie(dot)de>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and
Date: 2004-01-09 11:18:31
Message-ID: 200401091218.38015.holz@fiz-chemie.de (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-jdbc
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.
>
> > Btw. setBinaryStream() should really throw an SQLException, if
> > in can not read as many bytes as expected from the InputStream.
> > Otherwise the application might silently loss data.
>
> 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."

You seem to use a other javadoc than me.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#read(byte[],%20int,%20int)
is pretty clear.

> 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.

At least 1 byte will be read unless len == 0. No more 
than len bytes will be read. Within this limit read is
free to return as many bytes as it considers
efficient.

Martin

-- 
Martin Holz     <holz(at)fiz-chemie(dot)de>

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

In response to

pgsql-bugs by date

Next:From: Kris JurkaDate: 2004-01-09 16:18:27
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and
Previous:From: Martin HolzDate: 2004-01-09 11:12:39
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and

pgsql-jdbc by date

Next:From: Dave CramerDate: 2004-01-09 13:46:46
Subject: Re: PreparedStatement parameters and mutable objects
Previous:From: Martin HolzDate: 2004-01-09 11:12:39
Subject: Re: jdbc1.AbstractJdbc1Statement.setBinaryStream bug and

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group