poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1777739 - in /poi/trunk/src: java/org/apache/poi/util/ ooxml/java/org/apache/poi/xdgf/usermodel/section/ ooxml/java/org/apache/poi/xslf/extractor/ ooxml/java/org/apache/poi/xslf/usermodel/ ooxml/java/org/apache/poi/xssf/streaming/
Date Sat, 07 Jan 2017 00:26:47 GMT
Author: kiwiwings
Date: Sat Jan  7 00:26:46 2017
New Revision: 1777739

URL: http://svn.apache.org/viewvc?rev=1777739&view=rev
Log:
SonarQube fixes

Modified:
    poi/trunk/src/java/org/apache/poi/util/HexDump.java
    poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
    poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java

Modified: poi/trunk/src/java/org/apache/poi/util/HexDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/HexDump.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/HexDump.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/HexDump.java Sat Jan  7 00:26:46 2017
@@ -17,9 +17,7 @@
 
 package org.apache.poi.util;
 
-import java.io.BufferedInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -168,7 +166,9 @@ public class HexDump {
 
     public static char toAscii(int dataB) {
         char charB = (char)(dataB & 0xFF);
-        if (Character.isISOControl(charB)) return '.';
+        if (Character.isISOControl(charB)) {
+            return '.';
+        }
         
         switch (charB) {
             // printable, but not compilable with current compiler encoding
@@ -408,12 +408,10 @@ public class HexDump {
     }    
     
     
-    public static void main(String[] args) throws Exception {
-        File file = new File(args[0]);
-        InputStream in = new BufferedInputStream(new FileInputStream(file));
-        byte[] b = new byte[(int)file.length()];
-        in.read(b);
-        System.out.println(HexDump.dump(b, 0, 0));
+    public static void main(String[] args) throws IOException {
+        InputStream in = new FileInputStream(args[0]);
+        byte[] b = IOUtils.toByteArray(in);
         in.close();
+        System.out.println(HexDump.dump(b, 0, 0));
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java Sat Jan 
7 00:26:46 2017
@@ -56,7 +56,9 @@ public final class LittleEndianByteArray
 	    final int size = LittleEndianConsts.INT_SIZE;
 		checkPosition(size);
 		int le = LittleEndian.getInt(buf, pos);
-		super.skip(size);
+        if (super.skip(size) < size) {
+            throw new RuntimeException("Buffer overrun");
+        }
 		return le;
 	}
 
@@ -65,7 +67,9 @@ public final class LittleEndianByteArray
 	    final int size = LittleEndianConsts.LONG_SIZE;
 		checkPosition(size);
 		long le = LittleEndian.getLong(buf, pos);
-		super.skip(size);
+		if (super.skip(size) < size) {
+		    throw new RuntimeException("Buffer overrun");
+		}
 		return le;
 	}
 
@@ -84,7 +88,9 @@ public final class LittleEndianByteArray
         final int size = LittleEndianConsts.SHORT_SIZE;
         checkPosition(size);
         int le = LittleEndian.getUShort(buf, pos);
-        super.skip(size);
+        if (super.skip(size) < size) {
+            throw new RuntimeException("Buffer overrun");
+        }
         return le;
 	}
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xdgf/usermodel/section/CombinedIterable.java Sat
Jan  7 00:26:46 2017
@@ -118,7 +118,7 @@ public class CombinedIterable<T> impleme
 
                     } else {
                         lastI = masterIdx;
-                        val = currentMaster.getValue();
+                        val = (currentMaster != null) ? currentMaster.getValue() : null;
                         currentMaster = null;
                     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java Sat
Jan  7 00:26:46 2017
@@ -101,7 +101,8 @@ public class XSLFPowerPointExtractor ext
 	/**
 	 * Gets the slide text, but not the notes text
 	 */
-	public String getText() {
+	@Override
+    public String getText() {
 		return getText(slidesByDefault, notesByDefault);
 	}
 	
@@ -162,12 +163,10 @@ public class XSLFPowerPointExtractor ext
           
           // If requested, get text from the master and it's layout 
           if(masterText) {
-             if(layout != null) {
-                extractText(layout, true, text);
-             }
-             if(master != null) {
-                extractText(master, true, text);
-             }
+             assert (layout != null);
+             extractText(layout, true, text);
+             assert (master != null);
+             extractText(master, true, text);
           }
 
           // If the slide has comments, do those too

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java Sat Jan  7 00:26:46
2017
@@ -115,11 +115,7 @@ implements SlideShow<XSLFShape,XSLFTextP
         } catch (Exception e){
             throw new POIXMLException(e);
         } finally {
-            try {
-                is.close();
-            } catch (Exception e) {
-                throw new POIXMLException(e);
-            }
+            IOUtils.closeQuietly(is);
         }
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java?rev=1777739&r1=1777738&r2=1777739&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java Sat Jan  7 00:26:46
2017
@@ -17,6 +17,9 @@
 
 package org.apache.poi.xssf.streaming;
 
+import java.awt.Dimension;
+import java.io.IOException;
+
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.ss.usermodel.Picture;
 import org.apache.poi.ss.usermodel.Row;
@@ -26,15 +29,19 @@ import org.apache.poi.ss.util.ImageUtils
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
-import org.apache.poi.xssf.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFAnchor;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFPicture;
+import org.apache.poi.xssf.usermodel.XSSFPictureData;
+import org.apache.poi.xssf.usermodel.XSSFShape;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 
-import java.awt.Dimension;
-import java.io.IOException;
-
 /**
  * Streaming version of Picture.
  * Most of the code is a copy of the non-streaming XSSFPicture code.
@@ -140,38 +147,31 @@ public final class SXSSFPicture implemen
         double scaledHeight = size.getHeight() * scale;
 
         float w = 0;
-        int col2 = anchor.getCol1();
-        int dx2 = 0;
+        int col2 = anchor.getCol1()-1;
 
-        for (;;) {
-            w += getColumnWidthInPixels(col2);
-            if(w > scaledWidth) break;
-            col2++;
+        while (w <= scaledWidth) {
+            w += getColumnWidthInPixels(++col2);
         }
 
-        if(w > scaledWidth) {
-            double cw = getColumnWidthInPixels(col2 );
-            double delta = w - scaledWidth;
-            dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - delta));
-        }
+        assert (w > scaledWidth);
+        double cw = getColumnWidthInPixels(col2);
+        double deltaW = w - scaledWidth;
+        int dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - deltaW));
+
         anchor.setCol2(col2);
         anchor.setDx2(dx2);
 
         double h = 0;
-        int row2 = anchor.getRow1();
-        int dy2 = 0;
+        int row2 = anchor.getRow1()-1;
 
-        for (;;) {
-            h += getRowHeightInPixels(row2);
-            if(h > scaledHeight) break;
-            row2++;
+        while (h <= scaledHeight) {
+            h += getRowHeightInPixels(++row2);
         }
 
-        if(h > scaledHeight) {
-            double ch = getRowHeightInPixels(row2);
-            double delta = h - scaledHeight;
-            dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - delta));
-        }
+        assert (h > scaledHeight);
+        double ch = getRowHeightInPixels(row2);
+        double deltaH = h - scaledHeight;
+        int dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - deltaH));
         anchor.setRow2(row2);
         anchor.setDy2(dy2);
 



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


Mime
View raw message