From bb7b71826d7a32752ace2f4574752a401fb7fa0f Mon Sep 17 00:00:00 2001 From: Peter Mount Date: Wed, 14 Feb 2001 17:45:17 +0000 Subject: Web Feb 14 17:29:00 GMT 2001 peter@retep.org.uk - Fixed bug in LargeObject & BlobOutputStream where the stream's output was not flushed when either the stream or the blob were closed. - Fixed PreparedStatement.setBinaryStream() where it ignored the length --- .../org/postgresql/largeobject/LargeObject.java | 30 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java') diff --git a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java index c73301d131..20afda5782 100644 --- a/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java +++ b/src/interfaces/jdbc/org/postgresql/largeobject/LargeObject.java @@ -62,6 +62,10 @@ public class LargeObject private int oid; // OID of this object private int fd; // the descriptor of the open large object + private BlobOutputStream os; // The current output stream + + private boolean closed=false; // true when we are closed + /** * This opens a large object. * @@ -100,9 +104,25 @@ public class LargeObject */ public void close() throws SQLException { - FastpathArg args[] = new FastpathArg[1]; - args[0] = new FastpathArg(fd); - fp.fastpath("lo_close",false,args); // true here as we dont care!! + if(!closed) { + // flush any open output streams + if(os!=null) { + try { + // we can't call os.close() otherwise we go into an infinite loop! + os.flush(); + } catch(IOException ioe) { + throw new SQLException(ioe.getMessage()); + } finally { + os=null; + } + } + + // finally close + FastpathArg args[] = new FastpathArg[1]; + args[0] = new FastpathArg(fd); + fp.fastpath("lo_close",false,args); // true here as we dont care!! + closed=true; + } } /** @@ -279,7 +299,9 @@ public class LargeObject */ public OutputStream getOutputStream() throws SQLException { - return new BlobOutputStream(this); + if(os==null) + os = new BlobOutputStream(this); + return os; } } -- cgit v1.2.1