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.util.Arrays ; 24 import java.io.ByteArrayOutputStream ; 25 import java.io.IOException ; 26 27 34 public class EscherComplexProperty 35 extends EscherProperty 36 { 37 byte[] complexData = new byte[0]; 38 39 47 public EscherComplexProperty( short id, byte[] complexData ) 48 { 49 super( id ); 50 this.complexData = complexData; 51 } 52 53 61 public EscherComplexProperty( short propertyNumber, boolean isBlipId, byte[] complexData ) 62 { 63 super( propertyNumber, true, isBlipId ); 64 this.complexData = complexData; 65 } 66 67 70 public int serializeSimplePart( byte[] data, int pos ) 71 { 72 LittleEndian.putShort(data, pos, getId()); 73 LittleEndian.putInt(data, pos + 2, complexData.length); 74 return 6; 75 } 76 77 84 public int serializeComplexPart( byte[] data, int pos ) 85 { 86 System.arraycopy(complexData, 0, data, pos, complexData.length); 87 return complexData.length; 88 } 89 90 93 public byte[] getComplexData() 94 { 95 return complexData; 96 } 97 98 104 public boolean equals( Object o ) 105 { 106 if ( this == o ) return true; 107 if ( !( o instanceof EscherComplexProperty ) ) return false; 108 109 final EscherComplexProperty escherComplexProperty = (EscherComplexProperty) o; 110 111 if ( !Arrays.equals( complexData, escherComplexProperty.complexData ) ) return false; 112 113 return true; 114 } 115 116 121 public int getPropertySize() 122 { 123 return 6 + complexData.length; 124 } 125 126 129 public int hashCode() 130 { 131 return getId() * 11; 132 } 133 134 137 public String toString() 138 { 139 String dataStr; 140 ByteArrayOutputStream b = new ByteArrayOutputStream (); 141 try 142 { 143 HexDump.dump( this.complexData, 0, b, 0 ); 144 dataStr = b.toString(); 145 } 146 catch ( Exception e ) 147 { 148 dataStr = e.toString(); 149 } 150 finally 151 { 152 try 153 { 154 b.close(); 155 } 156 catch ( IOException e ) 157 { 158 e.printStackTrace(); 159 } 160 } 161 162 return "propNum: " + getPropertyNumber() 163 + ", propName: " + EscherProperties.getPropertyName( getPropertyNumber() ) 164 + ", complex: " + isComplex() 165 + ", blipId: " + isBlipId() 166 + ", data: " + System.getProperty("line.separator") + dataStr; 167 } 168 169 } 170 | Popular Tags |