/* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ package org.apache.poi.hssf.record; import java.util.Iterator; import org.apache.poi.hssf.record.common.UnicodeString; import org.apache.poi.hssf.record.cont.ContinuableRecord; import org.apache.poi.hssf.record.cont.ContinuableRecordOutput; import org.apache.poi.util.IntMapper; import org.apache.poi.util.LittleEndianConsts; /** * Title: Static String Table Record (0x00FC)
* * Description: This holds all the strings for LabelSSTRecords.
*
* REFERENCE: PG 389 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
*
* @see org.apache.poi.hssf.record.LabelSSTRecord
* @see org.apache.poi.hssf.record.ContinueRecord
*/
public final class SSTRecord extends ContinuableRecord {
public static final short sid = 0x00FC;
private static final UnicodeString EMPTY_STRING = new UnicodeString("");
// TODO - move these constants to test class (the only consumer)
/** standard record overhead: two shorts (record id plus data space size)*/
static final int STD_RECORD_OVERHEAD = 2 * LittleEndianConsts.SHORT_SIZE;
/** SST overhead: the standard record overhead, plus the number of strings and the number of unique strings -- two ints */
static final int SST_RECORD_OVERHEAD = STD_RECORD_OVERHEAD + 2 * LittleEndianConsts.INT_SIZE;
/** how much data can we stuff into an SST record? That would be _max minus the standard SST record overhead */
static final int MAX_DATA_SPACE = RecordInputStream.MAX_RECORD_DATA_SIZE - 8;
/** union of strings in the SST and EXTSST */
private int field_1_num_strings;
/** according to docs ONLY SST */
private int field_2_num_unique_strings;
private IntMapper
* The data consists of sets of string data. This string data is
* arranged as follows:
*
*
* The string_flag is bit mapped as follows:
*
*
* 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
*
* @param in the RecordInputstream to read the record from
*/
public SSTRecord(RecordInputStream in) {
// 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
* NOTE: THIS FUNCTION MUST ONLY BE CALLED AFTER THE SST RECORD HAS BEEN
* SERIALIZED.
*
* @param sstOffset The offset in the stream to the start of the
* SST record.
* @return The new SST record.
*/
public ExtSSTRecord createExtSSTRecord(int sstOffset) {
if (bucketAbsoluteOffsets == null || bucketRelativeOffsets == null) {
throw new IllegalStateException("SST record has not yet been serialized.");
}
ExtSSTRecord extSST = new ExtSSTRecord();
extSST.setNumStringsPerBucket((short)8);
int[] absoluteOffsets = bucketAbsoluteOffsets.clone();
int[] relativeOffsets = bucketRelativeOffsets.clone();
for ( int i = 0; i < absoluteOffsets.length; i++ ) {
absoluteOffsets[i] += sstOffset;
}
extSST.setBucketOffsets(absoluteOffsets, relativeOffsets);
return extSST;
}
/**
* Calculates the size in bytes of the EXTSST record as it would be if the
* record was serialized.
*
* @return The size of the ExtSST record in bytes.
*/
public int calcExtSSTRecordSize() {
return ExtSSTRecord.getRecordSizeForStrings(field_3_strings.size());
}
}
* 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)
*
*
*
*
* 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
*
*