From 0f0c16f56dac633ae5337246ae9a67dc82f460b9 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 9 Nov 2014 17:53:10 +0000 Subject: [PATCH] Add some missing close() calls and fix some generics warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1637703 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ss/format/CellDateFormatter.java | 8 +++++-- .../poi/ss/format/CellElapsedFormatter.java | 6 +++++- .../poi/ss/format/CellGeneralFormatter.java | 6 +++++- .../poi/ss/format/CellNumberFormatter.java | 12 +++++++++-- .../org/apache/poi/util/BitFieldFactory.java | 4 ++-- src/java/org/apache/poi/util/DrawingDump.java | 21 +++++++++++-------- src/java/org/apache/poi/util/HexRead.java | 4 ++-- 7 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/poi/ss/format/CellDateFormatter.java b/src/java/org/apache/poi/ss/format/CellDateFormatter.java index e45fa267d..952b15c13 100644 --- a/src/java/org/apache/poi/ss/format/CellDateFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellDateFormatter.java @@ -183,8 +183,12 @@ public class CellDateFormatter extends CellFormatter { Date dateObj = (Date) value; int pos = toAppendTo.length(); Formatter formatter = new Formatter(toAppendTo); - long msecs = dateObj.getTime() % 1000; - formatter.format(LOCALE, sFmt, msecs / 1000.0); + try { + long msecs = dateObj.getTime() % 1000; + formatter.format(LOCALE, sFmt, msecs / 1000.0); + } finally { + formatter.close(); + } toAppendTo.delete(pos, pos + 2); doneMillis = true; } diff --git a/src/java/org/apache/poi/ss/format/CellElapsedFormatter.java b/src/java/org/apache/poi/ss/format/CellElapsedFormatter.java index 07ebadf2a..716ade906 100644 --- a/src/java/org/apache/poi/ss/format/CellElapsedFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellElapsedFormatter.java @@ -201,7 +201,11 @@ public class CellElapsedFormatter extends CellFormatter { } Formatter formatter = new Formatter(toAppendTo); - formatter.format(printfFmt, parts); + try { + formatter.format(printfFmt, parts); + } finally { + formatter.close(); + } } /** diff --git a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java index e00a54c90..8c067576f 100644 --- a/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellGeneralFormatter.java @@ -57,7 +57,11 @@ public class CellGeneralFormatter extends CellFormatter { } Formatter formatter = new Formatter(toAppendTo); - formatter.format(LOCALE, fmt, value); + try { + formatter.format(LOCALE, fmt, value); + } finally { + formatter.close(); + } if (stripZeros) { // strip off trailing zeros int removeFrom; diff --git a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java index 485d335e3..2ea72cc69 100644 --- a/src/java/org/apache/poi/ss/format/CellNumberFormatter.java +++ b/src/java/org/apache/poi/ss/format/CellNumberFormatter.java @@ -595,7 +595,11 @@ public class CellNumberFormatter extends CellFormatter { } else { StringBuffer result = new StringBuffer(); Formatter f = new Formatter(result); - f.format(LOCALE, printfFmt, value); + try { + f.format(LOCALE, printfFmt, value); + } finally { + f.close(); + } if (numerator == null) { writeFractional(result, output); @@ -866,7 +870,11 @@ public class CellNumberFormatter extends CellFormatter { StringBuffer sb = new StringBuffer(); Formatter formatter = new Formatter(sb); - formatter.format(LOCALE, fmt, num); + try { + formatter.format(LOCALE, fmt, num); + } finally { + formatter.close(); + } writeInteger(sb, output, numSpecials, mods, false); } diff --git a/src/java/org/apache/poi/util/BitFieldFactory.java b/src/java/org/apache/poi/util/BitFieldFactory.java index d022ee66c..4159074d7 100644 --- a/src/java/org/apache/poi/util/BitFieldFactory.java +++ b/src/java/org/apache/poi/util/BitFieldFactory.java @@ -27,10 +27,10 @@ import java.util.*; */ public class BitFieldFactory { - private static Map instances = new HashMap(); + private static Map instances = new HashMap(); public static BitField getInstance(int mask) { - BitField f = (BitField)instances.get(Integer.valueOf(mask)); + BitField f = instances.get(Integer.valueOf(mask)); if (f == null) { f = new BitField(mask); instances.put(Integer.valueOf(mask), f); diff --git a/src/java/org/apache/poi/util/DrawingDump.java b/src/java/org/apache/poi/util/DrawingDump.java index 3a9d656a9..1055ab2da 100644 --- a/src/java/org/apache/poi/util/DrawingDump.java +++ b/src/java/org/apache/poi/util/DrawingDump.java @@ -35,15 +35,18 @@ public class DrawingDump POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0])); HSSFWorkbook wb = new HSSFWorkbook(fs); - System.out.println( "Drawing group:" ); - wb.dumpDrawingGroupRecords(true); - - for (int sheetNum = 1; sheetNum <= wb.getNumberOfSheets(); sheetNum++) - { - System.out.println( "Sheet " + sheetNum + ":" ); - HSSFSheet sheet = wb.getSheetAt(sheetNum - 1); - sheet.dumpDrawingRecords(true); + try { + System.out.println( "Drawing group:" ); + wb.dumpDrawingGroupRecords(true); + + for (int sheetNum = 1; sheetNum <= wb.getNumberOfSheets(); sheetNum++) + { + System.out.println( "Sheet " + sheetNum + ":" ); + HSSFSheet sheet = wb.getSheetAt(sheetNum - 1); + sheet.dumpDrawingRecords(true); + } + } finally { + wb.close(); } - } } diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index fa7ecb5c4..51b0ceeb2 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -109,7 +109,7 @@ public class HexRead { int characterCount = 0; byte b = (byte) 0; - List bytes = new ArrayList(); + List bytes = new ArrayList(); boolean done = false; while ( !done ) { @@ -163,7 +163,7 @@ public class HexRead break; } } - Byte[] polished = (Byte[]) bytes.toArray( new Byte[0] ); + Byte[] polished = bytes.toArray( new Byte[0] ); byte[] rval = new byte[polished.length]; for ( int j = 0; j < polished.length; j++ ) {