1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 33 34 public class UnknownRecord 35 extends Record 36 { 37 private short sid = 0; 38 private byte[] thedata = null; 39 40 public UnknownRecord() 41 { 42 } 43 44 51 52 public UnknownRecord(short id, short size, byte [] data) 53 { 54 sid = id; 55 thedata = data; 56 } 57 58 public UnknownRecord( short id, short size, byte[] data, int offset ) 59 { 60 sid = id; 61 thedata = new byte[size]; 62 System.arraycopy(data, offset, thedata, 0, size); 63 } 64 65 68 public int serialize(int offset, byte [] data) 69 { 70 if (thedata == null) 71 { 72 thedata = new byte[ 0 ]; 73 } 74 LittleEndian.putShort(data, 0 + offset, sid); 75 LittleEndian.putShort(data, 2 + offset, ( short ) (thedata.length)); 76 if (thedata.length > 0) 77 { 78 System.arraycopy(thedata, 0, data, 4 + offset, thedata.length); 79 } 80 return getRecordSize(); 81 } 82 83 public int getRecordSize() 84 { 85 int retval = 4; 86 87 if (thedata != null) 88 { 89 retval += thedata.length; 90 } 91 return retval; 92 } 93 94 protected void fillFields(byte [] data, short sid) 95 { 96 this.sid = sid; 97 thedata = data; 98 } 99 100 103 104 protected void validateSid(short id) 105 { 106 107 } 109 110 113 114 public String toString() 115 { 116 StringBuffer buffer = new StringBuffer (); 117 118 buffer.append("[UNKNOWN RECORD:" + Integer.toHexString(sid) + "]\n"); 119 buffer.append(" .id = ").append(Integer.toHexString(sid)) 120 .append("\n"); 121 buffer.append("[/UNKNOWN RECORD]\n"); 122 return buffer.toString(); 123 } 124 125 public short getSid() 126 { 127 return this.sid; 128 } 129 130 138 139 protected void fillFields(byte [] data, short size, int offset) 140 { 141 throw new RecordFormatException( 142 "Unknown record cannot be constructed via offset -- we need a copy of the data"); 143 } 144 145 146 public Object clone() { 147 UnknownRecord rec = new UnknownRecord(); 148 rec.sid = sid; 149 rec.thedata = thedata; 150 return rec; 151 } 152 } 153 | Popular Tags |