From: Dominik Stadler Date: Sat, 16 May 2020 13:06:20 +0000 (+0000) Subject: Fix some IDE warnings, make lock-objects final, use generics, remove unused allocated... X-Git-Tag: before_ooxml_3rd_edition~264 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c61cd6fa03f519eb706e1e3efa3cdf742c5aae29;p=poi.git Fix some IDE warnings, make lock-objects final, use generics, remove unused allocated fields to reduce memory overhead of DocumentInputStream git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877818 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index fe98e4121e..11c6a911d0 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -379,8 +379,7 @@ public class PropertySet { * stream, else {@code false}. * @exception IOException if an I/O error occurs */ - public static boolean isPropertySetStream(final InputStream stream) - throws IOException { + public static boolean isPropertySetStream(final InputStream stream) throws IOException { /* * Read at most this many bytes. */ diff --git a/src/java/org/apache/poi/poifs/common/POIFSConstants.java b/src/java/org/apache/poi/poifs/common/POIFSConstants.java index 1cc5d038d6..7cacb68fe8 100644 --- a/src/java/org/apache/poi/poifs/common/POIFSConstants.java +++ b/src/java/org/apache/poi/poifs/common/POIFSConstants.java @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.poifs.common; @@ -25,43 +25,43 @@ package org.apache.poi.poifs.common; public interface POIFSConstants { /** Most files use 512 bytes as their big block size */ - public static final int SMALLER_BIG_BLOCK_SIZE = 0x0200; - public static final POIFSBigBlockSize SMALLER_BIG_BLOCK_SIZE_DETAILS = + int SMALLER_BIG_BLOCK_SIZE = 0x0200; + POIFSBigBlockSize SMALLER_BIG_BLOCK_SIZE_DETAILS = new POIFSBigBlockSize(SMALLER_BIG_BLOCK_SIZE, (short)9); /** Some use 4096 bytes */ - public static final int LARGER_BIG_BLOCK_SIZE = 0x1000; - public static final POIFSBigBlockSize LARGER_BIG_BLOCK_SIZE_DETAILS = + int LARGER_BIG_BLOCK_SIZE = 0x1000; + POIFSBigBlockSize LARGER_BIG_BLOCK_SIZE_DETAILS = new POIFSBigBlockSize(LARGER_BIG_BLOCK_SIZE, (short)12); - + /** How big a block in the small block stream is. Fixed size */ - public static final int SMALL_BLOCK_SIZE = 0x0040; - + int SMALL_BLOCK_SIZE = 0x0040; + /** How big a single property is */ - public static final int PROPERTY_SIZE = 0x0080; - - /** - * The minimum size of a document before it's stored using - * Big Blocks (normal streams). Smaller documents go in the + int PROPERTY_SIZE = 0x0080; + + /** + * The minimum size of a document before it's stored using + * Big Blocks (normal streams). Smaller documents go in the * Mini Stream (SBAT / Small Blocks) */ - public static final int BIG_BLOCK_MINIMUM_DOCUMENT_SIZE = 0x1000; - + int BIG_BLOCK_MINIMUM_DOCUMENT_SIZE = 0x1000; + /** The highest sector number you're allowed, 0xFFFFFFFA */ - public static final int LARGEST_REGULAR_SECTOR_NUMBER = -5; - + int LARGEST_REGULAR_SECTOR_NUMBER = -5; + /** Indicates the sector holds a DIFAT block (0xFFFFFFFC) */ - public static final int DIFAT_SECTOR_BLOCK = -4; + int DIFAT_SECTOR_BLOCK = -4; /** Indicates the sector holds a FAT block (0xFFFFFFFD) */ - public static final int FAT_SECTOR_BLOCK = -3; + int FAT_SECTOR_BLOCK = -3; /** Indicates the sector is the end of a chain (0xFFFFFFFE) */ - public static final int END_OF_CHAIN = -2; + int END_OF_CHAIN = -2; /** Indicates the sector is not used (0xFFFFFFFF) */ - public static final int UNUSED_BLOCK = -1; - + int UNUSED_BLOCK = -1; + /** The first 4 bytes of an OOXML file, used in detection */ - public static final byte[] OOXML_FILE_HEADER = + byte[] OOXML_FILE_HEADER = new byte[] { 0x50, 0x4b, 0x03, 0x04 }; /** The first 5 bytes of a raw XML file, used in detection */ - public static final byte[] RAW_XML_FILE_HEADER = + byte[] RAW_XML_FILE_HEADER = new byte[] { 0x3c, 0x3f, 0x78, 0x6d, 0x6c }; } // end public interface POIFSConstants; diff --git a/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java b/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java index 26769a94ea..bf07261ef9 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java +++ b/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java @@ -36,11 +36,6 @@ import org.apache.poi.util.LittleEndianInput; * {@link POIFSFileSystem} instance. */ public final class DocumentInputStream extends InputStream implements LittleEndianInput { - - private static int SKIP_BUFFER_SIZE = 2048; - - private static byte[] SKIP_BYTE_BUFFER = new byte[SKIP_BUFFER_SIZE]; - /** returned by read operations if we're at end of document */ private static final int EOF = -1; diff --git a/src/java/org/apache/poi/ss/formula/functions/DateValue.java b/src/java/org/apache/poi/ss/formula/functions/DateValue.java index f513237abe..ea62ee156d 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DateValue.java +++ b/src/java/org/apache/poi/ss/formula/functions/DateValue.java @@ -101,10 +101,10 @@ public class DateValue extends Fixed1ArgFunction { groups.add(matchResult.group(i)); } int year = format.hasYear - ? Integer.valueOf(groups.get(format.yearIndex)) + ? Integer.parseInt(groups.get(format.yearIndex)) : LocalDate.now(LocaleUtil.getUserTimeZone().toZoneId()).getYear(); int month = parseMonth(groups.get(format.monthIndex)); - int day = Integer.valueOf(groups.get(format.dayIndex)); + int day = Integer.parseInt(groups.get(format.dayIndex)); return new NumberEval(DateUtil.getExcelDate(LocalDate.of(year, month, day))); } @@ -120,7 +120,7 @@ public class DateValue extends Fixed1ArgFunction { private int parseMonth(String monthPart) { try { - return Integer.valueOf(monthPart); + return Integer.parseInt(monthPart); } catch (NumberFormatException ignored) { } diff --git a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java index 450d21232c..ad5a8446ea 100644 --- a/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java +++ b/src/java/org/apache/poi/ss/usermodel/WorkbookFactory.java @@ -53,8 +53,9 @@ public abstract class WorkbookFactory { Workbook apply(T t, U u) throws IOException; } - private static Object hssfLock = new Object(); - private static Object xssfLock = new Object(); + private static final Object hssfLock = new Object(); + private static final Object xssfLock = new Object(); + protected static CreateWorkbook0 createHssfFromScratch; protected static CreateWorkbook1 createHssfByNode; @@ -338,7 +339,7 @@ public abstract class WorkbookFactory { synchronized (xssfLock) { if (createXssfFromScratch == null) { String factoryClass = "org.apache.poi.xssf.usermodel.XSSFWorkbookFactory"; - Class cls = initFactory(factoryClass, "poi-ooxml-*.jar"); + Class cls = initFactory(factoryClass, "poi-ooxml-*.jar"); try { cls.getMethod("init").invoke(null); } catch (Exception e) { @@ -355,7 +356,7 @@ public abstract class WorkbookFactory { synchronized (hssfLock) { if (createHssfFromScratch == null) { String factoryClass = "org.apache.poi.hssf.usermodel.HSSFWorkbookFactory"; - Class cls = initFactory(factoryClass, "poi-*.jar"); + Class cls = initFactory(factoryClass, "poi-*.jar"); try { cls.getMethod("init").invoke(null); } catch (Exception e) { @@ -366,7 +367,7 @@ public abstract class WorkbookFactory { } } - private static Class initFactory(String factoryClass, String jar) throws IOException { + private static Class initFactory(String factoryClass, String jar) throws IOException { try { return Class.forName(factoryClass, true, WorkbookFactory.class.getClassLoader()); } catch (ClassNotFoundException e) {