1 2 17 18 package org.apache.poi.ddf; 19 20 import org.apache.poi.util.LittleEndian; 21 import org.apache.poi.util.HexDump; 22 23 import java.io.ByteArrayOutputStream ; 24 import java.io.PrintWriter ; 25 26 33 public class EscherBSERecord 34 extends EscherRecord 35 { 36 public static final short RECORD_ID = (short) 0xF007; 37 public static final String RECORD_DESCRIPTION = "MsofbtBSE"; 38 39 public static final byte BT_ERROR = 0; 40 public static final byte BT_UNKNOWN = 1; 41 public static final byte BT_EMF = 2; 42 public static final byte BT_WMF = 3; 43 public static final byte BT_PICT = 4; 44 public static final byte BT_JPEG = 5; 45 public static final byte BT_PNG = 6; 46 public static final byte BT_DIB = 7; 47 48 private byte field_1_blipTypeWin32; 49 private byte field_2_blipTypeMacOS; 50 private byte[] field_3_uid; private short field_4_tag; 52 private int field_5_size; 53 private int field_6_ref; 54 private int field_7_offset; 55 private byte field_8_usage; 56 private byte field_9_name; 57 private byte field_10_unused2; 58 private byte field_11_unused3; 59 60 private byte[] remainingData; 61 62 70 public int fillFields( byte[] data, int offset, 71 EscherRecordFactory recordFactory 72 ) 73 { 74 int bytesRemaining = readHeader( data, offset ); 75 int pos = offset + 8; 76 field_1_blipTypeWin32 = data[pos]; 77 field_2_blipTypeMacOS = data[pos + 1]; 78 System.arraycopy( data, pos + 2, field_3_uid = new byte[16], 0, 16 ); 79 field_4_tag = LittleEndian.getShort( data, pos + 18 ); 80 field_5_size = LittleEndian.getInt( data, pos + 20 ); 81 field_6_ref = LittleEndian.getInt( data, pos + 24 ); 82 field_7_offset = LittleEndian.getInt( data, pos + 28 ); 83 field_8_usage = data[pos + 32]; 84 field_9_name = data[pos + 33]; 85 field_10_unused2 = data[pos + 34]; 86 field_11_unused3 = data[pos + 35]; 87 bytesRemaining -= 36; 88 remainingData = new byte[bytesRemaining]; 89 System.arraycopy( data, pos + 36, remainingData, 0, bytesRemaining ); 90 return bytesRemaining + 8 + 36; 91 92 } 93 94 103 public int serialize( int offset, byte[] data, EscherSerializationListener listener ) 104 { 105 listener.beforeRecordSerialize( offset, getRecordId(), this ); 106 107 LittleEndian.putShort( data, offset, getOptions() ); 108 LittleEndian.putShort( data, offset + 2, getRecordId() ); 109 int remainingBytes = remainingData.length + 36; 110 LittleEndian.putInt( data, offset + 4, remainingBytes ); 111 112 data[offset + 8] = field_1_blipTypeWin32; 113 data[offset + 9] = field_2_blipTypeMacOS; 114 for ( int i = 0; i < 16; i++ ) 115 data[offset + 10 + i] = field_3_uid[i]; 116 LittleEndian.putShort( data, offset + 26, field_4_tag ); 117 LittleEndian.putInt( data, offset + 28, field_5_size ); 118 LittleEndian.putInt( data, offset + 32, field_6_ref ); 119 LittleEndian.putInt( data, offset + 36, field_7_offset ); 120 data[offset + 40] = field_8_usage; 121 data[offset + 41] = field_9_name; 122 data[offset + 42] = field_10_unused2; 123 data[offset + 43] = field_11_unused3; 124 System.arraycopy( remainingData, 0, data, offset + 44, remainingData.length ); 125 int pos = offset + 8 + 36 + remainingData.length; 126 127 listener.afterRecordSerialize(pos, getRecordId(), pos - offset, this); 128 return pos - offset; 129 } 130 131 136 public int getRecordSize() 137 { 138 return 8 + 1 + 1 + 16 + 2 + 4 + 4 + 4 + 1 + 1 + 1 + 1 + remainingData.length; 139 } 140 141 144 public String getRecordName() 145 { 146 return "BSE"; 147 } 148 149 153 public byte getBlipTypeWin32() 154 { 155 return field_1_blipTypeWin32; 156 } 157 158 161 public void setBlipTypeWin32( byte blipTypeWin32 ) 162 { 163 this.field_1_blipTypeWin32 = blipTypeWin32; 164 } 165 166 170 public byte getBlipTypeMacOS() 171 { 172 return field_2_blipTypeMacOS; 173 } 174 175 178 public void setBlipTypeMacOS( byte blipTypeMacOS ) 179 { 180 this.field_2_blipTypeMacOS = blipTypeMacOS; 181 } 182 183 186 public byte[] getUid() 187 { 188 return field_3_uid; 189 } 190 191 194 public void setUid( byte[] uid ) 195 { 196 this.field_3_uid = uid; 197 } 198 199 202 public short getTag() 203 { 204 return field_4_tag; 205 } 206 207 210 public void setTag( short tag ) 211 { 212 this.field_4_tag = tag; 213 } 214 215 218 public int getSize() 219 { 220 return field_5_size; 221 } 222 223 226 public void setSize( int size ) 227 { 228 this.field_5_size = size; 229 } 230 231 234 public int getRef() 235 { 236 return field_6_ref; 237 } 238 239 242 public void setRef( int ref ) 243 { 244 this.field_6_ref = ref; 245 } 246 247 250 public int getOffset() 251 { 252 return field_7_offset; 253 } 254 255 258 public void setOffset( int offset ) 259 { 260 this.field_7_offset = offset; 261 } 262 263 266 public byte getUsage() 267 { 268 return field_8_usage; 269 } 270 271 274 public void setUsage( byte usage ) 275 { 276 this.field_8_usage = usage; 277 } 278 279 282 public byte getName() 283 { 284 return field_9_name; 285 } 286 287 290 public void setName( byte name ) 291 { 292 this.field_9_name = name; 293 } 294 295 public byte getUnused2() 296 { 297 return field_10_unused2; 298 } 299 300 public void setUnused2( byte unused2 ) 301 { 302 this.field_10_unused2 = unused2; 303 } 304 305 public byte getUnused3() 306 { 307 return field_11_unused3; 308 } 309 310 public void setUnused3( byte unused3 ) 311 { 312 this.field_11_unused3 = unused3; 313 } 314 315 318 public byte[] getRemainingData() 319 { 320 return remainingData; 321 } 322 323 326 public void setRemainingData( byte[] remainingData ) 327 { 328 this.remainingData = remainingData; 329 } 330 331 334 public String toString() 335 { 336 String nl = System.getProperty( "line.separator" ); 337 338 String extraData; 339 ByteArrayOutputStream b = new ByteArrayOutputStream (); 340 try 341 { 342 HexDump.dump( this.remainingData, 0, b, 0 ); 343 extraData = b.toString(); 344 } 345 catch ( Exception e ) 346 { 347 extraData = e.toString(); 348 } 349 return getClass().getName() + ":" + nl + 350 " RecordId: 0x" + HexDump.toHex( RECORD_ID ) + nl + 351 " Options: 0x" + HexDump.toHex( getOptions() ) + nl + 352 " BlipTypeWin32: " + field_1_blipTypeWin32 + nl + 353 " BlipTypeMacOS: " + field_2_blipTypeMacOS + nl + 354 " SUID: " + HexDump.toHex(field_3_uid) + nl + 355 " Tag: " + field_4_tag + nl + 356 " Size: " + field_5_size + nl + 357 " Ref: " + field_6_ref + nl + 358 " Offset: " + field_7_offset + nl + 359 " Usage: " + field_8_usage + nl + 360 " Name: " + field_9_name + nl + 361 " Unused2: " + field_10_unused2 + nl + 362 " Unused3: " + field_11_unused3 + nl + 363 " Extra Data:" + nl + extraData; 364 365 366 } 367 368 371 public String getBlipType( byte b ) 372 { 373 switch ( b ) 374 { 375 case BT_ERROR: 376 return " ERROR"; 377 case BT_UNKNOWN: 378 return " UNKNOWN"; 379 case BT_EMF: 380 return " EMF"; 381 case BT_WMF: 382 return " WMF"; 383 case BT_PICT: 384 return " PICT"; 385 case BT_JPEG: 386 return " JPEG"; 387 case BT_PNG: 388 return " PNG"; 389 case BT_DIB: 390 return " DIB"; 391 default: 392 if ( b < 32 ) 393 return " NotKnown"; 394 else 395 return " Client"; 396 } 397 } 398 399 400 } 401 | Popular Tags |