]> source.dussan.org Git - poi.git/commitdiff
Eclipse warnings, code formatting, javadoc, ...
authorDominik Stadler <centic@apache.org>
Fri, 4 Dec 2015 14:38:14 +0000 (14:38 +0000)
committerDominik Stadler <centic@apache.org>
Fri, 4 Dec 2015 14:38:14 +0000 (14:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717972 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java

index 05029238bf61e1be27f3f1fda002ab9776a11d83..9b86cf7793542b4e15a5d16f942da02ddcf1916b 100644 (file)
@@ -26,11 +26,11 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
 import org.apache.poi.hssf.usermodel.HSSFPatriarch;
-import org.apache.poi.hssf.util.CellReference;
 import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
 
 
@@ -721,7 +721,6 @@ public class AddDimensionedImage {
         String imageFile = null;
         String outputFile = null;
         FileOutputStream fos = null;
-        HSSFWorkbook workbook = null;
         HSSFSheet sheet = null;
         try {
             if(args.length < 2){
@@ -731,13 +730,14 @@ public class AddDimensionedImage {
             imageFile = args[0];
             outputFile = args[1];
 
-            workbook = new HSSFWorkbook();
+            HSSFWorkbook workbook = new HSSFWorkbook();
             sheet = workbook.createSheet("Picture Test");
             new AddDimensionedImage().addImageToSheet("A1", sheet,
                     imageFile, 125, 125,
                     AddDimensionedImage.EXPAND_ROW_AND_COLUMN);
             fos = new FileOutputStream(outputFile);
             workbook.write(fos);
+            workbook.close();
         }
         catch(FileNotFoundException fnfEx) {
             System.out.println("Caught an: " + fnfEx.getClass().getName());
@@ -752,13 +752,6 @@ public class AddDimensionedImage {
             ioEx.printStackTrace(System.out);
         }
         finally {
-            try {
-                if (workbook != null) {
-                    workbook.close();
-                }
-            } catch(IOException ioEx) {
-                // I G N O R E
-            }
             try {
                 if(fos != null) {
                     fos.close();
index cd87fe6238f3390b2eaaa37a79c0b9162bf3f1c4..117300f2c8cc073210f937be59a7181ea9aeaf83 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.After;
@@ -85,12 +86,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
     public void existingWorkbook() throws IOException {
        XSSFWorkbook xssfWb1 = new XSSFWorkbook();
        xssfWb1.createSheet("S1");
-       @SuppressWarnings("resource")
         SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1);
-       XSSFWorkbook xssfWb2 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
+       XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
        assertTrue(wb1.dispose());
 
-        @SuppressWarnings("resource")
         SXSSFWorkbook wb2 = new SXSSFWorkbook(xssfWb2);
        assertEquals(1, wb2.getNumberOfSheets());
        Sheet sheet  = wb2.getSheetAt(0);
@@ -99,11 +98,12 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
            assertTrue(wb2.dispose());
            xssfWb2.close();
            xssfWb1.close();
+           
+           wb2.close();
     }
 
     @Test
     public void useSharedStringsTable() throws Exception {
-        @SuppressWarnings("resource")
         SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true);
 
         SharedStringsTable sss =  POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource");
@@ -116,7 +116,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
         row.createCell(1).setCellValue("B");
         row.createCell(2).setCellValue("A");
 
-        XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+        XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
         sss = POITestCase.getFieldValue(SXSSFWorkbook.class, wb, SharedStringsTable.class, "_sharedStringSource");
         assertEquals(2, sss.getUniqueCount());
         assertTrue(wb.dispose());
@@ -147,9 +147,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
        Row row = sheet.createRow(1);
        Cell cell = row.createCell(1);
        cell.setCellValue("value 2_1_1");
-       @SuppressWarnings("resource")
         SXSSFWorkbook wb1 = new SXSSFWorkbook(xssfWb1);
-       XSSFWorkbook xssfWb2 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
+       XSSFWorkbook xssfWb2 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb1);
         assertTrue(wb1.dispose());
         xssfWb1.close();
 
@@ -172,7 +171,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
        Cell cell3_1_1 = row3_1.createCell(1);
        cell3_1_1.setCellValue("value 3_1_1");
 
-       XSSFWorkbook xssfWb3 = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb2);
+       XSSFWorkbook xssfWb3 = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb2);
        wb2.close();
        
        assertEquals(3, xssfWb3.getNumberOfSheets());
@@ -239,7 +238,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
         //Test escaping of Unicode control characters
         wb = new SXSSFWorkbook();
         wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019");
-        XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+        XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
         Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0);
         assertEquals("value?", cell.getStringCellValue());
 
@@ -250,7 +249,6 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
 
     @Test
     public void gzipSheetdataWriter() throws IOException {
-        @SuppressWarnings("resource")
         SXSSFWorkbook wb = new SXSSFWorkbook();
         wb.setCompressTempFiles(true);
         int rowNum = 1000;
@@ -270,7 +268,7 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
             }
         }
 
-        XSSFWorkbook xwb = (XSSFWorkbook)SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+        XSSFWorkbook xwb = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb);
         for(int i = 0; i < sheetNum; i++){
             Sheet sh = xwb.getSheetAt(i);
             assertEquals("sheet" + i, sh.getSheetName());
@@ -322,7 +320,6 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
         }
     }
 
-    @SuppressWarnings("resource")
     @Test
     public void workbookDispose()
     {
@@ -337,8 +334,8 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
 
     }
 
-    // currently writing the same sheet multiple times is not supported...
-    @Ignore
+    @Ignore("currently writing the same sheet multiple times is not supported...")
+    @Test
     public void bug53515() throws Exception {
         Workbook wb1 = new SXSSFWorkbook(10);
         populateWorkbook(wb1);
@@ -350,10 +347,9 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
         wb1.close();
     }
 
-    // Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files
-    // See http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html
-    @SuppressWarnings("resource")
-    @Ignore
+    @Ignore("Crashes the JVM because of documented JVM behavior with concurrent writing/reading of zip-files, "
+            + "see http://www.oracle.com/technetwork/java/javase/documentation/overview-156328.html")
+    @Test
     public void bug53515a() throws Exception {
         File out = new File("Test.xlsx");
         out.delete();
@@ -412,4 +408,31 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook {
             }
         }
     }
+
+    @Ignore("Just a local test for http://stackoverflow.com/questions/33627329/apache-poi-streaming-api-using-xssf-template")
+    @Test
+    public void testTemplateFile() throws IOException {
+        XSSFWorkbook workBook = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
+        SXSSFWorkbook streamingWorkBook = new SXSSFWorkbook(workBook,10);
+        Sheet sheet = streamingWorkBook.getSheet("Sheet1");
+        for(int rowNum = 10;rowNum < 1000000;rowNum++) {
+            Row row = sheet.createRow(rowNum);
+            for(int cellNum = 0;cellNum < 700;cellNum++) {
+                Cell cell = row.createCell(cellNum);
+                cell.setCellValue("somevalue");
+            }
+            
+            if(rowNum % 100 == 0) {
+                System.out.print(".");
+                if(rowNum % 10000 == 0) {
+                    System.out.println(rowNum);
+                }
+            }
+        }
+
+        streamingWorkBook.write(new FileOutputStream("C:\\temp\\streaming.xlsx"));
+        
+        streamingWorkBook.close();
+        workBook.close();
+    }
 }
index 93cee9b603dd642e6a66bb39f52d9b195069484d..7004ec36d1b808255a9aa4e3c298e6bb8f92160e 100644 (file)
@@ -2130,7 +2130,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
      *  in read-only mode
      * @throws InvalidFormatException 
      */
-    @SuppressWarnings("resource")
     @Test
     public void bug57482() throws IOException, InvalidFormatException {
         for (PackageAccess access : new PackageAccess[] {
index 08dbf9e85da0275faa9940fb79d7b007a2de0efb..d7de7b33740cc7f877cff1c34373ebc3ef86f16e 100644 (file)
@@ -177,8 +177,8 @@ public abstract class PropertyNode<T extends PropertyNode<T>>  implements Compar
     return false;
   }
 
-  public T clone()
-    throws CloneNotSupportedException
+  @SuppressWarnings("unchecked")
+  public T clone() throws CloneNotSupportedException
   {
     return (T) super.clone();
   }
index 50d2370d6a64e045432548165c75b6870dff732b..fefa202009aed8090d321fd9efb73eee1994f0d2 100644 (file)
@@ -60,8 +60,8 @@ public final class TestReWriteSanity extends TestCase {
                // Find the location of the PersistPtrIncrementalBlocks and
                // UserEditAtoms
                Record[] r = wss.getRecords();
-               Hashtable pp = new Hashtable();
-               Hashtable ue = new Hashtable();
+               Map<Integer,Record> pp = new Hashtable<Integer,Record>();
+               Map<Integer,Object> ue = new Hashtable<Integer,Object>();
                ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first
                int pos = 0;
                int lastUEPos = -1;