1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 import org.apache.poi.util.StringUtil; 23 24 33 34 public class FooterRecord 35 extends Record 36 { 37 public final static short sid = 0x15; 38 private byte field_1_footer_len; 39 private String field_2_footer; 40 41 public FooterRecord() 42 { 43 } 44 45 52 53 public FooterRecord(short id, short size, byte [] data) 54 { 55 super(id, size, data); 56 } 57 58 66 67 public FooterRecord(short id, short size, byte [] data, int offset) 68 { 69 super(id, size, data, offset); 70 } 71 72 protected void validateSid(short id) 73 { 74 if (id != sid) 75 { 76 throw new RecordFormatException("NOT A FooterRECORD"); 77 } 78 } 79 80 protected void fillFields(byte [] data, short size, int offset) 81 { 82 if (size > 0) 83 { 84 field_1_footer_len = data[ 0 + offset ]; 85 field_2_footer = StringUtil.getFromCompressedUnicode(data, 3 + offset, LittleEndian.ubyteToInt( field_1_footer_len) ); 87 } 88 } 89 90 96 97 public void setFooterLength(byte len) 98 { 99 field_1_footer_len = len; 100 } 101 102 108 109 public void setFooter(String footer) 110 { 111 field_2_footer = footer; 112 } 113 114 120 121 public short getFooterLength() 122 { 123 return (short)(0xFF & field_1_footer_len); } 125 126 132 133 public String getFooter() 134 { 135 return field_2_footer; 136 } 137 138 public String toString() 139 { 140 StringBuffer buffer = new StringBuffer (); 141 142 buffer.append("[FOOTER]\n"); 143 buffer.append(" .footerlen = ") 144 .append(Integer.toHexString(getFooterLength())).append("\n"); 145 buffer.append(" .footer = ").append(getFooter()) 146 .append("\n"); 147 buffer.append("[/FOOTER]\n"); 148 return buffer.toString(); 149 } 150 151 public int serialize(int offset, byte [] data) 152 { 153 int len = 4; 154 155 if (getFooterLength() > 0) 156 { 157 len+=3; } 159 LittleEndian.putShort(data, 0 + offset, sid); 160 LittleEndian.putShort(data, 2 + offset, 161 ( short ) ((len - 4) + getFooterLength())); 162 if (getFooterLength() > 0) 163 { 164 data[ 4 + offset ] = (byte)getFooterLength(); 165 StringUtil.putCompressedUnicode(getFooter(), data, 7 + offset); } 167 return getRecordSize(); 168 } 169 170 public int getRecordSize() 171 { 172 int retval = 4; 173 174 if (getFooterLength() > 0) 175 { 176 retval+=3; } 178 return retval + getFooterLength(); 179 } 180 181 public short getSid() 182 { 183 return this.sid; 184 } 185 186 public Object clone() { 187 FooterRecord rec = new FooterRecord(); 188 rec.field_1_footer_len = field_1_footer_len; 189 rec.field_2_footer = field_2_footer; 190 return rec; 191 } 192 } 193 | Popular Tags |