public void TestReadContinued() { //simulate a continues Drawing record MemoryStream out1 = new MemoryStream(); //main part DrawingRecord dg = new DrawingRecord(); byte[] data1 = new byte[8224]; Arrays.Fill(data1, (byte)1); dg.Data = (/*setter*/ data1); byte[] dataX = dg.Serialize(); out1.Write(dataX, 0, dataX.Length); //continued part byte[] data2 = new byte[4048]; Arrays.Fill(data2, (byte)2); ContinueRecord cn = new ContinueRecord(data2); dataX = cn.Serialize(); out1.Write(dataX, 0, dataX.Length); List <Record> rec = RecordFactory.CreateRecords(new MemoryStream(out1.ToArray())); Assert.AreEqual(2, rec.Count); Assert.IsTrue(rec[0] is DrawingRecord); Assert.IsTrue(rec[1] is ContinueRecord); Assert.IsTrue(Arrays.Equals(data1, ((DrawingRecord)rec[0]).Data)); Assert.IsTrue(Arrays.Equals(data2, ((ContinueRecord)rec[1]).Data)); }
public void TestCreateAggregate() { String msoDrawingRecord1 = "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 " + "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 " + "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 " + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 " + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 " + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 " + "05 00 94 00 00 00 11 F0 00 00 00 00"; String msoDrawingRecord2 = "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " + "0B 00 0C 00 00 00 11 F0 00 00 00 00"; DrawingRecord d1 = new DrawingRecord(); d1.Data = (HexRead.ReadFromString(msoDrawingRecord1)); ObjRecord r1 = new ObjRecord(); DrawingRecord d2 = new DrawingRecord(); d2.Data = (HexRead.ReadFromString(msoDrawingRecord2)); ObjRecord r2 = new ObjRecord(); ArrayList records = new ArrayList(); records.Add(d1); records.Add(r1); records.Add(d2); records.Add(r2); DrawingManager2 drawingManager = new DrawingManager2(new EscherDggRecord()); EscherAggregate aggregate = EscherAggregate.CreateAggregate(records, 0, drawingManager); Assert.AreEqual(1, aggregate.EscherRecords.Count); Assert.AreEqual(unchecked ((short)0xF002), aggregate.GetEscherRecord(0).RecordId); Assert.AreEqual(2, aggregate.GetEscherRecord(0).ChildRecords.Count); // System.out.println( "aggregate = " + aggregate ); }
private static DrawingRecord CreateDrawingRecord() { //throw new NotImplementedException(); byte[] drawingData = HexRead.ReadFromString("0F 00 02 F0 48 00 00 00 30 00 08 F0 " + "08 00 00 00 01 00 00 00 00 0C 00 00 0F 00 03 F0 " + "30 00 00 00 0F 00 04 F0 28 00 00 00 01 00 09 F0 " + "10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 00 02 00 0A F0 08 00 00 00 00 0C 00 00 " + "05 00 00 00"); DrawingRecord retval = new DrawingRecord(); retval.SetData(drawingData); return(retval); }
public void TestReadContinued() { //simulate a continues Drawing record MemoryStream out1 = new MemoryStream(); //main part DrawingRecord dg = new DrawingRecord(); byte[] data1 = new byte[8224]; Arrays.Fill(data1, (byte)1); dg.Data = (/*setter*/ data1); byte[] dataX = dg.Serialize(); out1.Write(dataX, 0, dataX.Length); //continued part byte[] data2 = new byte[4048]; Arrays.Fill(data2, (byte)2); ContinueRecord cn = new ContinueRecord(data2); dataX = cn.Serialize(); out1.Write(dataX, 0, dataX.Length); List <Record> rec = RecordFactory.CreateRecords(new MemoryStream(out1.ToArray())); Assert.AreEqual(1, rec.Count); Assert.IsTrue(rec[0] is DrawingRecord); //DrawingRecord.Data should return concatenated data1 and data2 byte[] tmp = new byte[data1.Length + data2.Length]; Array.Copy(data1, 0, tmp, 0, data1.Length); Array.Copy(data2, 0, tmp, data1.Length, data2.Length); DrawingRecord dg2 = (DrawingRecord)rec[(0)]; Assert.AreEqual(data1.Length + data2.Length, dg2.Data.Length); Assert.IsTrue(Arrays.Equals(tmp, dg2.Data)); }
public void TestCreateAggregate() { string msoDrawingRecord1 = "0F 00 02 F0 20 01 00 00 10 00 08 F0 08 00 00 00 \n" + "03 00 00 00 02 04 00 00 0F 00 03 F0 08 01 00 00 \n" + "0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 00 \n" + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \n" + "02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 00 \n" + "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 \n" + "01 04 00 00 00 0A 00 00 73 00 0B F0 2A 00 00 00 \n" + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 \n" + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 \n" + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 \n" + "00 00 00 00 01 00 54 00 05 00 45 00 01 00 88 03 \n" + "05 00 94 00 00 00 11 F0 00 00 00 00"; string msoDrawingRecord2 = "0F 00 04 F0 64 00 00 00 42 01 0A F0 08 00 00 00 " + "02 04 00 00 80 0A 00 00 73 00 0B F0 2A 00 00 00 " + "BF 00 08 00 08 00 44 01 04 00 00 00 7F 01 00 00 " + "01 00 BF 01 00 00 11 00 C0 01 40 00 00 08 FF 01 " + "10 00 10 00 BF 03 00 00 08 00 00 00 10 F0 12 00 " + "00 00 00 00 01 00 8D 03 05 00 E4 00 03 00 4D 03 " + "0B 00 0C 00 00 00 11 F0 00 00 00 00"; DrawingRecord d1 = new DrawingRecord(); d1.Data = HexRead.ReadFromString(msoDrawingRecord1); ObjRecord r1 = new ObjRecord(); DrawingRecord d2 = new DrawingRecord(); d2.Data = (HexRead.ReadFromString(msoDrawingRecord2)); TextObjectRecord r2 = new TextObjectRecord(); r2.Str = (new HSSFRichTextString("Aggregated")); NoteRecord n2 = new NoteRecord(); List <RecordBase> recordStream = new List <RecordBase>(); recordStream.Add(InternalSheet.CreateBOF()); recordStream.Add(d1); recordStream.Add(r1); recordStream.Add(CreateWindow2Record()); recordStream.Add(EOFRecord.instance); ConfirmAggregatedRecords(recordStream); recordStream = new List <RecordBase>(); recordStream.Add(InternalSheet.CreateBOF()); recordStream.Add(d1); recordStream.Add(r1); recordStream.Add(d2); recordStream.Add(r2); recordStream.Add(CreateWindow2Record()); recordStream.Add(EOFRecord.instance); ConfirmAggregatedRecords(recordStream); recordStream = new List <RecordBase>(); recordStream.Add(InternalSheet.CreateBOF()); recordStream.Add(d1); recordStream.Add(r1); recordStream.Add(d2); recordStream.Add(r2); recordStream.Add(n2); recordStream.Add(CreateWindow2Record()); recordStream.Add(EOFRecord.instance); ConfirmAggregatedRecords(recordStream); }
/// <summary> /// Returns the next available record, or null if /// this pass didn't return a record that's /// suitable for returning (eg was a continue record). /// </summary> /// <returns></returns> private Record GetNextRecord() { Record toReturn = null; if (in1.HasNextRecord) { // Grab our next record in1.NextRecord(); short sid = in1.Sid; // // for some reasons we have to make the workbook to be at least 4096 bytes // but if we have such workbook we Fill the end of it with zeros (many zeros) // // it Is not good: // if the Length( all zero records ) % 4 = 1 // e.g.: any zero record would be Readed as 4 bytes at once ( 2 - id and 2 - size ). // And the last 1 byte will be Readed WRONG ( the id must be 2 bytes ) // // So we should better to Check if the sid Is zero and not to Read more data // The zero sid shows us that rest of the stream data Is a fake to make workbook // certain size // if (sid == 0) { return(null); } // If we had a last record, and this one // Isn't a continue record, then pass // it on to the listener if ((rec != null) && (sid != ContinueRecord.sid)) { // This last record ought to be returned toReturn = rec; } // If this record Isn't a continue record, // then build it up if (sid != ContinueRecord.sid) { //Console.WriteLine("creating "+sid); Record[] recs = RecordFactory.CreateRecord(in1); // We know that the multiple record situations // don't contain continue records, so just // pass those on to the listener now if (recs.Length > 1) { bonusRecords = new ArrayList(recs.Length - 1); for (int k = 0; k < (recs.Length - 1); k++) { bonusRecords.Add(recs[k]); } } // Regardless of the number we Created, always hold // onto the last record to be Processed on the next // loop, in case it has any continue records rec = recs[recs.Length - 1]; // Don't return it just yet though, as we probably have // a record from the last round to return } else { // Normally, ContinueRecords are handled internally // However, in a few cases, there Is a gap between a record at // its Continue, so we have to handle them specially // This logic Is much like in RecordFactory.CreateRecords() Record[] recs = RecordFactory.CreateRecord(in1); ContinueRecord crec = (ContinueRecord)recs[0]; if ((lastRec is ObjRecord) || (lastRec is TextObjectRecord)) { // You can have Obj records between a DrawingRecord // and its continue! lastDrawingRecord.ProcessContinueRecord(crec.Data); // Trigger them on the drawing record, now it's complete rec = lastDrawingRecord; } else if ((lastRec is DrawingGroupRecord)) { ((DrawingGroupRecord)lastRec).ProcessContinueRecord(crec.Data); // Trigger them on the drawing record, now it's complete rec = lastRec; } else { if (rec is UnknownRecord) { ;//silently skip records we don't know about } else { throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception"); } } } // Update our tracking of the last record lastRec = rec; if (rec is DrawingRecord) { lastDrawingRecord = (DrawingRecord)rec; } } else { // No more records hitEOS = true; } // If we've hit the end-of-stream, then // finish off the last record and be done if (hitEOS) { complete = true; // Return the last record if there was // one, otherwise null if (rec != null) { toReturn = rec; rec = null; } } return(toReturn); }