From 48ff8e5686aec8c050e01be1383f93b797aef407 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Tue, 29 Nov 2016 23:14:43 +0000 Subject: [PATCH] sonarcube fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1771978 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/sl/image/ImageHeaderEMF.java | 13 ++++---- .../apache/poi/sl/image/ImageHeaderPICT.java | 16 +++++----- .../apache/poi/sl/image/ImageHeaderWMF.java | 31 ++++++++++--------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java index 7845c0ff9..fc7be14fe 100644 --- a/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java +++ b/src/java/org/apache/poi/sl/image/ImageHeaderEMF.java @@ -28,15 +28,16 @@ import org.apache.poi.util.POILogger; @Internal public class ImageHeaderEMF { - private static POILogger LOG = POILogFactory.getLogger(ImageHeaderEMF.class); + private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderEMF.class); - private final static String EMF_SIGNATURE = " EMF"; // 0x464D4520 (LE) - - // rectangular inclusive-inclusive bounds, in device units, of the smallest + private static final String EMF_SIGNATURE = " EMF"; // 0x464D4520 (LE) + + // rectangular inclusive-inclusive bounds, in device units, of the smallest // rectangle that can be drawn around the image stored in the metafile. private final Rectangle deviceBounds; - public ImageHeaderEMF(byte data[], int offset) { + public ImageHeaderEMF(final byte data[], final int off) { + int offset = off; int type = (int)LittleEndian.getUInt(data, offset); offset += 4; if (type != 1) { LOG.log(POILogger.WARN, "Invalid EMF picture - invalid type"); @@ -61,7 +62,7 @@ public class ImageHeaderEMF { public Dimension getSize() { return deviceBounds.getSize(); } - + public Rectangle getBounds() { return deviceBounds; } diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderPICT.java b/src/java/org/apache/poi/sl/image/ImageHeaderPICT.java index d994fb8ce..ff121e3e7 100644 --- a/src/java/org/apache/poi/sl/image/ImageHeaderPICT.java +++ b/src/java/org/apache/poi/sl/image/ImageHeaderPICT.java @@ -29,9 +29,9 @@ public class ImageHeaderPICT { * skip the first 512 bytes - they are MAC specific crap */ public static final int PICT_HEADER_OFFSET = 512; - + public static final double DEFAULT_RESOLUTION = Units.POINT_DPI; - + private static final byte V2_HEADER[] = { 0x00, 0x11, // v2 version opcode 0x02, (byte)0xFF, // version number of new picture @@ -41,10 +41,10 @@ public class ImageHeaderPICT { private final Rectangle bounds; private final double hRes, vRes; - - public ImageHeaderPICT(byte data[], int offset) { - // http://mirrors.apple2.org.za/apple.cabi.net/Graphics/PICT.and_QT.INFO/PICT.file.format.TI.txt + public ImageHeaderPICT(byte data[], final int off) { + // http://mirrors.apple2.org.za/apple.cabi.net/Graphics/PICT.and_QT.INFO/PICT.file.format.TI.txt + int offset = off; // low order 16 bits of picture size - can be ignored offset += 2; // rectangular bounding box of picture, at 72 dpi @@ -62,7 +62,7 @@ public class ImageHeaderPICT { break; } } - + if (isV2) { // 4 bytes - fixed, horizontal resolution (dpi) of source data hRes = readFixedPoint(data, offset); offset += 4; @@ -72,7 +72,7 @@ public class ImageHeaderPICT { hRes = DEFAULT_RESOLUTION; vRes = DEFAULT_RESOLUTION; } - + bounds = new Rectangle(x1,y1,x2-x1,y2-y1); } @@ -85,7 +85,7 @@ public class ImageHeaderPICT { public Rectangle getBounds() { return bounds; } - + private static int readUnsignedShort(byte data[], int offset) { int b0 = data[offset] & 0xFF; int b1 = data[offset+1] & 0xFF; diff --git a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java index b57b4d009..c3274d97f 100644 --- a/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java +++ b/src/java/org/apache/poi/sl/image/ImageHeaderWMF.java @@ -46,7 +46,7 @@ import org.apache.poi.util.Units; public class ImageHeaderWMF { public static final int APMHEADER_KEY = 0x9AC6CDD7; - private static POILogger LOG = POILogFactory.getLogger(ImageHeaderWMF.class); + private static final POILogger LOG = POILogFactory.getLogger(ImageHeaderWMF.class); @SuppressWarnings("unused") private final int handle; @@ -55,16 +55,16 @@ public class ImageHeaderWMF { /** * The number of logical units per inch used to represent the image. * This value can be used to scale an image. By convention, an image is - * considered to be recorded at 1440 logical units (twips) per inch. + * considered to be recorded at 1440 logical units (twips) per inch. * Thus, a value of 720 specifies that the image SHOULD be rendered at * twice its normal size, and a value of 2880 specifies that the image * SHOULD be rendered at half its normal size. */ - private final int inch; + private final int inch; @SuppressWarnings("unused") private final int reserved; private int checksum; - + public ImageHeaderWMF(Rectangle dim) { handle = 0; left = dim.x; @@ -75,8 +75,9 @@ public class ImageHeaderWMF { reserved = 0; } - public ImageHeaderWMF(byte[] data, int pos) { - int key = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; //header key + public ImageHeaderWMF(byte[] data, final int off) { + int offset = off; + int key = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; //header key if (key != APMHEADER_KEY) { LOG.log(POILogger.WARN, "WMF file doesn't contain a placeable header - ignore parsing"); handle = 0; @@ -89,16 +90,16 @@ public class ImageHeaderWMF { return; } - handle = LittleEndian.getUShort(data, pos); pos += LittleEndian.SHORT_SIZE; - left = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE; - top = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE; - right = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE; - bottom = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE; + handle = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; + left = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + top = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + right = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; + bottom = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; - inch = LittleEndian.getUShort(data, pos); pos += LittleEndian.SHORT_SIZE; - reserved = LittleEndian.getInt(data, pos); pos += LittleEndian.INT_SIZE; + inch = LittleEndian.getUShort(data, offset); offset += LittleEndian.SHORT_SIZE; + reserved = LittleEndian.getInt(data, offset); offset += LittleEndian.INT_SIZE; - checksum = LittleEndian.getShort(data, pos); pos += LittleEndian.SHORT_SIZE; + checksum = LittleEndian.getShort(data, offset); offset += LittleEndian.SHORT_SIZE; if (checksum != getChecksum()){ LOG.log(POILogger.WARN, "WMF checksum does not match the header data"); } @@ -147,7 +148,7 @@ public class ImageHeaderWMF { public Rectangle getBounds() { return new Rectangle(left, top, right-left, bottom-top); } - + public int getLength(){ return 22; }