KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 /**
24  * Title: Double Stream Flag Record<P>
25  * Description: tells if this is a double stream file. (always no for HSSF generated files)<P>
26  * Double Stream files contain both BIFF8 and BIFF7 workbooks.<P>
27  * REFERENCE: PG 305 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  * @author Andrew C. Oliver (acoliver at apache dot org)
29  * @version 2.0-pre
30  */

31
32 public class DSFRecord
33     extends Record
34 {
35     public final static short sid = 0x161;
36     private short field_1_dsf;
37
38     public DSFRecord()
39     {
40     }
41
42     /**
43      * Constructs a DBCellRecord and sets its fields appropriately.
44      *
45      * @param id id must be 0x161 or an exception will be throw upon validation
46      * @param size the size of the data area of the record
47      * @param data data of the record (should not contain sid/len)
48      */

49
50     public DSFRecord(short id, short size, byte [] data)
51     {
52         super(id, size, data);
53     }
54
55     /**
56      * Constructs a DBCellRecord and sets its fields appropriately.
57      *
58      * @param id id must be 0x161 or an exception will be throw upon validation
59      * @param size the size of the data area of the record
60      * @param data data of the record (should not contain sid/len)
61      * @param offset of the record's data
62      */

63
64     public DSFRecord(short id, short size, byte [] data, int offset)
65     {
66         super(id, size, data, offset);
67     }
68
69     protected void validateSid(short id)
70     {
71         if (id != sid)
72         {
73             throw new RecordFormatException("NOT A DSF RECORD");
74         }
75     }
76
77     protected void fillFields(byte [] data, short size, int offset)
78     {
79         field_1_dsf = LittleEndian.getShort(data, 0 + offset);
80     }
81
82     /**
83      * set the DSF flag
84      * @param dsfflag (0-off,1-on)
85      */

86
87     public void setDsf(short dsfflag)
88     {
89         field_1_dsf = dsfflag;
90     }
91
92     /**
93      * get the DSF flag
94      * @return dsfflag (0-off,1-on)
95      */

96
97     public short getDsf()
98     {
99         return field_1_dsf;
100     }
101
102     public String JavaDoc toString()
103     {
104         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
105
106         buffer.append("[DSF]\n");
107         buffer.append(" .isDSF = ")
108             .append(Integer.toHexString(getDsf())).append("\n");
109         buffer.append("[/DSF]\n");
110         return buffer.toString();
111     }
112
113     public int serialize(int offset, byte [] data)
114     {
115         LittleEndian.putShort(data, 0 + offset, sid);
116         LittleEndian.putShort(data, 2 + offset,
117                               (( short ) 0x02)); // 2 bytes (6 total)
118
LittleEndian.putShort(data, 4 + offset, getDsf());
119         return getRecordSize();
120     }
121
122     public int getRecordSize()
123     {
124         return 6;
125     }
126
127     public short getSid()
128     {
129         return this.sid;
130     }
131 }
132
Popular Tags