git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893847 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_2_0
@@ -104,8 +104,10 @@ import org.apache.poi.util.TempFile; | |||
if (encryptedTempData != null) { | |||
encryptedTempData.dispose(); | |||
} | |||
if (tempFile != null) { | |||
tempFile.delete(); | |||
if (tempFile != null && tempFile.exists()) { | |||
if (!tempFile.delete()) { | |||
LOG.atDebug().log("temp file was already deleted (probably due to previous call to close this resource)"); | |||
} | |||
} | |||
} | |||
} |
@@ -826,7 +826,7 @@ public final class HemfPlusDraw { | |||
@SuppressWarnings("squid:S2111") | |||
static double round10(double d) { | |||
return new BigDecimal(d).setScale(10, RoundingMode.HALF_UP).doubleValue(); | |||
return BigDecimal.valueOf(d).setScale(10, RoundingMode.HALF_UP).doubleValue(); | |||
} | |||
static int readRectS(LittleEndianInputStream leis, Rectangle2D bounds) { |
@@ -17,6 +17,7 @@ | |||
package org.apache.poi.hssf.record; | |||
import java.io.IOException; | |||
import java.util.Map; | |||
import java.util.function.Supplier; | |||
@@ -179,15 +180,19 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord { | |||
} | |||
private static Ptg readRefPtg(byte[] formulaRawBytes) { | |||
LittleEndianInput in = new LittleEndianInputStream(new UnsynchronizedByteArrayInputStream(formulaRawBytes)); | |||
byte ptgSid = in.readByte(); | |||
switch(ptgSid) { | |||
case AreaPtg.sid: return new AreaPtg(in); | |||
case Area3DPtg.sid: return new Area3DPtg(in); | |||
case RefPtg.sid: return new RefPtg(in); | |||
case Ref3DPtg.sid: return new Ref3DPtg(in); | |||
try (LittleEndianInputStream in = new LittleEndianInputStream( | |||
new UnsynchronizedByteArrayInputStream(formulaRawBytes))) { | |||
byte ptgSid = in.readByte(); | |||
switch(ptgSid) { | |||
case AreaPtg.sid: return new AreaPtg(in); | |||
case Area3DPtg.sid: return new Area3DPtg(in); | |||
case RefPtg.sid: return new RefPtg(in); | |||
case Ref3DPtg.sid: return new Ref3DPtg(in); | |||
} | |||
return null; | |||
} catch (IOException e) { | |||
throw new RuntimeException("Unexpected exception in readRefPtg", e); | |||
} | |||
return null; | |||
} | |||
private static byte[] readRawData(LittleEndianInput in, int size) { |
@@ -16,6 +16,8 @@ | |||
==================================================================== */ | |||
package org.apache.poi.poifs.filesystem; | |||
import org.apache.logging.log4j.LogManager; | |||
import org.apache.logging.log4j.Logger; | |||
import org.apache.poi.poifs.nio.FileBackedDataSource; | |||
import org.apache.poi.util.Beta; | |||
import org.apache.poi.util.TempFile; | |||
@@ -30,6 +32,7 @@ import java.io.IOException; | |||
*/ | |||
@Beta | |||
public class TempFilePOIFSFileSystem extends POIFSFileSystem { | |||
private static Logger LOG = LogManager.getLogger(TempFilePOIFSFileSystem.class); | |||
File tempFile; | |||
@Override | |||
@@ -44,7 +47,11 @@ public class TempFilePOIFSFileSystem extends POIFSFileSystem { | |||
@Override | |||
public void close() throws IOException { | |||
if (tempFile != null && tempFile.exists()) tempFile.delete(); | |||
if (tempFile != null && tempFile.exists()) { | |||
if (!tempFile.delete()) { | |||
LOG.atDebug().log("temp file was already deleted (probably due to previous call to close this resource)"); | |||
} | |||
} | |||
super.close(); | |||
} | |||
@@ -42,7 +42,7 @@ public class CellDateFormatter extends CellFormatter { | |||
private static final Calendar EXCEL_EPOCH_CAL = | |||
LocaleUtil.getLocaleCalendar(1904, 0, 1); | |||
private static final double NUM_MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24; | |||
private static final int NUM_MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24; | |||
private static /* final */ CellDateFormatter SIMPLE_DATE; | |||
@@ -134,7 +134,7 @@ final class PercentRankExcFunction implements FreeRefFunction { | |||
for (Double d : numbers) { | |||
if (d < x) lessThanCount++; | |||
} | |||
BigDecimal result = new BigDecimal((double)(lessThanCount + 1) / (double)(numbers.size() + 1)); | |||
BigDecimal result = BigDecimal.valueOf((double)(lessThanCount + 1) / (double)(numbers.size() + 1)); | |||
return new NumberEval(PercentRank.round(result, significance)); | |||
} else { | |||
int intermediateSignificance = significance < 5 ? 8 : significance + 3; |
@@ -75,17 +75,14 @@ public final class Fixed implements Function1Arg, Function2Arg, Function3Arg { | |||
OperandResolver.getSingleValue( | |||
numberParam, srcRowIndex, srcColumnIndex); | |||
BigDecimal number = | |||
new BigDecimal(OperandResolver.coerceValueToDouble(numberValueEval)); | |||
BigDecimal.valueOf(OperandResolver.coerceValueToDouble(numberValueEval)); | |||
ValueEval placesValueEval = | |||
OperandResolver.getSingleValue( | |||
placesParam, srcRowIndex, srcColumnIndex); | |||
OperandResolver.getSingleValue(placesParam, srcRowIndex, srcColumnIndex); | |||
int places = OperandResolver.coerceValueToInt(placesValueEval); | |||
ValueEval skipThousandsSeparatorValueEval = | |||
OperandResolver.getSingleValue( | |||
skipThousandsSeparatorParam, srcRowIndex, srcColumnIndex); | |||
OperandResolver.getSingleValue(skipThousandsSeparatorParam, srcRowIndex, srcColumnIndex); | |||
Boolean skipThousandsSeparator = | |||
OperandResolver.coerceValueToBoolean( | |||
skipThousandsSeparatorValueEval, false); | |||
OperandResolver.coerceValueToBoolean(skipThousandsSeparatorValueEval, false); | |||
// Round number to respective places. | |||
number = number.setScale(places, RoundingMode.HALF_UP); |
@@ -123,8 +123,12 @@ public final class PercentRank implements Function { | |||
if (greaterThanCount == numbers.size() || lessThanCount == numbers.size()) { | |||
return ErrorEval.NA; | |||
} | |||
BigDecimal result = new BigDecimal((double)lessThanCount / (double)(lessThanCount + greaterThanCount)); | |||
return new NumberEval(round(result, significance)); | |||
if (lessThanCount + greaterThanCount == 0) { | |||
return new NumberEval(0); | |||
} else { | |||
BigDecimal result = BigDecimal.valueOf((double)lessThanCount / (double)(lessThanCount + greaterThanCount)); | |||
return new NumberEval(round(result, significance)); | |||
} | |||
} else { | |||
int intermediateSignificance = significance < 5 ? 8 : significance + 3; | |||
ValueEval belowRank = calculateRank(numbers, closestMatchBelow, intermediateSignificance, false); | |||
@@ -145,7 +149,7 @@ public final class PercentRank implements Function { | |||
double diff = closestMatchAbove - closestMatchBelow; | |||
double pos = x - closestMatchBelow; | |||
BigDecimal rankDiff = new BigDecimal(NumberToTextConverter.toText(aboveRank.getNumberValue() - belowRank.getNumberValue())); | |||
BigDecimal result = new BigDecimal(belowRank.getNumberValue()).add(rankDiff.multiply(new BigDecimal(pos / diff))); | |||
BigDecimal result = BigDecimal.valueOf(belowRank.getNumberValue()).add(rankDiff.multiply(BigDecimal.valueOf(pos / diff))); | |||
return new NumberEval(round(result, significance)); | |||
} | |||
@@ -685,7 +685,7 @@ public class DataFormatter { | |||
private static final Pattern endsWithCommas = Pattern.compile("(,+)$"); | |||
private final BigDecimal divider; | |||
private static final BigDecimal ONE_THOUSAND = new BigDecimal(1000); | |||
private static final BigDecimal ONE_THOUSAND = BigDecimal.valueOf(1000); | |||
private final DecimalFormat df; | |||
private static String trimTrailingCommas(String s) { | |||
return s.replaceAll(",+$", ""); |
@@ -411,7 +411,7 @@ public class DateUtil { | |||
return null; | |||
} | |||
BigDecimal bd = new BigDecimal(date); | |||
BigDecimal bd = BigDecimal.valueOf(date); | |||
int wholeDays = bd.intValue(); | |||
@@ -79,7 +79,7 @@ public class ExcelGeneralNumberFormat extends Format { | |||
// numeric characters, with the decimal point counting as a numeric | |||
// character". We know there is a decimal point, so limit to 10 digits. | |||
// https://support.microsoft.com/en-us/kb/65903 | |||
final double rounded = new BigDecimal(value).round(TO_10_SF).doubleValue(); | |||
final double rounded = BigDecimal.valueOf(value).round(TO_10_SF).doubleValue(); | |||
return decimalFormat.format(rounded, toAppendTo, pos); | |||
} | |||
@@ -107,7 +107,7 @@ public class FractionFormat extends Format { | |||
@SuppressWarnings("squid:S2111") | |||
public String format(Number num) { | |||
final BigDecimal doubleValue = new BigDecimal(num.doubleValue()); | |||
final BigDecimal doubleValue = BigDecimal.valueOf(num.doubleValue()); | |||
final boolean isNeg = doubleValue.compareTo(BigDecimal.ZERO) < 0; | |||
@@ -225,7 +225,7 @@ final class NormalisedDecimal { | |||
return _fractionalPart - other._fractionalPart; | |||
} | |||
public BigDecimal getFractionalPart() { | |||
return new BigDecimal(_fractionalPart).divide(BD_2_POW_24); | |||
return BigDecimal.valueOf(_fractionalPart).divide(BD_2_POW_24); | |||
} | |||
private String getFractionalDigits() { |