KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > SSTRecordHeader


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22 import org.apache.poi.util.LittleEndianConsts;
23
24 /**
25  * Write out an SST header record.
26  *
27  * @author Glen Stampoultzis (glens at apache.org)
28  */

29 class SSTRecordHeader
30 {
31     int numStrings;
32     int numUniqueStrings;
33
34     public SSTRecordHeader( int numStrings, int numUniqueStrings )
35     {
36         this.numStrings = numStrings;
37         this.numUniqueStrings = numUniqueStrings;
38     }
39
40     /**
41      * Writes out the SST record. This consists of the sid, the record size, the number of
42      * strings and the number of unique strings.
43      *
44      * @param data The data buffer to write the header to.
45      * @param bufferIndex The index into the data buffer where the header should be written.
46      * @param recSize The number of records written.
47      *
48      * @return The bufer of bytes modified.
49      */

50     public int writeSSTHeader( byte[] data, int bufferIndex, int recSize )
51     {
52         int offset = bufferIndex;
53
54         LittleEndian.putShort( data, offset, SSTRecord.sid );
55         offset += LittleEndianConsts.SHORT_SIZE;
56         LittleEndian.putShort( data, offset, (short) ( recSize ) );
57         offset += LittleEndianConsts.SHORT_SIZE;
58 // LittleEndian.putInt( data, offset, getNumStrings() );
59
LittleEndian.putInt( data, offset, numStrings );
60         offset += LittleEndianConsts.INT_SIZE;
61 // LittleEndian.putInt( data, offset, getNumUniqueStrings() );
62
LittleEndian.putInt( data, offset, numUniqueStrings );
63         offset += LittleEndianConsts.INT_SIZE;
64         return offset - bufferIndex;
65     }
66
67 }
68
Popular Tags