KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.apache.poi.hssf.record;
21
22
23
24 import org.apache.poi.util.*;
25
26 /**
27  * The group marker record is used as a position holder for groups.
28
29  * @author Glen Stampoultzis (glens at apache.org)
30  */

31 public class GroupMarkerSubRecord
32     extends SubRecord
33 {
34     public final static short sid = 0x06;
35
36     private byte[] reserved = new byte[0]; // would really love to know what goes in here.
37

38     public GroupMarkerSubRecord()
39     {
40
41     }
42
43     /**
44      * Constructs a group marker record and sets its fields appropriately.
45      *
46      * @param id id must be 0x00 or an exception
47      * will be throw upon validation
48      * @param size size the size of the data area of the record
49      * @param data data of the record (should not contain sid/len)
50      */

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

67
68     public GroupMarkerSubRecord(short id, short size, byte [] data, int offset)
69     {
70         super(id, size, data, offset);
71     
72     }
73
74     /**
75      * Checks the sid matches the expected side for this record
76      *
77      * @param id the expected sid.
78      */

79     protected void validateSid(short id)
80     {
81         if (id != sid)
82         {
83             throw new RecordFormatException("Not a Group Marker record");
84         }
85     }
86
87     protected void fillFields(byte [] data, short size, int offset)
88     {
89 // int pos = 0;
90
reserved = new byte[size];
91         System.arraycopy(data, offset, reserved, 0, size);
92     }
93
94     public String JavaDoc toString()
95     {
96         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
97
98         String JavaDoc nl = System.getProperty("line.separator");
99         buffer.append("[ftGmo]" + nl);
100         buffer.append(" reserved = ").append(HexDump.toHex(reserved)).append(nl);
101         buffer.append("[/ftGmo]" + nl);
102         return buffer.toString();
103     }
104
105     public int serialize(int offset, byte[] data)
106     {
107         LittleEndian.putShort(data, 0 + offset, sid);
108         LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
109         System.arraycopy(reserved, 0, data, offset + 4, getRecordSize() - 4);
110
111         return getRecordSize();
112     }
113
114     /**
115      * Size of record (exluding 4 byte header)
116      */

117     public int getRecordSize()
118     {
119         return 4 + reserved.length;
120     }
121
122     public short getSid()
123     {
124         return sid;
125     }
126
127     public Object JavaDoc clone() {
128         GroupMarkerSubRecord rec = new GroupMarkerSubRecord();
129         rec.reserved = new byte[reserved.length];
130         for ( int i = 0; i < reserved.length; i++ )
131             rec.reserved[i] = reserved[i];
132         return rec;
133     }
134
135
136
137 } // END OF CLASS
138

139
140
Popular Tags