From 387fb86d68678c345aca10ab03fffc421e77de1e Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Fri, 4 Dec 2015 14:38:14 +0000 Subject: [PATCH] Eclipse warnings, code formatting, javadoc, ... git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1717972 13f79535-47bb-0310-9956-ffa450edef68 --- .../examples/AddDimensionedImage.java | 13 +--- .../poi/xssf/streaming/TestSXSSFWorkbook.java | 59 +++++++++++++------ .../poi/xssf/usermodel/TestXSSFBugs.java | 1 - .../apache/poi/hwpf/model/PropertyNode.java | 4 +- .../apache/poi/hslf/TestReWriteSanity.java | 4 +- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java index 05029238b..9b86cf779 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java @@ -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(); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index cd87fe623..117300f2c 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -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(); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 93cee9b60..7004ec36d 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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[] { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java index 08dbf9e85..d7de7b337 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java @@ -177,8 +177,8 @@ public abstract class PropertyNode> implements Compar return false; } - public T clone() - throws CloneNotSupportedException + @SuppressWarnings("unchecked") + public T clone() throws CloneNotSupportedException { return (T) super.clone(); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java index 50d2370d6..fefa20200 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/TestReWriteSanity.java @@ -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 pp = new Hashtable(); + Map ue = new Hashtable(); ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first int pos = 0; int lastUEPos = -1;