mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
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
This commit is contained in:
parent
eb497bac79
commit
c61cd6fa03
@ -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.
|
||||
*/
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
|
||||
|
||||
@ -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<DirectoryNode> 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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user