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

Input/Output of byte[]-Fields with 'FF' values in LargeObject with JDBC

From: pgsql-bugs(at)postgresql(dot)org
To: pgsql-bugs(at)postgresql(dot)org
Subject: Input/Output of byte[]-Fields with 'FF' values in LargeObject with JDBC
Date: 2001-04-27 11:29:33
Message-ID: (view raw or whole thread)
Lists: pgsql-bugs
wolfgang (w(dot)hickl(at)gis-systemhaus(dot)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);

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 =;
          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 p=0;
// !!! the value of a byte don't care => while(c>-1 && p<length) {
          } catch(IOException se) {
            throw new PSQLException("",se);
          // lob is closed by the stream so don't call lob.close()

=> New Method in org.postgresql.largeobject.BlobInputStream;

     * Read in Byte[]
    public int read(byte[] aByteArray) throws

        try {
            byte buf[] =;
            for (int ii=0; ii < buf.length; ii++)
                aByteArray[ii] = buf[ii];
        catch(SQLException se)
            throw new IOException(se.toString());

    } // ende read(byte[])

Best regards

Sample Code

No file was uploaded with this report

pgsql-bugs by date

Next:From: Alexey NalbatDate: 2001-04-27 12:50:21
Subject: Re: can external C-function get multiple rows?
Previous:From: pgsql-bugsDate: 2001-04-27 09:49:29
Subject: Optimalisation options change query results

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