]> source.dussan.org Git - poi.git/commitdiff
Eclipse warnings, close resources in CommandLineTextExtractor, add try/finally, forma...
authorDominik Stadler <centic@apache.org>
Thu, 3 Sep 2015 20:59:14 +0000 (20:59 +0000)
committerDominik Stadler <centic@apache.org>
Thu, 3 Sep 2015 20:59:14 +0000 (20:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1701139 13f79535-47bb-0310-9956-ffa450edef68

src/integrationtest/org/apache/poi/stress/AbstractFileHandler.java
src/ooxml/java/org/apache/poi/extractor/CommandLineTextExtractor.java
src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFAutoShape.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java

index 55e2c368f2927131eb3b6d5d07ec707aec8511eb..3bb0a53d5cc51763a87680fe8026c6b82fc9a08b 100644 (file)
@@ -27,11 +27,9 @@ import java.io.IOException;
 import java.io.InputStream;\r
 import java.util.HashSet;\r
 import java.util.Set;\r
-import java.util.zip.ZipException;\r
 \r
 import org.apache.poi.POIOLE2TextExtractor;\r
 import org.apache.poi.POITextExtractor;\r
-import org.apache.poi.dev.OOXMLPrettyPrint;\r
 import org.apache.poi.extractor.ExtractorFactory;\r
 import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;\r
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;\r
index 8f9ea7599e67003624625284d00c9477a5353941..919539592b4e72b29bcec84a2728086e7e6a6e23 100644 (file)
@@ -42,14 +42,18 @@ public class CommandLineTextExtractor {
          
          POITextExtractor extractor = 
             ExtractorFactory.createExtractor(f);
-         POITextExtractor metadataExtractor =
-            extractor.getMetadataTextExtractor();
-         
-         System.out.println("   " + DIVIDER);
-         System.out.println(metadataExtractor.getText());
-         System.out.println("   " + DIVIDER);
-         System.out.println(extractor.getText());
-         System.out.println(DIVIDER);
+         try {
+             POITextExtractor metadataExtractor =
+                extractor.getMetadataTextExtractor();
+             
+             System.out.println("   " + DIVIDER);
+             System.out.println(metadataExtractor.getText());
+             System.out.println("   " + DIVIDER);
+             System.out.println(extractor.getText());
+             System.out.println(DIVIDER);
+         } finally {
+             extractor.close();
+         }
       }
    }
 }
index 8937f8e53ff46e90db8c9557dcfd410db697bfe9..ade8c806c325608071c4e59b31ed80fc8ea7d9a3 100644 (file)
@@ -50,6 +50,7 @@ import org.apache.poi.util.TempFile;
 /**
  * Physical zip package.
  */
+@SuppressWarnings("deprecation")
 public final class ZipPackage extends Package {
     private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
 
@@ -62,7 +63,6 @@ public final class ZipPackage extends Package {
     /**
      * Constructor. Creates a new, empty ZipPackage.
      */
-    @SuppressWarnings("deprecation")
     public ZipPackage() {
        super(defaultPackageAccess);
        this.zipArchive = null;
@@ -84,7 +84,6 @@ public final class ZipPackage extends Package {
      *             If the specified input stream not an instance of
      *             ZipInputStream.
      */
-    @SuppressWarnings("deprecation")
     ZipPackage(InputStream in, PackageAccess access) throws IOException {
        super(access);
        InputStream zis = new ZipInputStream(in);
@@ -102,7 +101,6 @@ public final class ZipPackage extends Package {
      * @throws InvalidFormatException
      *             If the content type part parsing encounters an error.
      */
-    @SuppressWarnings("deprecation")
     ZipPackage(String path, PackageAccess access) {
        super(access);
 
@@ -128,7 +126,6 @@ public final class ZipPackage extends Package {
      * @throws InvalidFormatException
      *             If the content type part parsing encounters an error.
      */
-    @SuppressWarnings("deprecation")
     ZipPackage(File file, PackageAccess access) {
        super(access);
 
@@ -156,7 +153,6 @@ public final class ZipPackage extends Package {
      * @throws InvalidFormatException
      *             If the content type part parsing encounters an error.
      */
-    @SuppressWarnings("deprecation")
     ZipPackage(ZipEntrySource zipEntry, PackageAccess access) {
        super(access);
        this.zipArchive = zipEntry;
index 7bb2fd6db465a239883c0d795ff004a7fd49849a..9d35eceace290cb27fc6cd6baf81f8f65b2b3d92 100644 (file)
@@ -917,8 +917,8 @@ public class XSSFCellStyle implements CellStyle {
      * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
      * @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
      */
-   @Override
-public void setBorderRight(short border) {
+    @Override
+    public void setBorderRight(short border) {
         CTBorder ct = getCTBorder();
         CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
         if(border == BORDER_NONE) ct.unsetRight();
index 7accdfdc256b87a244f32a1ed8b0388d80bb10bb..3350149751c28e16d73257db5c70c2b767e07e0f 100644 (file)
@@ -18,6 +18,8 @@ package org.apache.poi.xslf.usermodel;
 \r
 import static org.junit.Assert.*;\r
 \r
+import java.io.IOException;\r
+\r
 import org.apache.poi.sl.usermodel.*;\r
 import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;\r
 import org.apache.poi.sl.usermodel.TextShape.TextAutofit;\r
@@ -32,7 +34,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
  */\r
 public class TestXSLFAutoShape {\r
     @Test\r
-    public void testTextBodyProperies() {\r
+    public void testTextBodyProperies() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
 \r
@@ -102,10 +104,12 @@ public class TestXSLFAutoShape {
         assertEquals(TextDirection.VERTICAL, shape.getTextDirection());\r
         shape.setTextDirection(null);\r
         assertEquals(TextDirection.HORIZONTAL, shape.getTextDirection());\r
+        \r
+        ppt.close();\r
     }\r
 \r
     @Test\r
-    public void testTextParagraph() {\r
+    public void testTextParagraph() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
         assertTrue(slide.getShapes().isEmpty());\r
@@ -202,10 +206,12 @@ public class TestXSLFAutoShape {
         p.setTextAlign(null);\r
         assertEquals(TextAlign.LEFT, p.getTextAlign());\r
         assertFalse(p.getXmlObject().getPPr().isSetAlgn());\r
+        \r
+        ppt.close();\r
     }\r
 \r
     @Test\r
-    public void testTextRun() {\r
+    public void testTextRun() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
 \r
@@ -272,10 +278,12 @@ public class TestXSLFAutoShape {
         assertEquals("POI", r.getRawText());\r
         r.setText(null);\r
         assertNull(r.getRawText());\r
+        \r
+        ppt.close();\r
     }\r
 \r
     @Test\r
-    public void testShapeType() {\r
+    public void testShapeType() throws IOException {\r
         XMLSlideShow ppt = new XMLSlideShow();\r
         XSLFSlide slide = ppt.createSlide();\r
 \r
@@ -290,5 +298,7 @@ public class TestXSLFAutoShape {
             shape.setShapeType(tp);\r
             assertEquals(tp, shape.getShapeType());\r
         }\r
+        \r
+        ppt.close();\r
     }\r
 }
\ No newline at end of file
index 41e0580b70b4fba6261f6c95cf7b53961451fd5f..566d1d712a7d1badcfa26be88dbd60b2a259c699 100644 (file)
@@ -2381,9 +2381,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
 
         // using temp file instead of ByteArrayOutputStream because of OOM in gump run
         File tmp = TempFile.createTempFile("poi-test", ".bug57880");
-        FileOutputStream fos = new FileOutputStream(tmp);
-        wb.write(fos);
-        fos.close();
+        OutputStream fos = new FileOutputStream(tmp);
+        try {
+            wb.write(fos);
+        } finally {
+            fos.close();
+        }
         
         wb.close();
         fmt = null; /*s = null;*/ wb = null;
index d37a28eb2a81097d756531e9e6fd1e204007dafa..17fba4a29a855047049eeb037752cbd75958f010 100644 (file)
@@ -139,5 +139,7 @@ public final class VisioTextExtractor extends POIOLE2TextExtractor {
 
                // Print not PrintLn as already has \n added to it
                System.out.print(extractor.getText());
+               
+               extractor.close();
        }
 }
index 8ef9a41be5f546aac987d866ff152a13e7ab7fc7..f1aad88c1f489b91581ad4a2c5f400821a406249 100644 (file)
@@ -228,6 +228,7 @@ public final class TestHSSFDataFormatter extends TestCase {
                row = wb.getSheetAt(0).getRow(1);
       it = row.cellIterator();
       log("==== VALID TIME FORMATS ====");
+      
       while (it.hasNext()) {
          Cell cell = it.next();
          String fmt = cell.getCellStyle().getDataFormatString();
@@ -239,7 +240,8 @@ public final class TestHSSFDataFormatter extends TestCase {
          assertTrue( ! "555.47431".equals(fmtval));
 
          // check we found the time properly
-         assertTrue("Format came out incorrect - " + fmt, fmtval.indexOf("11:23") > -1);
+         assertTrue("Format came out incorrect - " + fmt + ": " + fmtval + ", but expected to find '11:23'", 
+                 fmtval.indexOf("11:23") > -1);
       }
       
                // test number formats
@@ -409,8 +411,8 @@ public final class TestHSSFDataFormatter extends TestCase {
        }
 
        private static void log(String msg) {
-               if (false) { // successful tests should be silent
-                       System.out.println(msg);
-               }
+//             if (false) { // successful tests should be silent
+//                     System.out.println(msg);
+//             }
        }
 }