wolfgang (w.hickl@gis-systemhaus.de) reports a bug with a severity of 2
The lower the number the more severe it is.
Short Description
Input/Output of byte[]-Fields with 'FF' values in LargeObject with JDBC
Long Description
The following Java-Code don't work because of the "0xff" values
in the byteField:
byte[] byteField = new byte[6];
byteField[0] = (new Integer(0xff).byteValue());
byteField[1] = (new Integer(0xff).byteValue());
byteField[2] = (new Integer(0x00).byteValue());
byteField[3] = (new Integer(0x02).byteValue());
byteField[4] = (new Integer(0x53).byteValue());
ByteArrayInputStream byteStream =
new ByteArrayInputStream(byteField);
psta.setBinaryStream(blobIdx,byteStream,byteField.length);
My changes in the JDBC-Driver to fix this problem:
=> Change in org.postgresql.jdbc2.PreparedStatement
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException
{
LargeObjectManager lom = connection.getLargeObjectAPI();
int oid = lom.create();
LargeObject lob = lom.open(oid);
OutputStream los = lob.getOutputStream();
try {
// could be buffered, but then the OutputStream returned by LargeObject
// is buffered internally anyhow, so there would be no performance
// boost gained, if anything it would be worse!
int c=x.read();
int p=0;
// !!! the value of a byte don't care => while(c>-1 && p<length) {
while(p<length)
{
los.write(c);
c=x.read();
p++;
}
los.close();
} catch(IOException se) {
throw new PSQLException("postgresql.prep.is",se);
}
// lob is closed by the stream so don't call lob.close()
setInt(parameterIndex,oid);
}
=> New Method in org.postgresql.largeobject.BlobInputStream;
/**
* Read in Byte[]
*/
public int read(byte[] aByteArray) throws java.io.IOException
{
try {
byte buf[] = lo.read(aByteArray.length);
for (int ii=0; ii < buf.length; ii++)
{
aByteArray[ii] = buf[ii];
}
return(buf.length);
}
catch(SQLException se)
{
throw new IOException(se.toString());
}
} // ende read(byte[])
Best regards
Wolfgang
Sample Code
No file was uploaded with this report