if (cp == CodePageUtil.CP_UNICODE) {
pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3);
}
- leis.skip(pad);
+ IOUtils.skipFully(leis, pad);
dic.put(id, str);
- } catch (RuntimeException ex) {
+ } catch (RuntimeException|IOException ex) {
LOG.log(POILogger.WARN, errMsg, ex);
isCorrupted = true;
break;
* @return Formatted value
*/
private String getFormattedDateString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
+ if (cell == null) {
+ return null;
+ }
Format dateFormat = getFormat(cell, cfEvaluator);
if(dateFormat instanceof ExcelStyleDateFormatter) {
// Hint about the raw excel value
* @return a formatted number string
*/
private String getFormattedNumberString(Cell cell, ConditionalFormattingEvaluator cfEvaluator) {
-
+ if (cell == null) {
+ return null;
+ }
Format numberFormat = getFormat(cell, cfEvaluator);
double d = cell.getNumericCellValue();
if (numberFormat == null) {
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
- } catch (OpenXML4JException | Error | RuntimeException | IOException | XmlException e) {
+ } catch (OpenXML4JException | Error | RuntimeException | IOException | XmlException e) { // NOSONAR
// ensure file-handle release
IOUtils.closeQuietly(fs);
throw e;
throw new IllegalArgumentException("No supported documents found in the OOXML package (found "+contentType+")");
- } catch (IOException | Error | RuntimeException | XmlException | OpenXML4JException e) {
+ } catch (IOException | Error | RuntimeException | XmlException | OpenXML4JException e) { // NOSONAR
// ensure that we close the package again if there is an error opening it, however
// we need to revert the package to not re-write the file via close(), which is very likely not wanted for a TextExtractor!
pkg.revert();
saxFactory = SAXParserFactory.newInstance();
saxFactory.setValidating(false);
saxFactory.setNamespaceAware(true);
- } catch (RuntimeException | Error re) {
+ } catch (RuntimeException | Error re) { // NOSONAR
// this also catches NoClassDefFoundError, which may be due to a local class path issue
// This may occur if the code is run inside a web container
// or a restricted JVM
@Override
public void resize(double scale){
XSSFClientAnchor anchor = getClientAnchor();
- if (anchor == null) {
+ XSSFClientAnchor pref = getPreferredSize(scale);
+ if (anchor == null || pref == null) {
logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call");
return;
}
- XSSFClientAnchor pref = getPreferredSize(scale);
-
int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1());
int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());
*/
public void resize(double scaleX, double scaleY){
XSSFClientAnchor anchor = getClientAnchor();
-
XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
+ if (anchor == null || pref == null) {
+ logger.log(POILogger.WARN, "picture is not anchored via client anchor - ignoring resize call");
+ return;
+ }
int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1());
int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());
public Long getChecksum() {
if (this.checksum == null) {
- InputStream is = null;
byte[] data;
- try {
- is = getPackagePart().getInputStream();
+ try (InputStream is = getPackagePart().getInputStream()) {
data = IOUtils.toByteArray(is);
} catch (IOException e) {
throw new POIXMLException(e);
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- } catch (IOException e) {
- throw new POIXMLException(e);
- }
}
this.checksum = IOUtils.calculateChecksum(data);
}
import org.apache.poi.hslf.model.textproperties.HSLFTabStop;
import org.apache.poi.hslf.model.textproperties.HSLFTabStopPropCollection;
import org.apache.poi.util.BitField;
+import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
try {
// Get the header.
- leis.read(_header);
+ IOUtils.readFully(leis, _header);
// Get the record data.
read(leis);