Beispiel #1
0
        public override int Serialize(int offset, byte [] data)
        {
            int recSize  = RecordSize;
            int dataSize = recSize - 4;

            LittleEndianByteArrayOutputStream out1 = new LittleEndianByteArrayOutputStream(data, offset, recSize);

            out1.WriteShort(sid);
            out1.WriteShort(dataSize);

            if (_uninterpretedData == null)
            {
                for (int i = 0; i < subrecords.Count; i++)
                {
                    SubRecord record = subrecords[i];
                    record.Serialize(out1);
                }
                int expectedEndIx = offset + dataSize;
                // padding
                while (out1.WriteIndex < expectedEndIx)
                {
                    out1.WriteByte(0);
                }
            }
            else
            {
                out1.Write(_uninterpretedData);
            }
            return(recSize);
        }
Beispiel #2
0
        public override Object Clone()
        {
            ObjRecord rec = new ObjRecord();

            for (int i = 0; i < subrecords.Count; i++)
            {
                SubRecord record = subrecords[i];
                rec.AddSubRecord((SubRecord)record.Clone());
            }

            return(rec);
        }
Beispiel #3
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("[OBJ]\n");
            for (int i = 0; i < subrecords.Count; i++)
            {
                SubRecord record = subrecords[i];
                sb.Append("SUBRECORD: ").Append(record.ToString());
            }
            sb.Append("[/OBJ]\n");
            return(sb.ToString());
        }
Beispiel #4
0
        /**
         * Constructs a OBJ record and Sets its fields appropriately.
         *
         * @param in the RecordInputstream to Read the record from
         */

        public ObjRecord(RecordInputStream in1)
        {
            // TODO - problems with OBJ sub-records stream
            // MS spec says first sub-record is always CommonObjectDataSubRecord,
            // and last is
            // always EndSubRecord. OOO spec does not mention ObjRecord(0x005D).
            // Existing POI test data seems to violate that rule. Some test data
            // seems to contain
            // garbage, and a crash is only averted by stopping at what looks like
            // the 'EndSubRecord'

            //Check if this can be continued, if so then the
            //following wont work properly
            int subSize = 0;

            byte[] subRecordData = in1.ReadRemainder();

            if (LittleEndian.GetUShort(subRecordData, 0) != CommonObjectDataSubRecord.sid)
            {
                // seems to occur in just one junit on "OddStyleRecord.xls" (file created by CrystalReports)
                // Excel tolerates the funny ObjRecord, and replaces it with a corrected version
                // The exact logic/reasoning is not yet understood
                _uninterpretedData = subRecordData;
                subrecords         = null;
                return;
            }
            //if (subRecordData.Length % 2 != 0)
            //{
            //    String msg = "Unexpected length of subRecordData : " + HexDump.ToHex(subRecordData);
            //    throw new RecordFormatException(msg);
            //}
            subrecords = new List <SubRecord>();
            MemoryStream              bais         = new MemoryStream(subRecordData);
            LittleEndianInputStream   subRecStream = new LittleEndianInputStream(bais);
            CommonObjectDataSubRecord cmo          = (CommonObjectDataSubRecord)SubRecord.CreateSubRecord(subRecStream, 0);

            subrecords.Add(cmo);
            while (true)
            {
                SubRecord subRecord = SubRecord.CreateSubRecord(subRecStream, cmo.ObjectType);
                subrecords.Add(subRecord);
                if (subRecord.IsTerminating)
                {
                    break;
                }
            }
            int nRemainingBytes = subRecStream.Available();

            if (nRemainingBytes > 0)
            {
                // At present (Oct-2008), most unit test samples have (subRecordData.length % 2 == 0)
                _isPaddedToQuadByteMultiple = subRecordData.Length % MAX_PAD_ALIGNMENT == 0;
                if (nRemainingBytes >= (_isPaddedToQuadByteMultiple ? MAX_PAD_ALIGNMENT : NORMAL_PAD_ALIGNMENT))
                {
                    if (!CanPaddingBeDiscarded(subRecordData, nRemainingBytes))
                    {
                        String msg = "Leftover " + nRemainingBytes
                                     + " bytes in subrecord data " + HexDump.ToHex(subRecordData);
                        throw new RecordFormatException(msg);
                    }
                    _isPaddedToQuadByteMultiple = false;
                }
            }
            else
            {
                _isPaddedToQuadByteMultiple = false;
            }
            _uninterpretedData = null;
        }
Beispiel #5
0
 public void AddSubRecord(SubRecord o)
 {
     subrecords.Add(o);
 }
Beispiel #6
0
 public void AddSubRecord(int index, SubRecord element)
 {
     subrecords.Insert(index, element);
 }
Beispiel #7
0
 public void AddSubRecord(SubRecord o)
 {
     subrecords.Add(o);
 }
Beispiel #8
0
 public void AddSubRecord(int index, SubRecord element)
 {
     subrecords.Insert(index, element);
 }
 public SubRecordTreeNode(SubRecord record)
 {
     this.ImageKey = "Binary";
     this.Record = record;
     this.Text = record.GetType().Name;
 }