db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sure...@apache.org
Subject svn commit: r520684 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/load/ExportWriteData.java testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
Date Wed, 21 Mar 2007 00:42:17 GMT
Author: suresht
Date: Tue Mar 20 17:42:16 2007
New Revision: 520684

URL: http://svn.apache.org/viewvc?view=rev&rev=520684
Log:
DERBY-2456 (export file stream was not closed when export fails due 
to an invalid codeset).

This patch closes file streams correctly, if any exception occurs 
while setting up the streams required to perform export. Re-enabled the test 
case in ImportExportTest.java that was disabled earlier due to this bug.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java?view=diff&rev=520684&r1=520683&r2=520684
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/load/ExportWriteData.java Tue Mar
20 17:42:16 2007
@@ -103,28 +103,62 @@
 		  lobsFileName = url.getFile();
 	  }
     } catch (MalformedURLException ex) {}
-    FileOutputStream anOutputStream = new FileOutputStream(outputFileName);
-    BufferedOutputStream buffered = new BufferedOutputStream(anOutputStream);
+
+    
+    FileOutputStream anOutputStream = null;
+    BufferedOutputStream buffered = null;
+    FileOutputStream lobOutputStream = null;
+
+    try {
+        anOutputStream = new FileOutputStream(outputFileName);
+        buffered = new BufferedOutputStream(anOutputStream);
     
-    aStream = dataCodeset == null ?
+        aStream = dataCodeset == null ?
     		new OutputStreamWriter(buffered) :
     		new OutputStreamWriter(buffered, dataCodeset);    	        
 
-    // if lobs are exported to an external file, then 
-    // setup the required streams to write lob data.
-    if (lobsInExtFile) 
-    {
-        // setup streams to write large objects into the external file. 
-        FileOutputStream lobOutputStream = new FileOutputStream(lobsFileName);
-        lobOutBinaryStream = new BufferedOutputStream(lobOutputStream);
-
-        // helper stream to convert char data to binary, after conversion
-        // data is written to lobOutBinaryStream.
-        lobByteArrayStream = new ByteArrayOutputStream();
-        lobCharStream =  dataCodeset == null ?
-            new OutputStreamWriter(lobByteArrayStream) :
-            new OutputStreamWriter(lobByteArrayStream, dataCodeset);    	        
-	}
+        // if lobs are exported to an external file, then 
+        // setup the required streams to write lob data.
+        if (lobsInExtFile) 
+        {
+            // setup streams to write large objects into the external file. 
+            lobOutputStream = new FileOutputStream(lobsFileName);
+            lobOutBinaryStream = new BufferedOutputStream(lobOutputStream);
+
+            // helper stream to convert char data to binary, after conversion
+            // data is written to lobOutBinaryStream.
+            lobByteArrayStream = new ByteArrayOutputStream();
+            lobCharStream =  dataCodeset == null ?
+                new OutputStreamWriter(lobByteArrayStream) :
+                new OutputStreamWriter(lobByteArrayStream, dataCodeset);    	        
+        }
+    } catch (Exception e) {
+        // might have failed to setup export file stream. for example 
+        // user has specified invalid codeset or incorrect file path. 
+        // close the opened file streams.
+
+        if (aStream == null) {
+            if (buffered != null) {
+                buffered.close();
+            } else {
+                if(anOutputStream != null)
+                    anOutputStream .close();
+            }
+        } else {
+            // close the main export file stream.
+            aStream.close();
+            // close the external lob file stream.
+            if (lobOutBinaryStream != null) {
+                lobOutBinaryStream.close() ;
+            } else {
+                if (lobOutputStream != null) 
+                    lobOutputStream.close();
+            }
+        }
+
+        // throw back the original exception.
+        throw e;
+    }
   }
 
   /**if control file says true for column definition, write it as first line of the

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java?view=diff&rev=520684&r1=520683&r2=520684
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/tools/ImportExportTest.java
Tue Mar 20 17:42:16 2007
@@ -151,10 +151,7 @@
 		doImportAndExport(c, "T1", "%", "&", "UTF-16");
 	}
 	
-    /* This test is disabled temporarily due to bug : DERBY-2456 .
-     * Remove the prefix "derby2456"  when the bug is fixed.
-     */
-	public void derby2456testInvalidEncoding() throws Exception {
+	public void testInvalidEncoding() throws Exception {
 		Connection c = getConnection();
 		resetTables();
 		try {



Mime
View raw message