SonarQube fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777739 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-01-07 00:26:46 +00:00
parent 1042dacd93
commit 24c0b83841
6 changed files with 50 additions and 51 deletions

View File

@ -17,9 +17,7 @@
package org.apache.poi.util; package org.apache.poi.util;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -168,7 +166,9 @@ public class HexDump {
public static char toAscii(int dataB) { public static char toAscii(int dataB) {
char charB = (char)(dataB & 0xFF); char charB = (char)(dataB & 0xFF);
if (Character.isISOControl(charB)) return '.'; if (Character.isISOControl(charB)) {
return '.';
}
switch (charB) { switch (charB) {
// printable, but not compilable with current compiler encoding // printable, but not compilable with current compiler encoding
@ -408,12 +408,10 @@ public class HexDump {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws IOException {
File file = new File(args[0]); InputStream in = new FileInputStream(args[0]);
InputStream in = new BufferedInputStream(new FileInputStream(file)); byte[] b = IOUtils.toByteArray(in);
byte[] b = new byte[(int)file.length()];
in.read(b);
System.out.println(HexDump.dump(b, 0, 0));
in.close(); in.close();
System.out.println(HexDump.dump(b, 0, 0));
} }
} }

View File

@ -56,7 +56,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
final int size = LittleEndianConsts.INT_SIZE; final int size = LittleEndianConsts.INT_SIZE;
checkPosition(size); checkPosition(size);
int le = LittleEndian.getInt(buf, pos); int le = LittleEndian.getInt(buf, pos);
super.skip(size); if (super.skip(size) < size) {
throw new RuntimeException("Buffer overrun");
}
return le; return le;
} }
@ -65,7 +67,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
final int size = LittleEndianConsts.LONG_SIZE; final int size = LittleEndianConsts.LONG_SIZE;
checkPosition(size); checkPosition(size);
long le = LittleEndian.getLong(buf, pos); long le = LittleEndian.getLong(buf, pos);
super.skip(size); if (super.skip(size) < size) {
throw new RuntimeException("Buffer overrun");
}
return le; return le;
} }
@ -84,7 +88,9 @@ public final class LittleEndianByteArrayInputStream extends ByteArrayInputStream
final int size = LittleEndianConsts.SHORT_SIZE; final int size = LittleEndianConsts.SHORT_SIZE;
checkPosition(size); checkPosition(size);
int le = LittleEndian.getUShort(buf, pos); int le = LittleEndian.getUShort(buf, pos);
super.skip(size); if (super.skip(size) < size) {
throw new RuntimeException("Buffer overrun");
}
return le; return le;
} }

View File

@ -118,7 +118,7 @@ public class CombinedIterable<T> implements Iterable<T> {
} else { } else {
lastI = masterIdx; lastI = masterIdx;
val = currentMaster.getValue(); val = (currentMaster != null) ? currentMaster.getValue() : null;
currentMaster = null; currentMaster = null;
} }

View File

@ -101,6 +101,7 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
/** /**
* Gets the slide text, but not the notes text * Gets the slide text, but not the notes text
*/ */
@Override
public String getText() { public String getText() {
return getText(slidesByDefault, notesByDefault); return getText(slidesByDefault, notesByDefault);
} }
@ -162,13 +163,11 @@ public class XSLFPowerPointExtractor extends POIXMLTextExtractor {
// If requested, get text from the master and it's layout // If requested, get text from the master and it's layout
if(masterText) { if(masterText) {
if(layout != null) { assert (layout != null);
extractText(layout, true, text); extractText(layout, true, text);
} assert (master != null);
if(master != null) {
extractText(master, true, text); extractText(master, true, text);
} }
}
// If the slide has comments, do those too // If the slide has comments, do those too
if (comments != null) { if (comments != null) {

View File

@ -115,11 +115,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
} catch (Exception e){ } catch (Exception e){
throw new POIXMLException(e); throw new POIXMLException(e);
} finally { } finally {
try { IOUtils.closeQuietly(is);
is.close();
} catch (Exception e) {
throw new POIXMLException(e);
}
} }
} }

View File

@ -17,6 +17,9 @@
package org.apache.poi.xssf.streaming; 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.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.Picture; import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.usermodel.Row; 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.Internal;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; 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.CTPositiveSize2D;
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture; import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import java.awt.Dimension;
import java.io.IOException;
/** /**
* Streaming version of Picture. * Streaming version of Picture.
* Most of the code is a copy of the non-streaming XSSFPicture code. * Most of the code is a copy of the non-streaming XSSFPicture code.
@ -140,38 +147,31 @@ public final class SXSSFPicture implements Picture {
double scaledHeight = size.getHeight() * scale; double scaledHeight = size.getHeight() * scale;
float w = 0; float w = 0;
int col2 = anchor.getCol1(); int col2 = anchor.getCol1()-1;
int dx2 = 0;
for (;;) { while (w <= scaledWidth) {
w += getColumnWidthInPixels(col2); w += getColumnWidthInPixels(++col2);
if(w > scaledWidth) break;
col2++;
} }
if(w > scaledWidth) { assert (w > scaledWidth);
double cw = getColumnWidthInPixels(col2 ); double cw = getColumnWidthInPixels(col2);
double delta = w - scaledWidth; double deltaW = w - scaledWidth;
dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - delta)); int dx2 = (int)(XSSFShape.EMU_PER_PIXEL * (cw - deltaW));
}
anchor.setCol2(col2); anchor.setCol2(col2);
anchor.setDx2(dx2); anchor.setDx2(dx2);
double h = 0; double h = 0;
int row2 = anchor.getRow1(); int row2 = anchor.getRow1()-1;
int dy2 = 0;
for (;;) { while (h <= scaledHeight) {
h += getRowHeightInPixels(row2); h += getRowHeightInPixels(++row2);
if(h > scaledHeight) break;
row2++;
} }
if(h > scaledHeight) { assert (h > scaledHeight);
double ch = getRowHeightInPixels(row2); double ch = getRowHeightInPixels(row2);
double delta = h - scaledHeight; double deltaH = h - scaledHeight;
dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - delta)); int dy2 = (int)(XSSFShape.EMU_PER_PIXEL * (ch - deltaH));
}
anchor.setRow2(row2); anchor.setRow2(row2);
anchor.setDy2(dy2); anchor.setDy2(dy2);