#62355 - unsplit packages - 4 - open HPSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1832361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-05-27 22:15:59 +00:00
parent e2ec4ebe95
commit 09fa9890a6
15 changed files with 63 additions and 81 deletions

View File

@ -20,7 +20,7 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class Array public class Array
{ {
static class ArrayDimension { static class ArrayDimension {
private long _size; private long _size;
@ -74,9 +74,7 @@ class Array
private final ArrayHeader _header = new ArrayHeader(); private final ArrayHeader _header = new ArrayHeader();
private TypedPropertyValue[] _values; private TypedPropertyValue[] _values;
Array() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
_header.read(lei); _header.read(lei);
long numberOfScalarsLong = _header.getNumberOfScalarValues(); long numberOfScalarsLong = _header.getNumberOfScalarValues();
@ -100,7 +98,7 @@ class Array
} }
} }
TypedPropertyValue[] getValues(){ public TypedPropertyValue[] getValues(){
return _values; return _values;
} }
} }

View File

@ -21,16 +21,14 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianInput; import org.apache.poi.util.LittleEndianInput;
@Internal @Internal
class Blob { public class Blob {
//arbitrarily selected; may need to increase //arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 1_000_000; private static final int MAX_RECORD_LENGTH = 1_000_000;
private byte[] _value; private byte[] _value;
Blob() {} public void read( LittleEndianInput lei ) {
void read( LittleEndianInput lei ) {
int size = lei.readInt(); int size = lei.readInt();
_value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); _value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
if ( size > 0 ) { if ( size > 0 ) {

View File

@ -25,7 +25,7 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@Internal @Internal
class ClipboardData { public class ClipboardData {
//arbitrarily selected; may need to increase //arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000_000; private static final int MAX_RECORD_LENGTH = 100_000_000;
@ -34,9 +34,7 @@ class ClipboardData {
private int _format; private int _format;
private byte[] _value; private byte[] _value;
ClipboardData() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
int offset = lei.getReadIndex(); int offset = lei.getReadIndex();
int size = lei.readInt(); int size = lei.readInt();
@ -55,11 +53,11 @@ class ClipboardData {
lei.readFully(_value); lei.readFully(_value);
} }
byte[] getValue() { public byte[] getValue() {
return _value; return _value;
} }
byte[] toByteArray() { public byte[] toByteArray() {
byte[] result = new byte[LittleEndianConsts.INT_SIZE*2+_value.length]; byte[] result = new byte[LittleEndianConsts.INT_SIZE*2+_value.length];
LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result,0); LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(result,0);
try { try {
@ -72,7 +70,7 @@ class ClipboardData {
} }
} }
void setValue( byte[] value ) { public void setValue( byte[] value ) {
_value = value.clone(); _value = value.clone();
} }
} }

View File

@ -30,7 +30,7 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@Internal @Internal
class CodePageString { public class CodePageString {
//arbitrarily selected; may need to increase //arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000; private static final int MAX_RECORD_LENGTH = 100_000;
@ -39,9 +39,7 @@ class CodePageString {
private byte[] _value; private byte[] _value;
CodePageString() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
int offset = lei.getReadIndex(); int offset = lei.getReadIndex();
int size = lei.readInt(); int size = lei.readInt();
_value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); _value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
@ -70,7 +68,7 @@ class CodePageString {
TypedPropertyValue.skipPadding(lei); TypedPropertyValue.skipPadding(lei);
} }
String getJavaValue( int codepage ) throws UnsupportedEncodingException { public String getJavaValue( int codepage ) throws UnsupportedEncodingException {
int cp = ( codepage == -1 ) ? Property.DEFAULT_CODEPAGE : codepage; int cp = ( codepage == -1 ) ? Property.DEFAULT_CODEPAGE : codepage;
String result = CodePageUtil.getStringFromCodePage(_value, cp); String result = CodePageUtil.getStringFromCodePage(_value, cp);
@ -92,16 +90,16 @@ class CodePageString {
return result.substring( 0, terminator ); return result.substring( 0, terminator );
} }
int getSize() { public int getSize() {
return LittleEndianConsts.INT_SIZE + _value.length; return LittleEndianConsts.INT_SIZE + _value.length;
} }
void setJavaValue( String string, int codepage ) throws UnsupportedEncodingException { public void setJavaValue( String string, int codepage ) throws UnsupportedEncodingException {
int cp = ( codepage == -1 ) ? Property.DEFAULT_CODEPAGE : codepage; int cp = ( codepage == -1 ) ? Property.DEFAULT_CODEPAGE : codepage;
_value = CodePageUtil.getBytesInCodePage(string + "\0", cp); _value = CodePageUtil.getBytesInCodePage(string + "\0", cp);
} }
int write( OutputStream out ) throws IOException { public int write( OutputStream out ) throws IOException {
LittleEndian.putUInt( _value.length, out ); LittleEndian.putUInt( _value.length, out );
out.write( _value ); out.write( _value );
return LittleEndianConsts.INT_SIZE + _value.length; return LittleEndianConsts.INT_SIZE + _value.length;

View File

@ -20,14 +20,12 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class Currency { public class Currency {
private static final int SIZE = 8; private static final int SIZE = 8;
private final byte[] _value = new byte[SIZE]; private final byte[] _value = new byte[SIZE];
Currency() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
lei.readFully(_value); lei.readFully(_value);
} }
} }

View File

@ -20,14 +20,12 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class Date { public class Date {
private static final int SIZE = 8; private static final int SIZE = 8;
private final byte[] _value = new byte[SIZE]; private final byte[] _value = new byte[SIZE];
Date() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
lei.readFully(_value); lei.readFully(_value);
} }
} }

View File

@ -20,7 +20,7 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class Decimal { public class Decimal {
/** /**
* Findbugs: UNR_UNREAD_FIELD * Findbugs: UNR_UNREAD_FIELD
*/ */
@ -30,9 +30,7 @@ class Decimal {
private int field_4_hi32; private int field_4_hi32;
private long field_5_lo64; private long field_5_lo64;
Decimal() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
field_1_wReserved = lei.readShort(); field_1_wReserved = lei.readShort();
field_2_scale = lei.readByte(); field_2_scale = lei.readByte();
field_3_sign = lei.readByte(); field_3_sign = lei.readByte();

View File

@ -20,10 +20,12 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date; import java.util.Date;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
@Internal
public class Filetime { public class Filetime {
/** /**
* The difference between the Windows epoch (1601-01-01 * The difference between the Windows epoch (1601-01-01
@ -39,47 +41,47 @@ public class Filetime {
private int _dwHighDateTime; private int _dwHighDateTime;
private int _dwLowDateTime; private int _dwLowDateTime;
Filetime() {} public Filetime() {}
Filetime( int low, int high ) { public Filetime( int low, int high ) {
_dwLowDateTime = low; _dwLowDateTime = low;
_dwHighDateTime = high; _dwHighDateTime = high;
} }
Filetime( Date date ) { public Filetime( Date date ) {
long filetime = Filetime.dateToFileTime(date); long filetime = Filetime.dateToFileTime(date);
_dwHighDateTime = (int) ((filetime >>> 32) & UINT_MASK); _dwHighDateTime = (int) ((filetime >>> 32) & UINT_MASK);
_dwLowDateTime = (int) (filetime & UINT_MASK); _dwLowDateTime = (int) (filetime & UINT_MASK);
} }
void read( LittleEndianByteArrayInputStream lei ) { public void read( LittleEndianByteArrayInputStream lei ) {
_dwLowDateTime = lei.readInt(); _dwLowDateTime = lei.readInt();
_dwHighDateTime = lei.readInt(); _dwHighDateTime = lei.readInt();
} }
long getHigh() { public long getHigh() {
return _dwHighDateTime; return _dwHighDateTime;
} }
long getLow() { public long getLow() {
return _dwLowDateTime; return _dwLowDateTime;
} }
byte[] toByteArray() { public byte[] toByteArray() {
byte[] result = new byte[SIZE]; byte[] result = new byte[SIZE];
LittleEndian.putInt( result, 0 * LittleEndianConsts.INT_SIZE, _dwLowDateTime ); LittleEndian.putInt( result, 0 * LittleEndianConsts.INT_SIZE, _dwLowDateTime );
LittleEndian.putInt( result, 1 * LittleEndianConsts.INT_SIZE, _dwHighDateTime ); LittleEndian.putInt( result, 1 * LittleEndianConsts.INT_SIZE, _dwHighDateTime );
return result; return result;
} }
int write( OutputStream out ) throws IOException { public int write( OutputStream out ) throws IOException {
LittleEndian.putInt( _dwLowDateTime, out ); LittleEndian.putInt( _dwLowDateTime, out );
LittleEndian.putInt( _dwHighDateTime, out ); LittleEndian.putInt( _dwHighDateTime, out );
return SIZE; return SIZE;
} }
Date getJavaValue() { public Date getJavaValue() {
long l = (((long)_dwHighDateTime) << 32) | (_dwLowDateTime & UINT_MASK); long l = (((long)_dwHighDateTime) << 32) | (_dwLowDateTime & UINT_MASK);
return filetimeToDate( l ); return filetimeToDate( l );
} }

View File

@ -20,15 +20,13 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class GUID { public class GUID {
private int _data1; private int _data1;
private short _data2; private short _data2;
private short _data3; private short _data3;
private long _data4; private long _data4;
GUID() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
_data1 = lei.readInt(); _data1 = lei.readInt();
_data2 = lei.readShort(); _data2 = lei.readShort();
_data3 = lei.readShort(); _data3 = lei.readShort();

View File

@ -19,6 +19,6 @@ package org.apache.poi.hpsf;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
@Internal @Internal
class IndirectPropertyName extends CodePageString { public class IndirectPropertyName extends CodePageString {
IndirectPropertyName() {} IndirectPropertyName() {}
} }

View File

@ -27,22 +27,22 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@Internal @Internal
class TypedPropertyValue { public class TypedPropertyValue {
private static final POILogger LOG = POILogFactory.getLogger( TypedPropertyValue.class ); private static final POILogger LOG = POILogFactory.getLogger( TypedPropertyValue.class );
private int _type; private int _type;
private Object _value; private Object _value;
TypedPropertyValue( int type, Object value ) { public TypedPropertyValue( int type, Object value ) {
_type = type; _type = type;
_value = value; _value = value;
} }
Object getValue() { public Object getValue() {
return _value; return _value;
} }
void read( LittleEndianByteArrayInputStream lei ) { public void read( LittleEndianByteArrayInputStream lei ) {
_type = lei.readShort(); _type = lei.readShort();
short padding = lei.readShort(); short padding = lei.readShort();
if ( padding != 0 ) { if ( padding != 0 ) {
@ -52,7 +52,7 @@ class TypedPropertyValue {
readValue( lei ); readValue( lei );
} }
void readValue( LittleEndianByteArrayInputStream lei ) { public void readValue( LittleEndianByteArrayInputStream lei ) {
switch ( _type ) { switch ( _type ) {
case Variant.VT_EMPTY: case Variant.VT_EMPTY:
case Variant.VT_NULL: case Variant.VT_NULL:

View File

@ -31,16 +31,14 @@ import org.apache.poi.util.POILogger;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
@Internal @Internal
class UnicodeString { public class UnicodeString {
private static final POILogger LOG = POILogFactory.getLogger( UnicodeString.class ); private static final POILogger LOG = POILogFactory.getLogger( UnicodeString.class );
//arbitrarily selected; may need to increase //arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000; private static final int MAX_RECORD_LENGTH = 100_000;
private byte[] _value; private byte[] _value;
UnicodeString() {} public void read(LittleEndianByteArrayInputStream lei) {
void read(LittleEndianByteArrayInputStream lei) {
final int length = lei.readInt(); final int length = lei.readInt();
final int unicodeBytes = length*2; final int unicodeBytes = length*2;
_value = IOUtils.safelyAllocate(unicodeBytes, MAX_RECORD_LENGTH); _value = IOUtils.safelyAllocate(unicodeBytes, MAX_RECORD_LENGTH);
@ -66,11 +64,11 @@ class UnicodeString {
TypedPropertyValue.skipPadding(lei); TypedPropertyValue.skipPadding(lei);
} }
byte[] getValue() { public byte[] getValue() {
return _value; return _value;
} }
String toJavaString() { public String toJavaString() {
if ( _value.length == 0 ) { if ( _value.length == 0 ) {
return null; return null;
} }
@ -95,11 +93,11 @@ class UnicodeString {
return result.substring( 0, terminator ); return result.substring( 0, terminator );
} }
void setJavaValue( String string ) throws UnsupportedEncodingException { public void setJavaValue( String string ) throws UnsupportedEncodingException {
_value = CodePageUtil.getBytesInCodePage(string + "\0", CodePageUtil.CP_UNICODE); _value = CodePageUtil.getBytesInCodePage(string + "\0", CodePageUtil.CP_UNICODE);
} }
int write( OutputStream out ) throws IOException { public int write( OutputStream out ) throws IOException {
LittleEndian.putUInt( _value.length / 2, out ); LittleEndian.putUInt( _value.length / 2, out );
out.write( _value ); out.write( _value );
return LittleEndianConsts.INT_SIZE + _value.length; return LittleEndianConsts.INT_SIZE + _value.length;

View File

@ -22,16 +22,14 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@Internal @Internal
class VariantBool { public class VariantBool {
private final static POILogger LOG = POILogFactory.getLogger( VariantBool.class ); private final static POILogger LOG = POILogFactory.getLogger( VariantBool.class );
static final int SIZE = 2; static final int SIZE = 2;
private boolean _value; private boolean _value;
VariantBool() {} public void read( LittleEndianByteArrayInputStream lei ) {
void read( LittleEndianByteArrayInputStream lei ) {
short value = lei.readShort(); short value = lei.readShort();
switch (value) { switch (value) {
case 0: case 0:
@ -47,11 +45,11 @@ class VariantBool {
} }
} }
boolean getValue() { public boolean getValue() {
return _value; return _value;
} }
void setValue( boolean value ) { public void setValue( boolean value ) {
this._value = value; this._value = value;
} }
} }

View File

@ -26,16 +26,16 @@ import org.apache.poi.util.LittleEndianByteArrayInputStream;
* Holder for vector-type properties * Holder for vector-type properties
*/ */
@Internal @Internal
class Vector { public class Vector {
private final short _type; private final short _type;
private TypedPropertyValue[] _values; private TypedPropertyValue[] _values;
Vector( short type ) { public Vector( short type ) {
this._type = type; this._type = type;
} }
void read( LittleEndianByteArrayInputStream lei ) { public void read( LittleEndianByteArrayInputStream lei ) {
final long longLength = lei.readUInt(); final long longLength = lei.readUInt();
if ( longLength > Integer.MAX_VALUE ) { if ( longLength > Integer.MAX_VALUE ) {
@ -61,7 +61,7 @@ class Vector {
_values = values.toArray(new TypedPropertyValue[values.size()]); _values = values.toArray(new TypedPropertyValue[values.size()]);
} }
TypedPropertyValue[] getValues(){ public TypedPropertyValue[] getValues(){
return _values; return _values;
} }
} }

View File

@ -22,14 +22,14 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndianByteArrayInputStream; import org.apache.poi.util.LittleEndianByteArrayInputStream;
@Internal @Internal
class VersionedStream public class VersionedStream
{ {
private final GUID _versionGuid = new GUID(); private final GUID _versionGuid = new GUID();
private final IndirectPropertyName _streamName = new IndirectPropertyName(); private final IndirectPropertyName _streamName = new IndirectPropertyName();
VersionedStream() {} public VersionedStream() {}
void read( LittleEndianByteArrayInputStream lei ) { public void read( LittleEndianByteArrayInputStream lei ) {
_versionGuid.read(lei); _versionGuid.read(lei);
_streamName.read(lei); _streamName.read(lei);
} }