Example #1
0
        private static byte[] toByteArray(List <RecordBase> records)
        {
            MemoryStream out1 = new MemoryStream();

            foreach (RecordBase rb in records)
            {
                NPOI.HSSF.Record.Record r = (NPOI.HSSF.Record.Record)rb;
                try
                {
                    byte[] data = r.Serialize();
                    out1.Write(data, 0, data.Length);
                }
                catch (IOException e)
                {
                    throw new RuntimeException(e);
                }
            }
            return(out1.ToArray());
        }
Example #2
0
            public void VisitRecord(Record r)
            {

                int estimatedSize = r.RecordSize;
                byte[] buf = new byte[estimatedSize];
                int serializedSize = r.Serialize(0, buf);
                if (estimatedSize != serializedSize)
                {
                    throw new AssertionException("serialized size mismatch for record ("
                            + r.GetType().Name + ")");
                }
                _totalSize += estimatedSize;
            }
 public void VisitRecord(Record r)
 {
     int currentOffset = _startOffset + _countBytesWritten;
     _countBytesWritten += r.Serialize(currentOffset, _data);
 }
 private void CompareData(Record record, String message)
 {
     byte[] recData = record.Serialize();
     for (int i = 0; i < recData.Length; i++)
     {
         Assert.AreEqual(recData[i], data[offset[0]++], message + " data byte " + i);
     }
 }
        /**
         * Compare the Serialized bytes of two records are equal
         * @param first the first record to Compare
         * @param second the second record to Compare
         * @return boolean whether or not the record where equal
         */
        private static bool CompareRec(Record first, Record second)
        {
            byte[] rec1 = first.Serialize();
            byte[] rec2 = second.Serialize();

            if (rec1.Length != rec2.Length)
            {
                return false;
            }
            for (int k = 0; k < rec1.Length; k++)
            {
                if (rec1[k] != rec2[k])
                {
                    return false;
                }
            }
            return true;
        }
Example #6
0
        /**
         * Serializes this aggregate to a byte array.  Since this Is an aggregate
         * record it will effectively Serialize the aggregated records.
         *
         * @param offset    The offset into the start of the array.
         * @param data      The byte array to Serialize to.
         * @return          The number of bytes Serialized.
         */
        public override int Serialize(int offset, byte [] data)
        {
            ConvertUserModelToRecords();

            // Determine buffer size
            IList records = EscherRecords;
            int   size    = GetEscherRecordSize(records);

            byte[] buffer = new byte[size];


            // Serialize escher records into one big data structure and keep note of ending offsets.
            spEndingOffsets = new ArrayList();
            shapes          = new ArrayList();
            int pos = 0;

            for (IEnumerator iterator = records.GetEnumerator(); iterator.MoveNext();)
            {
                EscherRecord e = (EscherRecord)iterator.Current;
                pos += e.Serialize(pos, buffer, new SerializationListener(ref spEndingOffsets, ref shapes));
            }
            // todo: fix this
            shapes.Insert(0, null);
            spEndingOffsets.Insert(0, null);

            // Split escher records into Separate MSODRAWING and OBJ, TXO records.  (We don't break on
            // the first one because it's the patriach).
            pos = offset;
            for (int i = 1; i < shapes.Count; i++)
            {
                int endOffset = (int)spEndingOffsets[i] - 1;
                int startOffset;
                if (i == 1)
                {
                    startOffset = 0;
                }
                else
                {
                    startOffset = (int)spEndingOffsets[i - 1];
                }

                // Create and Write a new MSODRAWING record
                DrawingRecord drawing     = new DrawingRecord();
                byte[]        drawingData = new byte[endOffset - startOffset + 1];
                Array.Copy(buffer, startOffset, drawingData, 0, drawingData.Length);
                drawing.Data = drawingData;
                int temp = drawing.Serialize(pos, data);
                pos += temp;

                // Write the matching OBJ record
                Record obj = (Record)shapeToObj[shapes[i]];
                temp = obj.Serialize(pos, data);
                pos += temp;
            }

            // Write records that need to be Serialized after all drawing Group records
            for (int i = 0; i < tailRec.Count; i++)
            {
                Record rec = (Record)tailRec[i];
                pos += rec.Serialize(pos, data);
            }

            int bytesWritten = pos - offset;

            if (bytesWritten != RecordSize)
            {
                throw new RecordFormatException(bytesWritten + " bytes written but RecordSize reports " + RecordSize);
            }
            return(bytesWritten);
        }