poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1650070 - in /poi/trunk/src: java/org/apache/poi/ss/util/ImageUtils.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java testcases/org/apache/poi/ss/util/TestCellReference.java
Date Wed, 07 Jan 2015 14:36:40 GMT
Author: centic
Date: Wed Jan  7 14:36:39 2015
New Revision: 1650070

URL: http://svn.apache.org/r1650070
Log:
* Add missing close() on streams in ImageUtils.getImageDimension()
* Add some unit tests for CellReference

Modified:
    poi/trunk/src/java/org/apache/poi/ss/util/ImageUtils.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java

Modified: poi/trunk/src/java/org/apache/poi/ss/util/ImageUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/ImageUtils.java?rev=1650070&r1=1650069&r2=1650070&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/ImageUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/ImageUtils.java Wed Jan  7 14:36:39 2015
@@ -71,25 +71,30 @@ public class ImageUtils {
                 try {
                     //read the image using javax.imageio.*
                     ImageInputStream iis = ImageIO.createImageInputStream( is );
-                    Iterator<ImageReader> i = ImageIO.getImageReaders( iis );
-                    ImageReader r = i.next();
-                    r.setInput( iis );
-                    BufferedImage img = r.read(0);
+                    try {
+                        Iterator<ImageReader> i = ImageIO.getImageReaders( iis );
+                        ImageReader r = i.next();
+                        try {
+                            r.setInput( iis );
+                            BufferedImage img = r.read(0);
+        
+                            int[] dpi = getResolution(r);
+        
+                            //if DPI is zero then assume standard 96 DPI
+                            //since cannot divide by zero
+                            if (dpi[0] == 0) dpi[0] = PIXEL_DPI;
+                            if (dpi[1] == 0) dpi[1] = PIXEL_DPI;
+        
+                            size.width = img.getWidth()*PIXEL_DPI/dpi[0];
+                            size.height = img.getHeight()*PIXEL_DPI/dpi[1];
+                        } finally {
+                            r.dispose();
+                        }
+                    } finally {
+                        iis.close();
+                    }
 
-                    int[] dpi = getResolution(r);
-
-                    //if DPI is zero then assume standard 96 DPI
-                    //since cannot divide by zero
-                    if (dpi[0] == 0) dpi[0] = PIXEL_DPI;
-                    if (dpi[1] == 0) dpi[1] = PIXEL_DPI;
-
-                    size.width = img.getWidth()*PIXEL_DPI/dpi[0];
-                    size.height = img.getHeight()*PIXEL_DPI/dpi[1];
-
-                    r.dispose();
-                    iis.close();
-
-                } catch (IOException e){
+                } catch (IOException e) {
                     //silently return if ImageIO failed to read the image
                     logger.log(POILogger.WARN, e);
                 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1650070&r1=1650069&r2=1650070&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Wed Jan
 7 14:36:39 2015
@@ -50,7 +50,6 @@ import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.RegionUtil;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.XLSBUnsupportedException;
 import org.apache.poi.xssf.XSSFITestDataProvider;

Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java?rev=1650070&r1=1650069&r2=1650070&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestCellReference.java Wed Jan  7 14:36:39
2015
@@ -218,4 +218,34 @@ public final class TestCellReference ext
 		throw new AssertionFailedError("expected (c='" + colStr + "', r='" + rowStr + "' to be
"
 				+ (expResult ? "within" : "out of") + " bounds for version " + sv.name());
 	}
+	
+	public void testConvertColStringToIndex() {
+	    assertEquals(0, CellReference.convertColStringToIndex("A"));
+	    assertEquals(1, CellReference.convertColStringToIndex("B"));
+	    assertEquals(14, CellReference.convertColStringToIndex("O"));
+	    assertEquals(701, CellReference.convertColStringToIndex("ZZ"));
+	    assertEquals(18252, CellReference.convertColStringToIndex("ZZA"));
+	    
+	    assertEquals(0, CellReference.convertColStringToIndex("$A"));
+	    assertEquals(1, CellReference.convertColStringToIndex("$B"));
+	    
+	    try {
+	        CellReference.convertColStringToIndex("A$");
+	        fail("Should throw exception here");
+	    } catch (IllegalArgumentException e) {
+	        assertTrue(e.getMessage().contains("A$"));
+	    }
+    }
+    
+    public void testConvertNumColColString() {
+        assertEquals("A", CellReference.convertNumToColString(0));
+	    assertEquals("AV", CellReference.convertNumToColString(47));
+	    assertEquals("AW", CellReference.convertNumToColString(48));
+	    assertEquals("BF", CellReference.convertNumToColString(57));
+	    
+	    assertEquals("", CellReference.convertNumToColString(-1));
+	    assertEquals("", CellReference.convertNumToColString(Integer.MIN_VALUE));
+	    assertEquals("", CellReference.convertNumToColString(Integer.MAX_VALUE));
+	    assertEquals("FXSHRXW", CellReference.convertNumToColString(Integer.MAX_VALUE-1));
+	}
 }



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


Mime
View raw message