poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1753487 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
Date Wed, 20 Jul 2016 11:14:05 GMT
Author: nick
Date: Wed Jul 20 11:14:05 2016
New Revision: 1753487

URL: http://svn.apache.org/viewvc?rev=1753487&view=rev
Log:
Start on unit testing for HSSFWorkbook.write(File), bug in POIFS to fix first

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java?rev=1753487&r1=1753486&r2=1753487&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java Wed Jul 20 11:14:05
2016
@@ -89,6 +89,23 @@ public class POIFSFileSystem
 
     /**
      * <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less
memory than
+     *  creating from an <tt>InputStream</tt>.</p>
+     *  
+     * <p>Note that with this constructor, you will need to call {@link #close()}
+     *  when you're done to have the underlying file closed, as the file is
+     *  kept open during normal operation to read the data out.</p> 
+     * @param readOnly whether the POIFileSystem will only be used in read-only mode
+     *  
+     * @param file the File from which to read the data
+     *
+     * @exception IOException on errors reading, or on invalid data
+     */
+    public POIFSFileSystem(File file, boolean readOnly) throws IOException {
+        super(file, readOnly);
+    }
+    
+    /**
+     * <p>Creates a POIFSFileSystem from a <tt>File</tt>. This uses less
memory than
      *  creating from an <tt>InputStream</tt>. The File will be opened read-only</p>
      *  
      * <p>Note that with this constructor, you will need to call {@link #close()}
@@ -141,7 +158,7 @@ public class POIFSFileSystem
         tmp.close();
         
         // Open it up again backed by the file
-        return new POIFSFileSystem(file);
+        return new POIFSFileSystem(file, false);
     }
 
     /**

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=1753487&r1=1753486&r2=1753487&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Wed Jul 20
11:14:05 2016
@@ -71,6 +71,7 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.RecordFormatException;
 import org.apache.poi.util.TempFile;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import junit.framework.AssertionFailedError;
@@ -1277,4 +1278,22 @@ public final class TestHSSFWorkbook exte
         assertEquals(1, wb.getNumberOfSheets());
         assertEquals("Changed!", wb.getSheetAt(0).getRow(0).getCell(0).toString());
     }
+    
+    @Test
+    @Ignore("Not currently working, bug in POIFS creating empty FS")
+    public void testWriteToNewFile() throws Exception {
+        // Open from a Stream
+        HSSFWorkbook wb = new HSSFWorkbook(
+                POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
+
+        // Save to a new temp file
+        final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
+        wb.write(file);
+        wb.close();
+        
+        // Read and check
+        wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
+        assertEquals(3, wb.getNumberOfSheets());
+        wb.close();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message