Hi group,
since my last mail made it through, I assume that the previous one
just magically diappeared. Here it is again:
I have a problem when trying to use the getInputStream()/getOutputStream()
methods of LargeObject. The problem is demonstrated by the code I append
to this post.
There I create a LargeObject and put there all numbers from 100 to
2000 as shorts. Afterwards, I re-open this object by its oid, read
itout and print it on the screen.
The funny thing is that the program stops after writing the 127 on the
screen. So, either the writing was silently stopping with number 128,
or the reader creates a EOFException when the 8th bit was set.
The Postgresql version is 7.2.2, the jdbc driver is jdbc7.1-1.2.jar,
both directly from the SuSE 8.1 CD.
What is the cause of that and what can I do to get a correct behaviour?
Is it a bug or did I just not carefully read the manual?
Ciao
Ole
This is the Code:
---------------------------------8<------------------------------------------
import java.io.*;
import java.sql.*;
import org.postgresql.largeobject.*;
public class PgTest {
public static void main (String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection dbConn
= DriverManager.getConnection("jdbc:postgresql:ole", "ole", "nixda");
dbConn.setAutoCommit(false);
LargeObjectManager lobjm =
((org.postgresql.Connection)dbConn).getLargeObjectAPI();
int oid = lobjm.create(LargeObjectManager.READ
| LargeObjectManager.WRITE);
System.out.println("Oid is " + oid);
// *** 1st Step: write 1900 shorts ***
LargeObject wobj = lobjm.open(oid, LargeObjectManager.WRITE);
DataOutputStream dos = new DataOutputStream(wobj.getOutputStream());
for (short i = 100; i < 2000; i++) {
dos.writeShort(i);
}
dos.close();
wobj.close();
dbConn.commit();
// *** 2nd Step: read these shorts back from the same OID ***
LargeObject robj = lobjm.open(oid, LargeObjectManager.READ);
DataInputStream is = new DataInputStream(robj.getInputStream());
try {
while (true) {
System.out.println(is.readShort());
}
} catch (EOFException e) {
System.out.println("End of file reached.");
}
robj.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}