Fields Summary |
---|
private static UnicodeString | EMPTY_STRING |
static final int | MAX_RECORD_SIZEhow big can an SST record be? As big as any record can be: 8228 bytes |
static final int | STD_RECORD_OVERHEADstandard record overhead: two shorts (record id plus data space size) |
static final int | SST_RECORD_OVERHEADSST overhead: the standard record overhead, plus the number of strings and the number of unique strings -- two ints |
static final int | MAX_DATA_SPACEhow much data can we stuff into an SST record? That would be _max minus the standard SST record overhead |
static final int | STRING_MINIMAL_OVERHEADoverhead for each string includes the string's character count (a short) and the flag describing its characteristics (a byte) |
public static final short | sid |
private int | field_1_num_stringsunion of strings in the SST and EXTSST |
private int | field_2_num_unique_stringsaccording to docs ONLY SST |
private IntMapper | field_3_strings |
private SSTDeserializer | deserializer |
int[] | bucketAbsoluteOffsetsOffsets from the beginning of the SST record (even across continuations) |
int[] | bucketRelativeOffsetsOffsets relative the start of the current SST or continue record |
Methods Summary |
---|
public int | addString(org.apache.poi.hssf.record.UnicodeString string)Add a string.
field_1_num_strings++;
UnicodeString ucs = ( string == null ) ? EMPTY_STRING
: string;
int rval;
int index = field_3_strings.getIndex(ucs);
if ( index != -1 )
{
rval = index;
}
else
{
// This is a new string -- we didn't see it among the
// strings we've already collected
rval = field_3_strings.size();
field_2_num_unique_strings++;
SSTDeserializer.addToStringTable( field_3_strings, ucs );
}
return rval;
|
public int | calcExtSSTRecordSize()Calculates the size in bytes of the EXTSST record as it would be if the
record was serialized.
return ExtSSTRecord.getRecordSizeForStrings(field_3_strings.size());
|
int | countStrings()
return field_3_strings.size();
|
public org.apache.poi.hssf.record.ExtSSTRecord | createExtSSTRecord(int sstOffset)Creates an extended string record based on the current contents of
the current SST record. The offset within the stream to the SST record
is required because the extended string record points directly to the
strings in the SST record.
NOTE: THIS FUNCTION MUST ONLY BE CALLED AFTER THE SST RECORD HAS BEEN
SERIALIZED.
if (bucketAbsoluteOffsets == null || bucketAbsoluteOffsets == null)
throw new IllegalStateException("SST record has not yet been serialized.");
ExtSSTRecord extSST = new ExtSSTRecord();
extSST.setNumStringsPerBucket((short)8);
int[] absoluteOffsets = (int[]) bucketAbsoluteOffsets.clone();
int[] relativeOffsets = (int[]) bucketRelativeOffsets.clone();
for ( int i = 0; i < absoluteOffsets.length; i++ )
absoluteOffsets[i] += sstOffset;
extSST.setBucketOffsets(absoluteOffsets, relativeOffsets);
return extSST;
|
public boolean | equals(java.lang.Object o)
if ( ( o == null ) || ( o.getClass() != this.getClass() ) )
{
return false;
}
SSTRecord other = (SSTRecord) o;
return ( ( field_1_num_strings == other
.field_1_num_strings ) && ( field_2_num_unique_strings == other
.field_2_num_unique_strings ) && field_3_strings
.equals( other.field_3_strings ) );
|
protected void | fillFields(org.apache.poi.hssf.record.RecordInputStream in)Fill the fields from the data
The data consists of sets of string data. This string data is
arranged as follows:
short string_length; // length of string data
byte string_flag; // flag specifying special string
// handling
short run_count; // optional count of formatting runs
int extend_length; // optional extension length
char[] string_data; // string data, can be byte[] or
// short[] (length of array is
// string_length)
int[] formatting_runs; // optional formatting runs (length of
// array is run_count)
byte[] extension; // optional extension (length of array
// is extend_length)
The string_flag is bit mapped as follows:
Bit number |
Meaning if 0 |
Meaning if 1 |
0 |
string_data is byte[] |
string_data is short[]
|
1 |
Should always be 0 |
string_flag is defective
|
2 |
extension is not included |
extension is included
|
3 |
formatting run data is not included |
formatting run data is included
|
4 |
Should always be 0 |
string_flag is defective
|
5 |
Should always be 0 |
string_flag is defective
|
6 |
Should always be 0 |
string_flag is defective
|
7 |
Should always be 0 |
string_flag is defective
|
We can handle eating the overhead associated with bits 2 or 3
(or both) being set, but we have no idea what to do with the
associated data. The UnicodeString class can handle the byte[]
vs short[] nature of the actual string data
// this method is ALWAYS called after construction -- using
// the nontrivial constructor, of course -- so this is where
// we initialize our fields
field_1_num_strings = in.readInt();
field_2_num_unique_strings = in.readInt();
field_3_strings = new IntMapper();
deserializer = new SSTDeserializer(field_3_strings);
deserializer.manufactureStrings( field_2_num_unique_strings, in );
|
org.apache.poi.hssf.record.SSTDeserializer | getDeserializer()
return deserializer;
|
public int | getNumStrings()
return field_1_num_strings;
|
public int | getNumUniqueStrings()
return field_2_num_unique_strings;
|
public int | getRecordSize()
SSTRecordSizeCalculator calculator = new SSTRecordSizeCalculator(field_3_strings);
int recordSize = calculator.getRecordSize();
return recordSize;
|
public short | getSid()
return sid;
|
public org.apache.poi.hssf.record.UnicodeString | getString(int id)Get a particular string by its index
return (UnicodeString) field_3_strings.get( id );
|
java.util.Iterator | getStrings()
return field_3_strings.iterator();
|
public int | hashCode()
return field_2_num_unique_strings;
|
public boolean | isString16bit(int id)
UnicodeString unicodeString = ( (UnicodeString) field_3_strings.get( id ) );
return ( ( unicodeString.getOptionFlags() & 0x01 ) == 1 );
|
public int | serialize(int offset, byte[] data)called by the class that is responsible for writing this sucker.
Subclasses should implement this so that their data is passed back in a
byte array.
SSTSerializer serializer = new SSTSerializer(
field_3_strings, getNumStrings(), getNumUniqueStrings() );
int bytes = serializer.serialize( offset, data );
bucketAbsoluteOffsets = serializer.getBucketAbsoluteOffsets();
bucketRelativeOffsets = serializer.getBucketRelativeOffsets();
return bytes;
|
public void | setNumStrings(int count)USE THIS METHOD AT YOUR OWN PERIL: THE addString
METHODS MANIPULATE THE NUMBER OF STRINGS AS A SIDE EFFECT; YOUR
ATTEMPTS AT MANIPULATING THE STRING COUNT IS LIKELY TO BE VERY
WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN THIS RECORD IS
WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ THE RECORD
field_1_num_strings = count;
|
public void | setNumUniqueStrings(int count)USE THIS METHOD AT YOUR OWN PERIL: THE addString
METHODS MANIPULATE THE NUMBER OF UNIQUE STRINGS AS A SIDE
EFFECT; YOUR ATTEMPTS AT MANIPULATING THE UNIQUE STRING COUNT
IS LIKELY TO BE VERY WRONG AND WILL RESULT IN BAD BEHAVIOR WHEN
THIS RECORD IS WRITTEN OUT AND ANOTHER PROCESS ATTEMPTS TO READ
THE RECORD
field_2_num_unique_strings = count;
|
public java.lang.String | toString()Return a debugging string representation
StringBuffer buffer = new StringBuffer();
buffer.append( "[SST]\n" );
buffer.append( " .numstrings = " )
.append( Integer.toHexString( getNumStrings() ) ).append( "\n" );
buffer.append( " .uniquestrings = " )
.append( Integer.toHexString( getNumUniqueStrings() ) ).append( "\n" );
for ( int k = 0; k < field_3_strings.size(); k++ )
{
UnicodeString s = (UnicodeString)field_3_strings.get( k );
buffer.append( " .string_" + k + " = " )
.append( s.getDebugInfo() ).append( "\n" );
}
buffer.append( "[/SST]\n" );
return buffer.toString();
|
protected void | validateSid(short id)validate SID
if ( id != sid )
{
throw new RecordFormatException( "NOT An SST RECORD" );
}
|