db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1147219 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/largedata/LobLimitsLiteTest.java tests/largedata/LobLimitsTest.java tests/largedata/build.xml util/PrivilegedFileOpsForTests.java
Date Fri, 15 Jul 2011 16:32:31 GMT
Author: kmarsden
Date: Fri Jul 15 16:32:31 2011
New Revision: 1147219

URL: http://svn.apache.org/viewvc?rev=1147219&view=rev
Log:
DERBY-1903 Convert largedata/LobLimits.java to junit

Initial patch to convert embedded test to JUnit.
derby-1903_embeddedp1_diff.txt converts test to LobLimitsTest.java and adds LobLimitsLiteTest.java which runs the test with smaller lobs. 


Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsTest.java
      - copied, changed from r1146438, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimits.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/build.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java?rev=1147219&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java Fri Jul 15 16:32:31 2011
@@ -0,0 +1,66 @@
+/*
+
+Derby - Class org.apache.derbyTesting.functionTests.tests.largedata.LobLimitsLiteTest
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+*/
+
+package org.apache.derbyTesting.functionTests.tests.largedata;
+
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+
+
+
+/**
+ * LobLimitsLiteTest tests all the same functionality of 
+ * LobLimitsTest but with smaller Clobs and Blobs, so that
+ * the test can be run with suites.All. This 
+ * helps us ensure the basic functionality does not regress.
+ *   
+ */
+
+public class LobLimitsLiteTest extends LobLimitsTest {
+
+    public LobLimitsLiteTest(String name) {
+        super(name);
+   
+    }
+
+    static final int _1MB = 1024*1024;
+    static final int _100K = 1024 *100;
+    
+    public static Test suite() {
+        // Right now run just with embeddded.
+        Test suite = new CleanDatabaseTestSetup(
+                new TestSuite(LobLimitsTest.class)) {
+                    protected void decorateSQL(Statement s)
+                            throws SQLException {
+                        setupTables(s,_1MB, _100K);
+                    }
+                };
+                
+        return new SupportFilesSetup(suite);
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsLiteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsTest.java (from r1146438, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimits.java)
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsTest.java?p2=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimits.java&r1=1146438&r2=1147219&rev=1147219&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimits.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/LobLimitsTest.java Fri Jul 15 16:32:31 2011
@@ -1,6 +1,6 @@
 /*
 
-Derby - Class org.apache.derbyTesting.functionTests.tests.largedata.LobLimits
+Derby - Class org.apache.derbyTesting.functionTests.tests.largedata.LobLimitsTest
 
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
@@ -21,11 +21,34 @@ limitations under the License.
 
 package org.apache.derbyTesting.functionTests.tests.largedata;
 
-import java.sql.*;
-import java.io.*;
 
-import org.apache.derby.tools.ij;
-import org.apache.derby.tools.JDBCDisplayUtil;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+
 
 /**
 * This test is part of the "largedata" suite because this test tests data for
@@ -35,176 +58,81 @@ import org.apache.derby.tools.JDBCDispla
 * no regression has occurred.
 */
 
-public class LobLimits {
+public class LobLimitsTest extends BaseJDBCTestCase {
+
+   public LobLimitsTest(String name) {
+        super(name);
+    }
+
+static boolean trace = false;
 
-   static boolean trace = false;
    static final int _2GB = 2 * 1024 * 1024* 1024 - 1;
    static final int _100MB = 100 * 1024 * 1024;
-   static final int MORE_DATA_THAN_COL_WIDTH= (_100MB)+1;
+   static final long _4GB =  4*1024*1024*(1024L);
    static final int NUM_TRAILING_SPACES = 33*1024;
    
-   static PreparedStatement insertBlob = null;
-   static PreparedStatement selectBlob = null;
-   static PreparedStatement insertClob = null;
-   static PreparedStatement selectClob = null;
-   static PreparedStatement deleteBlob = null;
-   static PreparedStatement deleteClob = null;
-   static PreparedStatement insertBlob2 = null;
-   static PreparedStatement selectBlob2 = null;
-   static PreparedStatement insertClob2 = null;
-   static PreparedStatement selectClob2 = null;
-   static PreparedStatement deleteBlob2 = null;
-   static PreparedStatement deleteClob2 = null;
+   
+   static int BIGGEST_LOB_SZ= _2GB;
 
-   static final String DATAFILE = "byteLobLimits.dat";
+   public static void setBIGGEST_LOB_SZ(int bIGGESTLOBSZ) {
+    BIGGEST_LOB_SZ = bIGGESTLOBSZ;
+}
 
-   static final String CHARDATAFILE = "charLobLimits.txt";
+static int BIG_LOB_SZ = _100MB;
 
-   /**
-    * setup prepared statements and schema for the tests
-    * @param conn
-    * @throws SQLException
-    */
-   private void setup(Connection conn) throws SQLException {
-       System.out.println("-----------------------------------");
-       System.out.println(" START setup");
+   public static void setBIG_LOB_SZ(int bIGLOBSZ) {
+    BIG_LOB_SZ = bIGLOBSZ;
+}
+   static int MORE_DATA_THAN_COL_WIDTH= (_100MB)+1;
 
-       conn.setAutoCommit(true);
-       // Create a test table.
-       Statement s = conn.createStatement();
-       try {
-           s.execute("DROP TABLE BLOBTBL");
-       } catch (Exception e) {
-       }
-       try {
-           s.execute("DROP TABLE CLOBTBL");
-       } catch (Exception e) {
-       }
-       try {
-           s.execute("DROP TABLE BLOBTBL2");
-       } catch (Exception e) {
-       }
-       try {
-           s.execute("DROP TABLE CLOBTBL2");
-       } catch (Exception e) {
-       }
+   public static void setMORE_DATA_THAN_COL_WIDTH(int mOREDATATHANCOLWIDTH) {
+    MORE_DATA_THAN_COL_WIDTH = mOREDATATHANCOLWIDTH;
+}
 
-       s.execute("CREATE TABLE BLOBTBL (ID INT NOT NULL PRIMARY KEY, "
-               + "POS BIGINT, DLEN BIGINT, CONTENT BLOB(2G))");
+static final String DATAFILE = "extinout/byteLobLimits.dat";
 
-       insertBlob = conn
-               .prepareStatement("INSERT INTO BLOBTBL values (?,?,?,?)");
+   static final String CHARDATAFILE = "extinout/charLobLimits.txt";
 
+  
+    /**
+     * Setup the schema and the blob sizes for the test.
+     * @param s
+     * @param biggestlobsz 
+     * @param biglobsz
+     * @throws SQLException
+     */
+    static void setupTables(Statement s, int biggestlobsz, int biglobsz ) throws SQLException {
+       setBIGGEST_LOB_SZ(biggestlobsz);
+       setBIG_LOB_SZ(biglobsz);
+       setMORE_DATA_THAN_COL_WIDTH(biglobsz +1);
+       println("BIGGEST_LOB_SZ=" + BIGGEST_LOB_SZ + " BIG_LOB_SZ=" + BIG_LOB_SZ);
+       Connection conn = s.getConnection();
+       conn.setAutoCommit(true);
+       s.execute("CREATE TABLE BLOBTBL (ID INT NOT NULL PRIMARY KEY, "
+               + "POS BIGINT, DLEN BIGINT, CONTENT BLOB(2G))");
        s.execute("CREATE TABLE CLOBTBL (ID INT NOT NULL PRIMARY KEY,"
                + "POS BIGINT, DLEN BIGINT, CONTENT CLOB(2G))");
-
-       insertBlob = conn
-               .prepareStatement("INSERT INTO BLOBTBL values (?,?,?,?)");
-       selectBlob = conn
-               .prepareStatement("SELECT CONTENT,DLEN FROM BLOBTBL WHERE ID = ?");
-
-       insertClob = conn
-               .prepareStatement("INSERT INTO CLOBTBL values (?,?,?,?)");
-
-       selectClob = conn
-               .prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL WHERE ID = ?");
-
-       deleteBlob = conn.prepareStatement("DELETE FROM BLOBTBL");
-       deleteClob = conn.prepareStatement("DELETE  from CLOBTBL");
-
        s.execute("CREATE TABLE BLOBTBL2 (ID INT NOT NULL PRIMARY KEY, "
-               + "POS BIGINT, CONTENT BLOB("+_100MB+"),DLEN BIGINT)");
-
-       insertBlob2 = conn
-               .prepareStatement("INSERT INTO BLOBTBL2 values (?,?,?,?)");
+               + "POS BIGINT, CONTENT BLOB("+BIG_LOB_SZ+"),DLEN BIGINT)");
 
        // Please dont change the clob column width,since tests use this width to 
        // test for truncation of trailing spaces.
        s.execute("CREATE TABLE CLOBTBL2 (ID INT NOT NULL PRIMARY KEY,"
-               + "POS BIGINT, CONTENT CLOB("+_100MB+"), DLEN BIGINT)");
-
-       insertBlob2 = conn
-               .prepareStatement("INSERT INTO BLOBTBL2 values (?,?,?,?)");
-       selectBlob2 = conn
-               .prepareStatement("SELECT CONTENT,DLEN FROM BLOBTBL2 WHERE ID = ?");
-
-       insertClob2 = conn
-               .prepareStatement("INSERT INTO CLOBTBL2 values (?,?,?,?)");
-
-       selectClob2 = conn
-               .prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL2 WHERE ID = ?");
-       System.out.println("-----------------------------------");
-       System.out.println(" END setup");
-
-       deleteBlob2 = conn.prepareStatement("DELETE FROM BLOBTBL2");
-       deleteClob2 = conn.prepareStatement("DELETE  from CLOBTBL2");
-       System.out.println("-----------------------------------");
-       System.out.println(" END setup");
-
-   }
-
-   /**
-    * Create an instance of this class and do the test.
-    */
-   public static void main(String[] args) {
-       //trace = Boolean.getBoolean("trace");
-       new LobLimits().runTests(args);
-
-   }
-
-   /**
-    * Create a JDBC connection using the arguments passed in from the harness,
-    * and then run the LOB tests.
-    * 
-    * @param args
-    *            Arguments from the harness.
-    */
-   public void runTests(String[] args) {
-       Connection conn = null;
-       try {
+               + "POS BIGINT, CONTENT CLOB("+BIG_LOB_SZ+"), DLEN BIGINT)"); 
 
-           // use the ij utility to read the property file and
-           // make the initial connection.
-           ij.getPropertyArg(args);
-           conn = ij.startJBMS();
-
-           // do the initial setup,drop and create tables
-           // prepare stmts
-           setup(conn);
-
-           conn.setAutoCommit(false);
-
-           clobTests(conn);
-           blobTests(conn);
-           //cleanup
-           cleanup(conn);
-       } catch (Exception e) {
-           System.out.println("FAIL -- Unexpected exception:");
-           e.printStackTrace(System.out);
-       }
    }
 
-   /**
-    * Close all prepared statements and connection
-    * @param conn
-    * @throws Exception
-    */
-   private void cleanup(Connection conn) throws Exception {
-       insertBlob.close();
-       selectBlob.close();
-       selectClob.close();
-       insertClob.close();
-       deleteClob.close();
-       deleteBlob.close();
-       insertBlob2.close();
-       selectBlob2.close();
-       selectClob2.close();
-       insertClob2.close();
-       deleteBlob2.close();
-       deleteClob2.close();
-       conn.close();
-       new File(DATAFILE).delete();
-       new File(CHARDATAFILE).delete();
+   public static Test suite() {
+       // Right now run just with embeddded.
+       Test suite = new CleanDatabaseTestSetup(
+               new TestSuite(LobLimitsTest.class)) {
+                   protected void decorateSQL(Statement s)
+                           throws SQLException {
+                       setupTables(s,_2GB, _100MB);
+                   }
+               };
+               
+       return new SupportFilesSetup(suite);
    }
 
    /**
@@ -212,9 +140,21 @@ public class LobLimits {
     * @param conn
     * @throws Exception
     */
-   private static void blobTests(Connection conn) throws Exception {
-
-       try {
+   public void testBlob() throws Exception {
+       Connection conn = getConnection();
+       conn.setAutoCommit(false);
+        PreparedStatement insertBlob =
+                prepareStatement("INSERT INTO BLOBTBL values (?,?,?,?)");
+        PreparedStatement selectBlob =
+                prepareStatement("SELECT CONTENT,DLEN FROM BLOBTBL WHERE ID = ?");
+        PreparedStatement insertBlob2 =
+                prepareStatement("INSERT INTO BLOBTBL2 values (?,?,?,?)");
+        PreparedStatement selectBlob2 =
+                prepareStatement("SELECT CONTENT,DLEN FROM BLOBTBL2 WHERE ID = ?");
+        PreparedStatement deleteBlob2 =
+                prepareStatement("DELETE FROM BLOBTBL2");
+        PreparedStatement deleteBlob =
+                conn.prepareStatement("DELETE FROM BLOBTBL");
            // Test - 2Gb blob ( actually it is 2gb -1)
            // Note with setBinaryStream interface the maximum size for the
            // stream, can be max value for an int.
@@ -222,29 +162,29 @@ public class LobLimits {
            // maximum size of 2gb -1
 
            // first do insert blob of 2g, 2 rows
-           insertBlob_SetBinaryStream("BlobTest #1", conn, insertBlob, _2GB,
-                   0, 2, _2GB);
+           insertBlob_SetBinaryStream("BlobTest #1", conn, insertBlob, BIGGEST_LOB_SZ,
+                   0, 2, BIGGEST_LOB_SZ);
            // do a select to see if the inserts in test above went ok
-           selectBlob("BlobTest #2", conn, selectBlob, _2GB, 0, 1);
-           selectBlob("BlobTest #3", conn, selectBlob, _2GB, 1, 1);
+           selectBlob("BlobTest #2", conn, selectBlob, BIGGEST_LOB_SZ, 0, 1);
+           selectBlob("BlobTest #3", conn, selectBlob, BIGGEST_LOB_SZ, 1, 1);
            
            // now do a select of one of the 2gb rows and update another 2g row 
            // using the setBlob api, updated blob is of length 2gb
            // Fix for Bug entry -DERBY-599[setBlob should not materialize blob
            // into memory]
-           selectUpdateBlob("BlobTest #4",conn,selectBlob,_2GB,0,1,1);
+           selectUpdateBlob("BlobTest #4",conn,selectBlob,BIGGEST_LOB_SZ,0,1,1);
            // select row from blobtbl and then do insert into the blobtbl
            // using setBlob
-           selectInsertBlob("BlobTest #4.1",conn,selectBlob,insertBlob,_2GB,0,3,1);
+           selectInsertBlob("BlobTest #4.1",conn,selectBlob,insertBlob,BIGGEST_LOB_SZ,0,3,1);
                               
            // Test - generate random data, write to a file, use it to insert
            // data into blob and then read back and compare if all is ok
            // currently in fvt ( derbyall), tests check for substrings etc and 
            // for small amounts of data.  This test will test for 100mb of blob data
 
-           FileOutputStream fos = new FileOutputStream(DATAFILE);
-           RandomByteStream r = new RandomByteStream(new java.util.Random(),
-                   _100MB);
+           FileOutputStream fos = PrivilegedFileOpsForTests.getFileOutputStream(new File(DATAFILE));
+           RandomByteStreamT r = new RandomByteStreamT(new java.util.Random(),
+                   BIG_LOB_SZ);
            // write in chunks of 32k buffer
            byte[] buffer = new byte[32 * 1024];
            int count = 0;
@@ -254,31 +194,30 @@ public class LobLimits {
 
            fos.flush();
            fos.close();
-
-           insertBlob2("BlobTest #5.1 ", conn, insertBlob2, _100MB, 0, 1,
-                   _100MB, DATAFILE);
-           selectBlob2("BlobTest #5.2 ", conn, selectBlob2, _100MB, 0, 1,
+           insertBlob2("BlobTest #5.1 ", conn, insertBlob2, BIG_LOB_SZ, 0, 1,
+                   BIG_LOB_SZ, DATAFILE);
+           selectBlob2("BlobTest #5.2 ", conn, selectBlob2, BIG_LOB_SZ, 0, 1,
                    DATAFILE);
            
            
            // update the 2gb row in blobtbl with the 100mb data and compare if the update
            // went ok. 
-           selectUpdateBlob2("BlobTest #6",conn,selectBlob2,selectBlob,_100MB,0,1,1,DATAFILE);
+           selectUpdateBlob2("BlobTest #6",conn,selectBlob2,selectBlob,BIG_LOB_SZ,0,1,1,DATAFILE);
                        
            deleteTable(conn, deleteBlob2, 1);
-           
-       } catch (Exception e) {
-           System.out.println("FAIL -- Unexpected exception:");
-           e.printStackTrace(System.out);
-       }
 
        conn.commit();
        
        deleteTable(conn, deleteBlob, 3);
-
+   }
+   
+   public void testBlobNegative () throws SQLException {
        // Negative Test, use setBlob api to insert a 4GB blob.
-       long _4GB =  4*1024*1024*(1024L);
-       BlobImpl _4GbBlob = new BlobImpl(new RandomByteStream(new java.util.Random(),_4GB),_4GB);
+       Connection conn = getConnection();
+       conn.setAutoCommit(false);
+       PreparedStatement insertBlob = prepareStatement("INSERT INTO BLOBTBL values (?,?,?,?)");
+       
+       BlobImplT _4GbBlob = new BlobImplT(new RandomByteStreamT(new java.util.Random(),_4GB),_4GB);
 
        try
        {
@@ -287,49 +226,69 @@ public class LobLimits {
        }
        catch(SQLException sqle)
        {
-           System.out.println("DERBY DOES NOT SUPPORT INSERT OF 4GB BLOB ");
-           expectedException(sqle);
+           //DERBY DOES NOT SUPPORT INSERT OF 4GB BLOB
+           assertSQLState("22003", sqle);
        }
        // ADD  NEW TESTS HERE
    }
 
    /**
     * tests using clobs
-    * @param conn
     * @throws Exception
     */
-   private static void clobTests(Connection conn) throws Exception {
-       try {
-           // Test - 2Gb blob
-           // Note with setCharacterStream interface the maximum size for the
-           // stream has to be max value for a int which is (2GB -1 )
-           // first do insert clob of 2g, 2 rows
-           insertClob_SetCharacterStream("ClobTest #1", conn, insertClob,
-                   _2GB, 0, 2, _2GB);
-           // do a select to see if the inserts in test above went ok
-           selectClob("ClobTest #2", conn, selectClob, _2GB, 0, 1);
-           selectClob("ClobTest #3", conn, selectClob, _2GB, 0, 1);
-           // do a select and then update a row of 2gb size: uses getClob
-           selectUpdateClob("ClobTest #4",conn,selectClob,_2GB,0,1,1);
+   public void testClob1() throws Exception {
+       Connection conn = getConnection();
+        setAutoCommit(false);
+        PreparedStatement insertClob =
+                prepareStatement("INSERT INTO CLOBTBL values (?,?,?,?)");
+        PreparedStatement selectClob = 
+            prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL WHERE ID = ?");
+
+       // Test - 2Gb blob
+       // Note with setCharacterStream interface the maximum size for the
+       // stream has to be max value for a int which is (2GB -1 )
+       // first do insert clob of 2g, 2 rows
+       insertClob_SetCharacterStream("ClobTest #1", conn, insertClob,
+               BIGGEST_LOB_SZ, 0, 2, BIGGEST_LOB_SZ);
+       // do a select to see if the inserts in test above went ok
+       selectClob("ClobTest #2", conn, selectClob, BIGGEST_LOB_SZ, 0, 1);
+       selectClob("ClobTest #3", conn, selectClob, BIGGEST_LOB_SZ, 0, 1);
+       // do a select and then update a row of 2gb size: uses getClob
+       selectUpdateClob("ClobTest #4",conn,selectClob,BIGGEST_LOB_SZ,0,1,1);
            
+   }
+   
+   /**
+    * @throws Exception
+    */
+   public void testClob2() throws Exception {
+        Connection conn = getConnection();
+        conn.setAutoCommit(false);
+        PreparedStatement selectClob =
+                prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL WHERE ID = ?");
+        PreparedStatement insertClob2 =
+                prepareStatement("INSERT INTO CLOBTBL2 values (?,?,?,?)");
+        PreparedStatement selectClob2 =
+                prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL2 WHERE ID = ?");
 
+       setAutoCommit(false);
            // Test - generate random data, write to a file, use it to insert
            // data into clob and then read back and compare if all is ok
            // currently in fvt ( derbyall), tests check for substrings etc and 
            // for small amounts of data.  This test will test for 100mb of clob data
-           writeToFile(CHARDATAFILE,new RandomCharReader(new java.util.Random(),_100MB));
-           insertClob2("ClobTest #5.1 ", conn, insertClob2, _100MB, 0, 1,
-                   _100MB, CHARDATAFILE);
-           selectClob2("ClobTest #5.2 ", conn, selectClob2, _100MB, 0, 1,
+           writeToFile(CHARDATAFILE,new RandomCharReaderT(new java.util.Random(),BIG_LOB_SZ));
+           insertClob2("ClobTest #5.1 ", conn, insertClob2, BIG_LOB_SZ, 0, 1,
+                   BIG_LOB_SZ, CHARDATAFILE);
+           selectClob2("ClobTest #5.2 ", conn, selectClob2, BIG_LOB_SZ, 0, 1,
                    CHARDATAFILE);
 
            // Disabled for now, this will materialize, will open 
            // jira for it.
-           //updateClob2("ClobTest #8.1",conn,selectClob,_100MB,0,0,10,1,CHARDATAFILE);
+           //updateClob2("ClobTest #8.1",conn,selectClob,BIG_LOB_SZ,0,0,10,1,CHARDATAFILE);
 
            // update the 2gb row in clobtbl with the 100mb data and compare if the update
            // went ok.
-           selectUpdateClob2("ClobTest #8.2",conn,selectClob2,selectClob,_100MB,0,1,1,CHARDATAFILE);
+           selectUpdateClob2("ClobTest #8.2",conn,selectClob2,selectClob,BIG_LOB_SZ,0,1,1,CHARDATAFILE);
 
            // test for trailing space truncation
            // insert 100mb+33k of data which has 33k of trailing space,
@@ -338,30 +297,47 @@ public class LobLimits {
            
            // Generate random data and write to a file, this file will be used
            // in the verification process after inserts and updates.
-           writeToFile(CHARDATAFILE,new RandomCharReader(new java.util.Random(),
-                   (NUM_TRAILING_SPACES +_100MB),NUM_TRAILING_SPACES));
-           insertClob2("ClobTest #6.1 ", conn, insertClob2,_100MB, 3, 1,
-                   (NUM_TRAILING_SPACES +_100MB), CHARDATAFILE);
+           writeToFile(CHARDATAFILE,new RandomCharReaderT(new java.util.Random(),
+                   (NUM_TRAILING_SPACES +BIG_LOB_SZ),NUM_TRAILING_SPACES));
+           insertClob2("ClobTest #6.1 ", conn, insertClob2,BIG_LOB_SZ, 3, 1,
+                   (NUM_TRAILING_SPACES +BIG_LOB_SZ), CHARDATAFILE);
            // select will retrieve data and verify the data inserted. 
-           selectClob2("ClobTest #6.2 ", conn, selectClob2, _100MB, 3, 1,
+           selectClob2("ClobTest #6.2 ", conn, selectClob2, BIG_LOB_SZ, 3, 1,
                    CHARDATAFILE);
 
-           negativeSpaceTruncationTest("ClobTest #7",conn);
-           
-           // Test - for stream contains a trailing non-space character
-           // insert should throw an error
-           writeToFile(CHARDATAFILE,new RandomCharReader(new java.util.Random(),MORE_DATA_THAN_COL_WIDTH));
-           try
-           {
+
+       }
+   
+   public void testClobNegative() throws Exception {
+       Connection conn = getConnection();
+       conn.setAutoCommit(false);
+        PreparedStatement insertClob =
+                prepareStatement("INSERT INTO CLOBTBL values (?,?,?,?)");
+        PreparedStatement selectClob =
+                prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL WHERE ID = ?");
+        PreparedStatement insertClob2 =
+                prepareStatement("INSERT INTO CLOBTBL2 values (?,?,?,?)");
+        PreparedStatement selectClob2 =
+                prepareStatement("SELECT CONTENT,DLEN FROM CLOBTBL2 WHERE ID = ?");
+        PreparedStatement deleteClob2 =
+                prepareStatement("DELETE  from CLOBTBL2");
+        PreparedStatement deleteClob = prepareStatement("DELETE  from CLOBTBL");
+
+       negativeSpaceTruncationTest("ClobTest #7",conn);
+       
+       // Test - for stream contains a trailing non-space character
+       // insert should throw an error
+       writeToFile(CHARDATAFILE,new RandomCharReaderT(new java.util.Random(),MORE_DATA_THAN_COL_WIDTH));
+              
+           try {
                insertClob2("ClobTest #9.1 ", conn, insertClob2,MORE_DATA_THAN_COL_WIDTH, 4, 1,
                        MORE_DATA_THAN_COL_WIDTH, CHARDATAFILE);
            }catch(SQLException sqle)
            {
-               System.out.println("NEGATIVE TEST - Expected Exception: truncation of non-blanks not allowed");
-               expectedException(sqle);
+               assertSQLState("XSDA4",sqle);               
            }
            // no row must be retrieved.
-           selectClob2("ClobTest #9.2 ", conn, selectClob2, _100MB, 4, 0,
+           selectClob2("ClobTest #9.2 ", conn, selectClob2, BIG_LOB_SZ, 4, 0,
                    CHARDATAFILE);
 
            try
@@ -370,9 +346,9 @@ public class LobLimits {
                        MORE_DATA_THAN_COL_WIDTH +1 , CHARDATAFILE);
            }catch(SQLException sqle)
            {
-               System.out.println("NEGATIVE TEST - Expected Exception: truncation of non-blanks not allowed and"+
-                       " stream length is one greater than actual length of the stream ");
-               expectedException(sqle);
+               //NEGATIVE TEST - Expected Exception: truncation of non-blanks not allowed and
+               //stream length is one greater than actual length of the stream 
+               assertSQLState("XSDA4",sqle);
            }
 
            try
@@ -381,34 +357,29 @@ public class LobLimits {
                        MORE_DATA_THAN_COL_WIDTH -1 , CHARDATAFILE);
            }catch(SQLException sqle)
            {
-               System.out.println("NEGATIVE TEST - Expected Exception: truncation of non-blanks not allowed and"+
-                       " stream length is one less than actual length of the stream ");
-               expectedException(sqle);
+               //NEGATIVE TEST - Expected Exception: truncation of non-blanks not allowed and
+               //stream length is one less than actual length of the stream
+               assertSQLState("XSDA4", sqle);
            }
            deleteTable(conn, deleteClob2, 2);
-       } catch (Exception e) {
-           System.out.println("FAIL -- Unexpected exception:");
-           e.printStackTrace(System.out);
-       }
 
        try {
            // give -ve streamlength
            insertClob_SetCharacterStream("ClobTest #12.1", conn, insertClob,
-                   _100MB, 4, 1, -1);
+                   BIG_LOB_SZ, 4, 1, -1);
        } catch (SQLException sqle) {
-           System.out.println("NEGATIVE TEST - Expected Exception:");
-           expectedException(sqle);
+           assertSQLState("XJ025", sqle);
        }
 
-       selectClob("ClobTest #12.2", conn, selectClob,_100MB, 4, 0);
+       selectClob("ClobTest #12.2", conn, selectClob,BIG_LOB_SZ, 4, 0);
 
        deleteTable(conn, deleteClob, 2);
        
        // Negative tests use the setClob API to insert a 4GB clob
 
-       long _4GB =  4*1024*1024*(1024L);
+       //long _4GB =  4*1024*1024*(1024L);
 
-       ClobImpl _4GBClob = new ClobImpl(new RandomCharReader(new java.util.Random(),_4GB),_4GB);		
+       ClobImplT _4GBClob = new ClobImplT(new RandomCharReaderT(new java.util.Random(),_4GB),_4GB);		
 
        try
        {
@@ -417,8 +388,8 @@ public class LobLimits {
        }
        catch(SQLException sqle)
        {
-           System.out.println("DERBY DOES NOT SUPPORT INSERT OF 4GB CLOB ");
-           expectedException(sqle);
+           //DERBY DOES NOT SUPPORT INSERT OF 4GB CLOB 
+           assertSQLState("22003",sqle);
        }
 
        // ADD NEW TESTS HERE
@@ -427,28 +398,31 @@ public class LobLimits {
    private static void negativeSpaceTruncationTest(String msg,Connection conn)
        throws Exception
    {
+       PreparedStatement insertClob2 = conn
+       .prepareStatement("INSERT INTO CLOBTBL2 values (?,?,?,?)");
+
        // Negative test, stream has trailing spaces but the stream length is one 
        // more than the actual length of the stream
        try
        {
-           insertClob2(msg, conn, insertClob2,_100MB, 4, 1,
-               (NUM_TRAILING_SPACES +_100MB - 1), CHARDATAFILE);
+           insertClob2(msg, conn, insertClob2,BIG_LOB_SZ, 4, 1,
+               (NUM_TRAILING_SPACES +BIG_LOB_SZ - 1), CHARDATAFILE);
        }catch(SQLException sqle)
        {
-           System.out.println("EXPECTED EXCEPTION - stream has trailing spaces,but stream "+
-                   " length is 1 less than actual length of stream");
-           expectedException(sqle);
+           //EXPECTED EXCEPTION - stream has trailing spaces,but stream 
+           //length is 1 less than actual length of stream
+           assertSQLState("XSDA4",sqle);
        }
 
        try
        {
-           insertClob2(msg, conn, insertClob2,_100MB, 5, 1,
-               (NUM_TRAILING_SPACES +_100MB + 1), CHARDATAFILE);
+           insertClob2(msg, conn, insertClob2,BIG_LOB_SZ, 5, 1,
+               (NUM_TRAILING_SPACES +BIG_LOB_SZ + 1), CHARDATAFILE);
        }catch(SQLException sqle)
        {
-           System.out.println("EXPECTED EXCEPTION - stream has trailing spaces,but stream "+
-                   " length is 1 greater than actual length of stream");
-           expectedException(sqle);
+           //EXPECTED EXCEPTION - stream has trailing spaces,but stream 
+           // length is 1 greater than actual length of stream
+           assertSQLState("XSDA4", sqle);
        }
    }
    
@@ -463,12 +437,11 @@ public class LobLimits {
    private static void insertBlob_SetBinaryStream(String testId,
            Connection conn, PreparedStatement ps, int bloblen, int start,
            int rows, int streamLength) throws SQLException {
-       System.out.println("========================================");
-       System.out.println("START " + testId + "insertBlob of size = "
+       println("========================================");
+       println("START " + testId + "insertBlob of size = "
                + bloblen);
        long ST = 0;
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        int count = 0;
        java.util.Random random = new java.util.Random();
@@ -476,19 +449,16 @@ public class LobLimits {
            ps.setInt(1, i);
            ps.setInt(2, 0);
            ps.setLong(3, bloblen);
-           ps.setBinaryStream(4, new RandomByteStream(random, bloblen),
+           ps.setBinaryStream(4, new RandomByteStreamT(random, bloblen),
                    streamLength);
            count += ps.executeUpdate();
        }
        conn.commit();
-       if (trace) {
-           System.out.println("Insert Blob (" + bloblen + ")" + " rows= "
+       println("Insert Blob (" + bloblen + ")" + " rows= "
                    + count + " = " + (long) (System.currentTimeMillis() - ST));
-
-       }
        verifyTest(count, rows, " Rows inserted with blob of size (" + bloblen
                + ") =");
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -508,16 +478,11 @@ public class LobLimits {
     private static void insertBlob_SetBlob(String testId, Connection conn,
             PreparedStatement ps, java.sql.Blob blob, long bloblen, int start,
             int rows, int expectedRows) throws SQLException {
-        System.out.println("========================================");
-        System.out.println("START " + testId + "insertBlob of size = "
+        println("========================================");
+        println("START " + testId + "insertBlob of size = "
                 + bloblen);
-        long ST = 0;
-        if (trace)
-            ST = System.currentTimeMillis();
+        long ST = System.currentTimeMillis();
         int count = 0;
-
-        try {
-            
             for (int i = start; i < start + rows; i++) {
                 ps.setInt(1, i);
                 ps.setInt(2, 0);
@@ -526,22 +491,13 @@ public class LobLimits {
                 count += ps.executeUpdate();
             }
             conn.commit();
-            if (trace) {
-                System.out.println("Insert Blob (" + bloblen + ")" + " rows= "
+            println("Insert Blob (" + bloblen + ")" + " rows= "
                         + count + " = "
                         + (long) (System.currentTimeMillis() - ST));
 
-            }
-        } catch (SQLException e) {
-            verifyTest(count, expectedRows,
-                    " Rows inserted with blob of size (" + bloblen + ") =");
-            System.out.println("========================================");
-            throw e;
-        }
-
         verifyTest(count, expectedRows,
                 " Rows inserted with blob of size (" + bloblen + ") =");
-        System.out.println("========================================");
+        println("========================================");
 
     }
 
@@ -555,15 +511,13 @@ public class LobLimits {
    private static void selectBlob(String testId, Connection conn,
            PreparedStatement ps, int bloblen, int id, int expectedRows)
            throws SQLException {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - SELECT BLOB of size = "
+       println("========================================");
+       println("START " + testId + " - SELECT BLOB of size = "
                + bloblen);
 
        long ST = 0;
        ResultSet rs = null;
-
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        int count = 0;
        ps.setInt(1, id);
@@ -574,23 +528,18 @@ public class LobLimits {
            Blob value = rs.getBlob(1);
            long l = value.length();
            long dlen = rs.getLong(2);
-           if (dlen != l) {
-               System.out.println("FAIL - MISMATCH LENGTHS GOT " + l
+           assertEquals("FAIL - MISMATCH LENGTHS GOT " + l
                        + " expected " + dlen + " for row in BLOBTBL with ID="
-                       + id);
-           }
+                       + id, dlen, l);
        }
        conn.commit();
 
        verifyTest(count, expectedRows,
                "Matched rows selected with blob of size(" + bloblen + ") =");
-
-       if (trace) {
-           System.out.println("Select Blob (" + bloblen + ")" + " rows= "
+       println("Select Blob (" + bloblen + ")" + " rows= "
                    + expectedRows + " = "
                    + (long) (System.currentTimeMillis() - ST));
-       }
-       System.out.println("========================================");
+       println("========================================");
    }
 
    /**
@@ -605,19 +554,19 @@ public class LobLimits {
    private static void insertBlob2(String testId, Connection conn,
            PreparedStatement ps, int bloblen, int start, int rows,
            int streamLength, String file) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + "insert Blob of size = "
+       println("========================================");
+       println("START " + testId + "insert Blob of size = "
                + bloblen);
        int count = 0;
        java.util.Random random = new java.util.Random();
        FileInputStream fis = null;
 
        long ST = 0;
-       if (trace)
-           ST = System.currentTimeMillis();
+       
+       ST = System.currentTimeMillis();
 
        for (int i = start; i < start + rows; i++) {
-           fis = new FileInputStream(file);
+           fis = PrivilegedFileOpsForTests.getFileInputStream(new File(file));
            ps.setInt(1, i);
            ps.setInt(2, 0);
            ps.setLong(4, bloblen);
@@ -626,14 +575,11 @@ public class LobLimits {
            fis.close();
        }
        conn.commit();
-       if (trace) {
-           System.out.println("Insert Blob (" + bloblen + ")" + " rows= "
+       println("Insert Blob (" + bloblen + ")" + " rows= "
                    + count + " = " + (long) (System.currentTimeMillis() - ST));
-
-       }
        verifyTest(count, rows, " Rows inserted with blob of size (" + bloblen
                + ") =");
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -648,15 +594,13 @@ public class LobLimits {
    private static void selectBlob2(String testId, Connection conn,
            PreparedStatement ps, int bloblen, int id, int expectedRows,
            String file) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - SELECT BLOB of size = "
+       println("========================================");
+       println("START " + testId + " - SELECT BLOB of size = "
                + bloblen);
 
        long ST = 0;
        ResultSet rs = null;
-
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        int count = 0;
        ps.setInt(1, id);
@@ -667,24 +611,22 @@ public class LobLimits {
            Blob value = rs.getBlob(1);
            long l = value.length();
            long dlen = rs.getLong(2);
-           if (dlen != l) {
-               System.out.println("FAIL - MISMATCH LENGTHS GOT " + l
+           assertEquals("FAIL - MISMATCH LENGTHS GOT " + l
                        + " expected " + dlen + " for row in BLOBTBL with ID="
-                       + id);
-           } else
-               compareBlobToFile(value.getBinaryStream(), file);
+                       + id, dlen, l);
+           
+           compareBlobToFile(value.getBinaryStream(), file);
        }
        conn.commit();
 
        verifyTest(count, expectedRows,
                "Matched rows selected with blob of size(" + bloblen + ") =");
 
-       if (trace) {
-           System.out.println("Select Blob (" + bloblen + ")" + " rows= "
+   
+           println("Select Blob (" + bloblen + ")" + " rows= "
                    + expectedRows + " = "
                    + (long) (System.currentTimeMillis() - ST));
-       }
-       System.out.println("========================================");
+           println("========================================");
    }
 
    /**
@@ -700,8 +642,8 @@ public class LobLimits {
    private static void selectUpdateBlob(String testId, Connection conn,
            PreparedStatement ps, int bloblen, int id, int updateId,
            int expectedRows) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - select and then update blob of size= "
+       println("========================================");
+       println("START " + testId + " - select and then update blob of size= "
                + bloblen + " - Uses getBlob api");
 
        ResultSet rs = null;
@@ -712,19 +654,17 @@ public class LobLimits {
        Blob value = rs.getBlob(1);
        long l = value.length();
        long dlen = rs.getLong(2);
-       if (dlen != l) {
-           System.out
-                   .println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
-                           + dlen + " for row in BLOBTBL with ID=" + id);
-       }
-
+       assertEquals("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+                           + dlen + " for row in BLOBTBL with ID=" + id,
+                           dlen, l);
+       
        PreparedStatement psUpd = conn
                .prepareStatement("update BLOBTBL set content=?,dlen =? where id = ?");
        psUpd.setBlob(1,value);
        psUpd.setLong(2, l);
        psUpd.setInt(3, updateId);
 
-       System.out.println("Rows Updated = " + psUpd.executeUpdate());
+       println("Rows Updated = " + psUpd.executeUpdate());
        conn.commit();
 
        // now select and verify that update went through ok.
@@ -732,17 +672,16 @@ public class LobLimits {
        ResultSet rs2 = ps.executeQuery();
        rs2.next();
        Blob updatedValue = rs2.getBlob(1);
-
-       if(updatedValue.length() != l)
-           System.out.println("FAIL - Retrieving the updated blob length does not match "+
-                   "expected length = "+l +" found = "+ updatedValue.length());
-
+       assertEquals("FAIL - Retrieving the updated blob length does not match "+
+                   "expected length = "+l +" found = "+ updatedValue.length(),
+                   l, updatedValue.length());
+       
        // close resultsets
        conn.commit();
        rs.close();
        rs2.close();
        psUpd.close();
-       System.out.println("========================================");
+       println("========================================");
    }
 
    /**
@@ -758,8 +697,8 @@ public class LobLimits {
    private static void selectInsertBlob(String testId, Connection conn,
            PreparedStatement ps,PreparedStatement ins, int bloblen, int id, int insertId,
            int expectedRows) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - select and then insert blob of size= "
+       println("========================================");
+       println("START " + testId + " - select and then insert blob of size= "
                + bloblen + " - Uses getBlob api to do select and setBlob for insert");
 
        ResultSet rs = null;
@@ -770,18 +709,16 @@ public class LobLimits {
        Blob value = rs.getBlob(1);
        long l = value.length();
        long dlen = rs.getLong(2);
-       if (dlen != l) {
-           System.out
-                   .println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
-                           + dlen + " for row in BLOBTBL with ID=" + id);
-       }
-       
+       assertEquals("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+                           + dlen + " for row in BLOBTBL with ID=" + id,
+                           dlen,l);
        ins.setInt(1,insertId);
        ins.setInt(2,0);
        ins.setLong(3,l);
        ins.setBlob(4,value);
        
-       System.out.println("Rows Updated = " + ins.executeUpdate());
+       // assert one row updated
+       assertEquals(1,ins.executeUpdate());
        conn.commit();
 
        // now select and verify that update went through ok.
@@ -789,16 +726,14 @@ public class LobLimits {
        ResultSet rs2 = ps.executeQuery();
        rs2.next();
        Blob insertedValue = rs2.getBlob(1);
-
-       if(insertedValue.length() != l)
-           System.out.println("FAIL - Retrieving the updated blob length does not match "+
-                   "expected length = "+l +" found = "+ insertedValue.length());
-
+       assertEquals("FAIL - Retrieving the updated blob length does not match "+
+               "expected length = "+l +" found = "+ insertedValue.length(),
+               l, insertedValue.length());
        // close resultsets
        conn.commit();
        rs.close();
        rs2.close();
-       System.out.println("========================================");
+       println("========================================");
    }
 
 
@@ -816,8 +751,8 @@ public class LobLimits {
    private static void selectUpdateBlob2(String testId, Connection conn,
            PreparedStatement ps,PreparedStatement sel,int bloblen, int id, int updateId,
            int expectedRows,String file) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - select and then update blob of size= "
+       println("========================================");
+       println("START " + testId + " - select and then update blob of size= "
                + bloblen + " - Uses getBlob and setBlob  api");
 
        ResultSet rs = null;
@@ -829,19 +764,16 @@ public class LobLimits {
        Blob value = rs.getBlob(1);
        long l = value.length();
        long dlen = rs.getLong(2);
-       if (dlen != l) {
-           System.out
-                   .println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
-                           + dlen + " for row in BLOBTBL2 with ID=" + id);
-       }
-
+       assertEquals("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+               + dlen + " for row in BLOBTBL2 with ID=" + id, dlen, l);
+       
        PreparedStatement psUpd = conn
                .prepareStatement("update BLOBTBL set content=?,dlen =? where id = ?");
        psUpd.setBlob(1,value);
        psUpd.setLong(2, l);
        psUpd.setInt(3, updateId);
-
-       System.out.println("Rows Updated = " + psUpd.executeUpdate());
+       // assert 1 row updated
+       assertEquals(1, psUpd.executeUpdate());
        conn.commit();
 
        // now select and verify that update went through ok.
@@ -849,38 +781,29 @@ public class LobLimits {
        ResultSet rs2 = sel.executeQuery();
        rs2.next();
        Blob updatedValue = rs2.getBlob(1);
-       
-       if (updatedValue.length() != l)
-       {
-           System.out.println("FAIL - MISMATCH length of updated blob value : expected="+
-                   l+" found ="+updatedValue.length());
-       }
-       else
-           compareBlobToFile(updatedValue.getBinaryStream(),file);
+       assertEquals("FAIL - MISMATCH length of updated blob value : expected="+
+               l+" found ="+updatedValue.length(), l, updatedValue.length());
+       compareBlobToFile(updatedValue.getBinaryStream(),file);
 
        // close resultsets
        conn.commit();
        rs.close();
        rs2.close();
        psUpd.close();
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
    private static void compareBlobToFile(InputStream lobstream, String filename)
            throws Exception {
-       FileInputStream file = new FileInputStream(filename);
+       FileInputStream file = PrivilegedFileOpsForTests.getFileInputStream(new File(filename));
        int l = 0;
        int b = 0;
        do {
            l = lobstream.read();
            b = file.read();
-           if (l != b)
-           {
-               System.out.println("FAIL -- MISMATCH in data stored versus"+
-                       "data retrieved");
-               break;
-           }
+           assertEquals("FAIL -- MISMATCH in data stored (" + l + ") versus"+
+                   "data retrieved from file(" + b +"). ", b,l);
        } while (l != -1 && b != -1);
    }
 
@@ -902,33 +825,29 @@ public class LobLimits {
    private static void insertClob_SetCharacterStream(String testId,
            Connection conn, PreparedStatement ps, int cloblen, int start,
            int rows, int streamLength) throws SQLException {
-       System.out.println("========================================");
-       System.out.println("START " + testId + "  -insertClob of size = "
+       println("========================================");
+       println("START " + testId + "  -insertClob of size = "
                + cloblen);
 
        long ST = 0;
        java.util.Random random = new java.util.Random();
        int count = 0;
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        for (int i = start; i < start + rows; i++) {
            ps.setInt(1, i);
            ps.setInt(2, 0);
            ps.setLong(3, cloblen);
-           ps.setCharacterStream(4, new RandomCharReader(random, cloblen),
+           ps.setCharacterStream(4, new RandomCharReaderT(random, cloblen),
                    streamLength);
            count += ps.executeUpdate();
        }
        conn.commit();
-       if (trace) {
-           System.out.println("Insert Clob (" + cloblen + ")" + " rows= "
+       println("Insert Clob (" + cloblen + ")" + " rows= "
                    + count + " = " + (long) (System.currentTimeMillis() - ST));
-
-       }
        verifyTest(count, rows, "Rows inserted with clob of size (" + cloblen
                + ") = ");
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -948,40 +867,26 @@ public class LobLimits {
     private static void insertClob_SetClob(String testId, Connection conn,
             PreparedStatement ps, java.sql.Clob clob, long cloblen, int start,
             int rows, int expectedRows) throws SQLException {
-        System.out.println("========================================");
-        System.out.println("START " + testId + "insertClob of size = "
-                + cloblen);
+        println("========================================");
+        println("START " + testId + "insertClob of size = " + cloblen);
         long ST = 0;
-        if (trace)
-           ST = System.currentTimeMillis();
+        ST = System.currentTimeMillis();
         int count = 0;
 
-        try {
-            
-            for (int i = start; i < start + rows; i++) {
-                ps.setInt(1, i);
-                ps.setInt(2, 0);
-                ps.setLong(3, cloblen);
-                ps.setClob(4, clob);
-                count += ps.executeUpdate();
-            }
-            conn.commit();
-            if (trace) {
-                System.out.println("Insert Clob (" + cloblen + ")" + " rows= "
-                        + count + " = "
-                        + (long) (System.currentTimeMillis() - ST));
-
-            }
-        } catch (SQLException e) {
-            verifyTest(count, expectedRows,
-                    " Rows inserted with clob of size (" + cloblen + ") =");
-            System.out.println("========================================");
-            throw e;
+        for (int i = start; i < start + rows; i++) {
+            ps.setInt(1, i);
+            ps.setInt(2, 0);
+            ps.setLong(3, cloblen);
+            ps.setClob(4, clob);
+            count += ps.executeUpdate();
         }
-
-        verifyTest(count, expectedRows,
-                " Rows inserted with clob of size (" + cloblen + ") =");
-        System.out.println("========================================");
+        conn.commit();
+        println("Insert Clob (" + cloblen + ")" + " rows= " + count + " = "
+                + (long) (System.currentTimeMillis() - ST));
+
+        verifyTest(count, expectedRows, " Rows inserted with clob of size ("
+                + cloblen + ") =");
+        println("========================================");
 
     }
 
@@ -994,15 +899,14 @@ public class LobLimits {
    private static void selectClob(String testId, Connection conn,
            PreparedStatement ps, int cloblen, int id, int expectedRows)
            throws SQLException {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - SELECT CLOB of size = "
+       println("========================================");
+       println("START " + testId + " - SELECT CLOB of size = "
                + cloblen);
 
        long ST = 0;
        int count = 0;
        ResultSet rs = null;
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        ps.setInt(1, id);
        rs = ps.executeQuery();
@@ -1011,24 +915,20 @@ public class LobLimits {
            Clob value = rs.getClob(1);
            long l = value.length();
            long dlen = rs.getLong(2);
-           if (dlen != l) {
-               System.out.println("FAIL - MISMATCH LENGTHS GOT " + l
-                       + " expected " + dlen + " for row in CLOBTBL with ID="
-                       + id);
+           assertEquals("FAIL - MISMATCH LENGTHS GOT " + l
+                   + " expected " + dlen + " for row in CLOBTBL with ID="
+                   + id, l, dlen);
            }
-
-       }
        conn.commit();
-       if (trace) {
-           System.out.println("Select Clob (" + cloblen + ")" + " rows= "
-                   + expectedRows + " = "
-                   + (long) (System.currentTimeMillis() - ST));
+       
+       println("Select Clob (" + cloblen + ")" + " rows= "
+               + expectedRows + " = "
+               + (long) (System.currentTimeMillis() - ST));
 
-       }
 
        verifyTest(count, expectedRows,
                "Matched rows selected with clob of size(" + cloblen + ") =");
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -1043,33 +943,35 @@ public class LobLimits {
    private static void insertClob2(String testId, Connection conn,
            PreparedStatement ps, int cloblen, int start, int rows,
            int streamLength, String file) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + "insert Clob of size = "
+       println("========================================");
+       println("START " + testId + "insert Clob of size = "
                + cloblen);
        int count = 0;
        FileReader reader = null;
        long ST = 0;
-       if (trace)
-           ST = System.currentTimeMillis();
-
-       for (int i = start; i < start + rows; i++) {
-           reader = new FileReader(file);
-           ps.setInt(1, i);
-           ps.setInt(2, 0);
-           ps.setLong(4, cloblen);
-           ps.setCharacterStream(3, reader, streamLength);
-           count += ps.executeUpdate();
-           reader.close();
-       }
+       ST = System.currentTimeMillis();
+        try {
+            for (int i = start; i < start + rows; i++) {
+                reader = PrivilegedFileOpsForTests
+                        .getFileReader(new File(file));
+                println("Got reader for file " + file + " " + reader);
+                ps.setInt(1, i);
+                ps.setInt(2, 0);
+                ps.setLong(4, cloblen);
+                ps.setCharacterStream(3, reader, streamLength);
+                count += ps.executeUpdate();
+            }
+        } finally {
+            reader.close();
+            println("Closed reader for file " + file + " " + reader);
+        }
        conn.commit();
-       if (trace) {
-           System.out.println("Insert Clob (" + cloblen + ")" + " rows= "
+ 
+       println("Insert Clob (" + cloblen + ")" + " rows= "
                    + count + " = " + (long) (System.currentTimeMillis() - ST));
-
-       }
        verifyTest(count, rows, " Rows inserted with clob of size (" + cloblen
                + ") =");
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -1083,15 +985,14 @@ public class LobLimits {
    private static void selectClob2(String testId, Connection conn,
            PreparedStatement ps, int cloblen, int id, int expectedRows,
            String file) throws SQLException, Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - SELECT CLOB of size = "
+       println("========================================");
+       println("START " + testId + " - SELECT CLOB of size = "
                + cloblen);
 
        long ST = 0;
        ResultSet rs = null;
 
-       if (trace)
-           ST = System.currentTimeMillis();
+       ST = System.currentTimeMillis();
 
        int count = 0;
        ps.setInt(1, id);
@@ -1102,24 +1003,21 @@ public class LobLimits {
            Clob value = rs.getClob(1);
            long l = value.length();
            long dlen = rs.getLong(2);
-           if (cloblen != l) {
-               System.out.println("FAIL - MISMATCH LENGTHS GOT " + l
-                       + " expected " + dlen + " for row in CLOBTBL2 with ID="
-                       + id);
-           } else
-               compareClobToFile(value.getCharacterStream(), file, cloblen);
+           assertEquals("FAIL - MISMATCH LENGTHS GOT " + l
+                   + " expected " + dlen + " for row in CLOBTBL2 with ID="
+                   + id, l, cloblen);
+           compareClobToFile(value.getCharacterStream(), file, cloblen);
        }
        conn.commit();
 
        verifyTest(count, expectedRows,
                "Matched rows selected with clob of size(" + cloblen + ") =");
 
-       if (trace) {
-           System.out.println("Select Clob (" + cloblen + ")" + " rows= "
+       
+       println("Select Clob (" + cloblen + ")" + " rows= "
                    + expectedRows + " = "
                    + (long) (System.currentTimeMillis() - ST));
-       }
-       System.out.println("========================================");
+       println("========================================");
    }
 
    /*
@@ -1130,8 +1028,8 @@ public class LobLimits {
    private static void selectUpdateClob(String testId, Connection conn,
            PreparedStatement ps, int cloblen, int id, int updateId,
            int expectedRows) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - select and then update clob of size= "
+       println("========================================");
+       println("START " + testId + " - select and then update clob of size= "
                + cloblen + " - Uses setClob api");
 
        ResultSet rs = null;
@@ -1142,11 +1040,8 @@ public class LobLimits {
        Clob value = rs.getClob(1);
        long l = value.length();
        long dlen = rs.getLong(2);
-       if (dlen != l) {
-           System.out
-                   .println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
-                           + dlen + " for row in CLOBTBL with ID=" + id);
-       }
+       assertEquals("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+               + dlen + " for row in CLOBTBL with ID=" + id, dlen, l);
 
        PreparedStatement psUpd = conn
                .prepareStatement("update CLOBTBL set content=?,dlen =? where id = ?");
@@ -1154,7 +1049,8 @@ public class LobLimits {
        psUpd.setLong(2, l);
        psUpd.setInt(3, updateId);
 
-       System.out.println("Rows Updated = " + psUpd.executeUpdate());
+       assertEquals(1,psUpd.executeUpdate());
+       
        conn.commit();
 
        // now select and verify that update went through ok.
@@ -1162,17 +1058,16 @@ public class LobLimits {
        ResultSet rs2 = ps.executeQuery();
        rs2.next();
        Clob updatedValue = rs2.getClob(1);
-
-       if(updatedValue.length() != l)
-           System.out.println("FAIL - Retrieving the updated clob length does not match "+
-                   "expected length = "+l +" found = "+ updatedValue.length());
+       assertEquals("FAIL - Retrieving the updated clob length does not match "+
+               "expected length = "+l +" found = "+ updatedValue.length(),l, 
+               updatedValue.length());
 
        // close resultsets
        conn.commit();
        rs.close();
        rs2.close();
        psUpd.close();
-       System.out.println("========================================");
+       println("========================================");
    }
 
    
@@ -1184,8 +1079,8 @@ public class LobLimits {
    private static void selectUpdateClob2(String testId, Connection conn,
            PreparedStatement ps, PreparedStatement sel,int cloblen, int id, int updateId,
            int expectedRows,String file) throws Exception {
-       System.out.println("========================================");
-       System.out.println("START " + testId + " - select and then update clob of size= "
+       println("========================================");
+       println("START " + testId + " - select and then update clob of size= "
                + cloblen + " - Uses setClob api");
 
        ResultSet rs = null;
@@ -1197,11 +1092,8 @@ public class LobLimits {
        Clob value = rs.getClob(1);
        long l = value.length();
        long dlen = rs.getLong(2);
-       if (dlen != l) {
-           System.out
-                   .println("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
-                           + dlen + " for row in CLOBTBL2 with ID=" + id);
-       }
+       assertEquals("FAIL - MISMATCH LENGTHS GOT " + l + " expected "
+               + dlen + " for row in CLOBTBL2 with ID=" + id, dlen, l);
 
        PreparedStatement psUpd = conn
                .prepareStatement("update CLOBTBL set content=?,dlen =? where id = ?");
@@ -1209,7 +1101,7 @@ public class LobLimits {
        psUpd.setLong(2, l);
        psUpd.setInt(3, updateId);
 
-       System.out.println("Rows Updated = " + psUpd.executeUpdate());
+       assertEquals(1, psUpd.executeUpdate());
        conn.commit();
 
        // now select and verify that update went through ok.
@@ -1217,21 +1109,16 @@ public class LobLimits {
        ResultSet rs2 = sel.executeQuery();
        rs2.next();
        Clob updatedValue = rs2.getClob(1);
-       
-       if (updatedValue.length() != l)
-       {
-           System.out.println("FAIL - MISMATCH length of updated clob value , found="+
-                   updatedValue.length() +",expected = "+l);
-       }
-       else
-           compareClobToFile(updatedValue.getCharacterStream(),file,(int)l);
+       assertEquals("FAIL - MISMATCH length of updated clob value , found="+
+                   updatedValue.length() +",expected = "+l, l, updatedValue.length());
+       compareClobToFile(updatedValue.getCharacterStream(),file,(int)l);
 
        // close resultsets
        conn.commit();
        rs.close();
        rs2.close();
        psUpd.close();
-       System.out.println("========================================");
+       println("========================================");
 
    }
 
@@ -1308,44 +1195,29 @@ public class LobLimits {
    
    private static void compareClobToFile(Reader lobstream, String filename,int length)
            throws Exception {
-       FileReader file = new FileReader(filename);
+       FileReader file = PrivilegedFileOpsForTests.getFileReader(
+                   new  File(filename));
        int c1 = 0;
        int c2 = 0;
        long count = 0;
        do {
            c1 = lobstream.read();
            c2 = file.read();
-           if (c1 != c2)
-           {
-               System.out.println("FAIL -- MISMATCH in data stored versus data retrieved at " + count);
-               break;
-           }
+           assertEquals("FAIL -- MISMATCH in data stored versus data retrieved at " + 
+                   count + " " + c1 + " does not match " + c2,
+                   c2, c1);
            count++;
            length--;
        } while (c1 != -1 && c2 != -1 && length > 0);
-   }
-
-   private static void expectedException(SQLException sqle) {
-
-       while (sqle != null) {
-           String sqlState = sqle.getSQLState();
-           if (sqlState == null) {
-               sqlState = "<NULL>";
-           }
-           System.out.println("EXPECTED SQL Exception: (" + sqlState + ") "
-                   + sqle.getMessage());
-
-           sqle = sqle.getNextException();
-       }
+       file.close();
    }
 
    private static void verifyTest(int affectedRows, int expectedRows,
            String test) {
-       if (affectedRows != expectedRows)
-           System.out.println("FAIL --" + test + affectedRows
-                   + " , but expected rows =" + expectedRows);
-       else
-           System.out.println(test + affectedRows);
+       assertEquals("FAIL --" + test + affectedRows
+               + " , but expected rows =" + expectedRows, expectedRows,
+               affectedRows);
+       println(test + affectedRows);
    }
    
    private static void writeToFile(String file,Reader r)
@@ -1353,9 +1225,11 @@ public class LobLimits {
    {
        // does file exist, if so delete and write to a fresh file
        File f =new File(file);
-       if (f.exists())
-           f.delete();
-       FileWriter writer = new FileWriter(file);
+       if (PrivilegedFileOpsForTests.exists(f)) {
+           assertTrue(PrivilegedFileOpsForTests.delete(f));
+       }
+       FileWriter writer = PrivilegedFileOpsForTests.getFileWriter(f);
+       println("Got FileWriter for " + file + " " + writer);
        // write in chunks of 32k buffer
        char[] buffer = new char[32 * 1024];
        int count = 0;
@@ -1364,18 +1238,19 @@ public class LobLimits {
            writer.write(buffer,0,count);
        writer.flush();
        writer.close();
+       println("writer " + writer + " for file " + file + " closed");
    }
 }
 
 /**
  * Class to generate random byte data
  */
-class RandomByteStream extends java.io.InputStream {
+class RandomByteStreamT extends java.io.InputStream {
    private long length;
 
    private java.util.Random dpr;
 
-   RandomByteStream(java.util.Random dpr, long length) {
+   RandomByteStreamT(java.util.Random dpr, long length) {
        this.length = length;
        this.dpr = dpr;
 
@@ -1410,19 +1285,19 @@ class RandomByteStream extends java.io.I
 /*
  * Class to generate random char data, generates 1,2,3bytes character.
  */
-class RandomCharReader extends java.io.Reader {
+class RandomCharReaderT extends java.io.Reader {
    private long length;
    private long numTrailingSpaces;
 
    private java.util.Random dpr;
 
-   RandomCharReader(java.util.Random dpr, long length) {
+   RandomCharReaderT(java.util.Random dpr, long length) {
        this.length = length;
        this.dpr = dpr;
        this.numTrailingSpaces = 0;
    }
 
-   RandomCharReader(java.util.Random dpr, long length,long numTrailingSpaces) {
+   RandomCharReaderT(java.util.Random dpr, long length,long numTrailingSpaces) {
        this.length = length;
        this.dpr = dpr;
        this.numTrailingSpaces = numTrailingSpaces;
@@ -1551,11 +1426,11 @@ class RandomCharReader extends java.io.R
  * Derby throws an error if the clob size exceeds 2GB
  **/
 
-class ClobImpl implements java.sql.Clob {
+class ClobImplT implements java.sql.Clob {
   long length;
   Reader myReader;
  
-  public ClobImpl(Reader myReader,long length) {
+  public ClobImplT(Reader myReader,long length) {
       this.length = length;
       this.myReader = myReader;
   }
@@ -1624,12 +1499,12 @@ class ClobImpl implements java.sql.Clob 
  * Derby throws an error if the blob length exceeds the max range of
  * int. 
  */
-class BlobImpl implements java.sql.Blob
+class BlobImplT implements java.sql.Blob
 {
     long length;
     InputStream myStream;
     
-    public BlobImpl(InputStream is, long length)
+    public BlobImplT(InputStream is, long length)
     {
         this.myStream = is;
         this.length = length;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/build.xml?rev=1147219&r1=1147218&r2=1147219&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/largedata/build.xml Fri Jul 15 16:32:31 2011
@@ -16,79 +16,30 @@
   limitations under the License.
 -->
 
-<!-- ==================================================================== -->
-<!--                       Derby build file                          -->
-<!-- ==================================================================== -->
+<project default="largedatatests" basedir="../../../../../../..">
 
-<project default="FTOtestsubdir" basedir="../../../../../../../.." >
-
-<!-- ==================================================================== -->
-<!--                           Set properties                             -->
-<!-- ==================================================================== -->
+<!-- Properties -->
 
   <!-- User settings -->
   <property file="${user.home}/ant.properties"/>
-
   <!-- Set property lib dir -->
-  <property name="properties.dir" value="tools/ant/properties" />
-
+  <property name="properties.dir" value="tools/ant/properties"/>
   <!-- Significant dirs -->
   <property file="${properties.dir}/dirs.properties"/>
   <property file="${properties.dir}/derbytesting.properties"/>
-
+  <property file="${user.home}/properties/derbytesting.properties"/>
+  <property file="${ant.home}/properties/derbytesting.properties"/>
   <!-- Compiler settings -->
-  <property file="${properties.dir}/sane${sanity}.properties"/>
-  <property file="${properties.dir}/defaultcompiler.properties"/>
   <property file="${properties.dir}/${build.compiler}.properties"/>
-
-  <!-- Parser properties -->
-  <!--property file="${properties.dir}/parser.properties"/-->
-
   <!-- Compile-time classpath properties files -->
   <property file="${properties.dir}/extrapath.properties"/>
-  <property file="${properties.dir}/compilepath.properties"/>
-
-  <!-- Release and Version info -->
-  <property file="${properties.dir}/release.properties"/>
-
-  <!-- derby testing specific properties files -->
-  <property file="${ant.home}/properties/derbytesting.properties"/>
-  <property file="${user.home}/properties/derbytesting.properties"/>
-  <property name="this.dir" value="${derby.testing.functest.dir}/tests/largedata"/>
-
-<!--             ============ Begin Targets ==============                -->
- 
-  <target name="FTOtestsubdir" depends="compilet1,compilet2,copyfiles"/>
-
-  <!-- mkdir / init target may not be necessary, just here for reference... -->
-  <target name="init">
-    <mkdir dir="${out.dir}/${derby.testing.functest.dir}/tests/largedata"/>
-  </target>
-
-  <target name="compilet1">
-    <javac
-      source="1.4"
-      target="1.4"
-      bootclasspath="${empty}"
-      nowarn="on"
-      debug="true"
-      depend="${depend}"
-      deprecation="${deprecation}"
-      optimize="${optimize}"
-      proceed="${proceed}"
-      verbose="${verbose}" 
-      srcdir="${derby.testing.src.dir}"
-      destdir="${out.dir}">
-      <classpath>
-        <!--pathelement location="${oro}"/-->
-        <pathelement path="${compile.classpath}"/>
-      </classpath>
-      <include name="${this.dir}/*.java"/>
-      <exclude name="${this.dir}/LobLimits.java"/>
-    </javac>
-  </target>
+  <property file="${properties.dir}/derbytesting.properties"/> 
+  <property file="${properties.dir}/compilepath.properties"/> 
+  
+<!-- Targets -->
 
-  <target name="compilet2">
+  <target name="largedatatests" 
+          description="Build Derby largedata tests">
     <javac
       source="1.4"
       target="1.4"
@@ -104,22 +55,11 @@
       destdir="${out.dir}">
       <classpath>
         <pathelement path="${java14compile.classpath}"/>
+        <pathelement path="${junit}"/>
       </classpath>
-      <include name="${this.dir}/LobLimits.java"/>
+      <include name="${derby.testing.functest.dir}/tests/largedata/*.java"/>
     </javac>
   </target>
-
-  <target name="copyfiles">
-    <copy todir="${out.dir}/${derby.testing.functest.dir}/tests/largedata">
-      <fileset dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/largedata" 
-        includesfile="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/largedata/copyfiles.ant"/>  
-    </copy>
-  </target> 
-
-
-<!--             ============= End Targets ==============                -->
-
-<!--             ============= End Project ==============                -->
-
+  
 </project>
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java?rev=1147219&r1=1147218&r2=1147219&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/PrivilegedFileOpsForTests.java Fri Jul 15 16:32:31 2011
@@ -25,6 +25,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -140,6 +141,27 @@ public class PrivilegedFileOpsForTests {
     }
 
     /**
+     * Delete a file
+     *
+     * @return {@code true} if file was deleted, {@code false} otherwise
+     * @throws SecurityException if the required permissions to read the file,
+     *      or the path it is in, are missing
+     * @see File#delete
+     */
+    public static boolean delete(final File file)
+            throws SecurityException {
+        if (file == null) {
+            throw new IllegalArgumentException("file cannot be <null>");
+        }
+        return ((Boolean)AccessController.doPrivileged(
+                    new PrivilegedAction() {
+                        public Object run() {
+                            return Boolean.valueOf(file.delete());
+                        }
+                    })).booleanValue();
+    }
+
+    /**
      * Obtains a reader for the specified file.
      *
      * @param file the file to obtain a reader for
@@ -166,6 +188,34 @@ public class PrivilegedFileOpsForTests {
         }
     }
 
+    /**
+     * Obtains a writer for the specified file.
+     *
+     * @param file the file to obtain a writer for
+     * @return An writer for the specified file.
+     * @throws IOException 
+     * @throws IOException if the file cannot be opened
+     * @throws SecurityException if the required permissions to write to the file,
+     *      or the path it is in, are missing
+     */
+    public static FileWriter getFileWriter(final File file)
+            throws IOException {
+        if (file == null) {
+            throw new IllegalArgumentException("file cannot be <null>");
+        }
+        try {
+            return (FileWriter)AccessController.doPrivileged(
+                    new PrivilegedExceptionAction() {
+                        public Object run()
+                                throws IOException {
+                            return new FileWriter(file);
+                        }
+                    });
+        } catch (PrivilegedActionException pae) {
+            throw (IOException)pae.getCause();
+        }
+    }
+
     
     /**
      * In a priv block, do a recursive copy from source to target.  
@@ -411,4 +461,6 @@ public class PrivilegedFileOpsForTests {
             }
         });
     }
-}
+    
+
+ }



Mime
View raw message