1 2 17 18 package org.apache.poi.ddf; 19 20 import org.apache.poi.util.HexDump; 21 import org.apache.poi.util.LittleEndian; 22 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 27 33 public class UnknownEscherRecord extends EscherRecord 34 { 35 private static final byte[] NO_BYTES = new byte[0]; 36 37 38 private byte[] thedata = NO_BYTES; 39 private List childRecords = new ArrayList (); 40 41 public UnknownEscherRecord() 42 { 43 } 44 45 53 public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) 54 { 55 int bytesRemaining = readHeader( data, offset ); 56 if ( isContainerRecord() ) 57 { 58 int bytesWritten = 0; 59 thedata = new byte[0]; 60 offset += 8; 61 bytesWritten += 8; 62 while ( bytesRemaining > 0 ) 63 { 64 EscherRecord child = recordFactory.createRecord( data, offset ); 65 int childBytesWritten = child.fillFields( data, offset, recordFactory ); 66 bytesWritten += childBytesWritten; 67 offset += childBytesWritten; 68 bytesRemaining -= childBytesWritten; 69 getChildRecords().add( child ); 70 } 71 return bytesWritten; 72 } 73 else 74 { 75 thedata = new byte[bytesRemaining]; 76 System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining ); 77 return bytesRemaining + 8; 78 } 79 } 80 81 87 public int serialize( int offset, byte[] data, EscherSerializationListener listener ) 88 { 89 listener.beforeRecordSerialize( offset, getRecordId(), this ); 90 91 LittleEndian.putShort(data, offset, getOptions()); 92 LittleEndian.putShort(data, offset+2, getRecordId()); 93 int remainingBytes = thedata.length; 94 for ( Iterator iterator = getChildRecords().iterator(); iterator.hasNext(); ) 95 { 96 EscherRecord r = (EscherRecord) iterator.next(); 97 remainingBytes += r.getRecordSize(); 98 } 99 LittleEndian.putInt(data, offset+4, remainingBytes); 100 System.arraycopy(thedata, 0, data, offset+8, thedata.length); 101 int pos = offset+8+thedata.length; 102 for ( Iterator iterator = getChildRecords().iterator(); iterator.hasNext(); ) 103 { 104 EscherRecord r = (EscherRecord) iterator.next(); 105 pos += r.serialize(pos, data, listener ); 106 } 107 108 listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); 109 return pos - offset; 110 } 111 112 public byte[] getData() 113 { 114 return thedata; 115 } 116 117 122 public int getRecordSize() 123 { 124 return 8 + thedata.length; 125 } 126 127 public List getChildRecords() 128 { 129 return childRecords; 130 } 131 132 public void setChildRecords( List childRecords ) 133 { 134 this.childRecords = childRecords; 135 } 136 137 public Object clone() 138 { 139 return super.clone(); 141 } 142 143 146 public String getRecordName() 147 { 148 return "Unknown 0x" + HexDump.toHex(getRecordId()); 149 } 150 151 public String toString() 152 { 153 String nl = System.getProperty( "line.separator" ); 154 155 StringBuffer children = new StringBuffer (); 156 if ( getChildRecords().size() > 0 ) 157 { 158 children.append( " children: " + nl ); 159 for ( Iterator iterator = getChildRecords().iterator(); iterator.hasNext(); ) 160 { 161 EscherRecord record = (EscherRecord) iterator.next(); 162 children.append( record.toString() ); 163 children.append( nl ); 164 } 165 } 166 167 String theDumpHex = ""; 168 try 169 { 170 if (thedata.length != 0) 171 { 172 theDumpHex = " Extra Data:" + nl; 173 theDumpHex += HexDump.dump(thedata, 0, 0); 174 } 175 } 176 catch ( Exception e ) 177 { 178 theDumpHex = "Error!!"; 179 } 180 181 return getClass().getName() + ":" + nl + 182 " isContainer: " + isContainerRecord() + nl + 183 " options: 0x" + HexDump.toHex( getOptions() ) + nl + 184 " recordId: 0x" + HexDump.toHex( getRecordId() ) + nl + 185 " numchildren: " + getChildRecords().size() + nl + 186 theDumpHex + 187 children.toString(); 188 } 189 190 public void addChildRecord( EscherRecord childRecord ) 191 { 192 getChildRecords().add( childRecord ); 193 } 194 195 } 196 197 198 199 | Popular Tags |