1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import java.util.ArrayList ; 22 23 import org.apache.poi.util.LittleEndian; 24 25 34 35 public class ContinueRecord 36 extends Record 37 { 38 public final static short sid = 0x003C; 39 private byte[] field_1_data; 40 41 44 45 public ContinueRecord() 46 { 47 } 48 49 56 57 public ContinueRecord(short id, short size, byte [] data) 58 { 59 super(id, size, data); 60 } 61 62 70 71 public ContinueRecord(short id, short size, byte [] data, int offset) 72 { 73 super(id, size, data, offset); 74 } 75 76 79 80 public byte [] serialize() 81 { 82 byte[] retval = new byte[ field_1_data.length + 4 ]; 83 serialize(0, retval); 84 return retval; 85 } 86 87 public int serialize(int offset, byte [] data) 88 { 89 90 LittleEndian.putShort(data, offset, sid); 91 LittleEndian.putShort(data, offset + 2, ( short ) field_1_data.length); 92 System.arraycopy(field_1_data, 0, data, offset + 4, field_1_data.length); 93 return field_1_data.length + 4; 94 } 97 98 102 103 public void setData(byte [] data) 104 { 105 field_1_data = data; 106 } 107 108 112 113 public byte [] getData() 114 { 115 return field_1_data; 116 } 117 118 124 125 public static byte [] processContinue(byte [] data) 126 { 128 int records = (data.length / 8214); int offset = 8214; 132 133 ArrayList crs = new ArrayList (records); 135 int totalsize = 8214; 136 byte[] retval = null; 137 138 for (int cr = 0; cr < records; cr++) 139 { 140 ContinueRecord contrec = new ContinueRecord(); 141 int arraysize = Math.min((8214 - 4), (data.length - offset)); 142 byte[] crdata = new byte[ arraysize ]; 143 144 System.arraycopy(data, offset, crdata, 0, arraysize); 145 146 offset += crdata.length; 148 contrec.setData(crdata); 149 crs.add(contrec.serialize()); 150 } 151 for (int cr = 0; cr < records; cr++) 152 { 153 totalsize += (( byte [] ) crs.get(cr)).length; 154 } 155 156 retval = new byte[ totalsize ]; 158 offset = 8214; 159 System.arraycopy(data, 0, retval, 0, 8214); 160 for (int cr = 0; cr < records; cr++) 161 { 162 byte[] src = ( byte [] ) crs.get(cr); 163 164 System.arraycopy(src, 0, retval, offset, src.length); 165 166 offset += src.length; 168 } 169 return retval; 170 } 171 172 178 179 protected void fillFields(byte [] ignored_parm1, short ignored_parm2) 180 { 181 this.field_1_data = ignored_parm1; 182 } 185 186 191 192 protected void validateSid(short id) 193 { 194 if (id != ContinueRecord.sid) 195 { 196 throw new RecordFormatException("Not a Continue Record"); 197 } 198 } 199 200 205 206 public String toString() 207 { 208 StringBuffer buffer = new StringBuffer (); 209 210 buffer.append("[CONTINUE RECORD]\n"); 211 buffer.append(" .id = ").append(Integer.toHexString(sid)) 212 .append("\n"); 213 buffer.append("[/CONTINUE RECORD]\n"); 214 return buffer.toString(); 215 } 216 217 public short getSid() 218 { 219 return this.sid; 220 } 221 222 229 230 protected void fillFields(byte [] ignored_parm1, short ignored_parm2, int ignored_parm3) 231 { 232 } 233 234 237 public Object clone() { 238 ContinueRecord clone = new ContinueRecord(); 239 clone.setData(field_1_data); 240 return clone; 241 } 242 243 } 244 | Popular Tags |