예제 #1
0
        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));

        }
예제 #2
0
        /**
         * Clone this record.
         */
        public override Object Clone()
        {
            ContinueRecord Clone = new ContinueRecord();

            Clone.Data = (field_1_data);
            return(Clone);
        }
예제 #3
0
        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));

        }
예제 #4
0
        private int SerializeTrailingRecords(int offset, byte[] data)
        {
            byte[] textBytes;
            try
            {
                textBytes = Encoding.GetEncoding("UTF-16LE").GetBytes(_text.String);
            }
            catch (EncoderFallbackException)
            {
                throw;
            }
            int remainingLength = textBytes.Length;

            int countTextBytesWritten = 0;
            int pos = offset;
            // (regardless what was read, we always serialize double-byte
            // unicode characters (UTF-16LE).
            Byte unicodeFlag = (byte)1;

            while (remainingLength > 0)
            {
                int chunkSize = Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE - 2, remainingLength);
                remainingLength       -= chunkSize;
                pos                   += ContinueRecord.Write(data, pos, unicodeFlag, textBytes, countTextBytesWritten, chunkSize);
                countTextBytesWritten += chunkSize;
            }

            byte[] formatData = CreateFormatData(_text);
            pos += ContinueRecord.Write(data, pos, null, formatData);
            return(pos - offset);
        }
예제 #5
0
 /**
  * Clone this record.
  */
 public override Object Clone() {
   ContinueRecord Clone = new ContinueRecord();
   Clone.Data=(field_1_data);
   return Clone;
 }
예제 #6
0
 /**
  * @param drawingData - escher records saved into single byte array
  * @param writtenEscherBytes - count of bytes already saved into drawing records (we should know it to decide create
  *                           drawing or continue record)
  * @param pos current position of data array
  * @param data - array of bytes where drawing records must be serialized
  * @param i - number of shape, saved into data array
  * @return offset of data array after serialization
  */
 private int WriteDataIntoDrawingRecord(byte[] drawingData, int writtenEscherBytes, int pos, byte[] data, int i)
 {
     int temp = 0;
     //First record in drawing layer MUST be DrawingRecord
     if (writtenEscherBytes + drawingData.Length > RecordInputStream.MAX_RECORD_DATA_SIZE && i != 1)
     {
         for (int j = 0; j < drawingData.Length; j += RecordInputStream.MAX_RECORD_DATA_SIZE)
         {
             byte[] buf = new byte[Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j)];
             System.Array.Copy(drawingData, j, buf, 0, Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j));
             ContinueRecord drawing = new ContinueRecord(buf);
             temp += drawing.Serialize(pos + temp, data);
         }
     }
     else
     {
         for (int j = 0; j < drawingData.Length; j += RecordInputStream.MAX_RECORD_DATA_SIZE)
         {
             if (j == 0)
             {
                 DrawingRecord drawing = new DrawingRecord();
                 byte[] buf = new byte[Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j)];
                 System.Array.Copy(drawingData, j, buf, 0, Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j));
                 drawing.Data = (buf);
                 temp += drawing.Serialize(pos + temp, data);
             }
             else
             {
                 byte[] buf = new byte[Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j)];
                 System.Array.Copy(drawingData, j, buf, 0, Math.Min(RecordInputStream.MAX_RECORD_DATA_SIZE, drawingData.Length - j));
                 ContinueRecord drawing = new ContinueRecord(buf);
                 temp += drawing.Serialize(pos + temp, data);
             }
         }
     }
     return temp;
 }
예제 #7
0
        /**
         * @return the next available record, or <code>null</code> if
         * this pass didn't return a record that's
         * suitable for returning (eg was a continue record).
         */
        private Record ReadNextRecord()
        {
            Record record = RecordFactory.CreateSingleRecord(_recStream);

            _lastRecordWasEOFLevelZero = false;

            if (record is BOFRecord)
            {
                _bofDepth++;
                return(record);
            }

            if (record is EOFRecord)
            {
                _bofDepth--;
                if (_bofDepth < 1)
                {
                    _lastRecordWasEOFLevelZero = true;
                }

                return(record);
            }

            if (record is DBCellRecord)
            {
                // Not needed by POI.  Regenerated from scratch by POI when spreadsheet is written
                return(null);
            }

            if (record is RKRecord)
            {
                return(RecordFactory.ConvertToNumberRecord((RKRecord)record));
            }

            if (record is MulRKRecord)
            {
                Record[] records = RecordFactory.ConvertRKRecords((MulRKRecord)record);

                _unreadRecordBuffer = records;
                _unreadRecordIndex  = 1;
                return(records[0]);
            }

            if (record.Sid == DrawingGroupRecord.sid &&
                _lastRecord is DrawingGroupRecord)
            {
                DrawingGroupRecord lastDGRecord = (DrawingGroupRecord)_lastRecord;
                lastDGRecord.Join((AbstractEscherHolderRecord)record);
                return(null);
            }
            if (record.Sid == ContinueRecord.sid)
            {
                ContinueRecord contRec = (ContinueRecord)record;

                if (_lastRecord is ObjRecord || _lastRecord is TextObjectRecord)
                {
                    // Drawing records have a very strange continue behaviour.
                    //There can actually be OBJ records mixed between the continues.
                    _lastDrawingRecord.ProcessContinueRecord(contRec.Data);
                    //we must remember the position of the continue record.
                    //in the serialization procedure the original structure of records must be preserved
                    if (_shouldIncludeContinueRecords)
                    {
                        return(record);
                    }
                    return(null);
                }
                if (_lastRecord is DrawingGroupRecord)
                {
                    ((DrawingGroupRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                    return(null);
                }
                if (_lastRecord is DrawingRecord)
                {
                    ((DrawingRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                    return(null);
                }
                if (_lastRecord is CrtMlFrtRecord)
                {
                    return(record);
                }
                if (_lastRecord is UnknownRecord)
                {
                    //Gracefully handle records that we don't know about,
                    //that happen to be continued
                    return(record);
                }
                if (_lastRecord is EOFRecord)
                {
                    // This is really odd, but excel still sometimes
                    //  outPuts a file like this all the same
                    return(record);
                }
                //if (_lastRecord is StringRecord)
                //{
                //    ((StringRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                //    return null;
                //}
                throw new RecordFormatException("Unhandled Continue Record");
            }
            _lastRecord = record;
            if (record is DrawingRecord)
            {
                _lastDrawingRecord = (DrawingRecord)record;
            }
            return(record);
        }
예제 #8
0
        public void TestDuplicatePLS_bug47415()
        {
            NPOI.HSSF.Record.Record plsA = ur(UnknownRecord.PLS_004D, "BA AD F0 0D");
            NPOI.HSSF.Record.Record plsB = ur(UnknownRecord.PLS_004D, "DE AD BE EF");
            NPOI.HSSF.Record.Record contB1 = new ContinueRecord(HexRead.ReadFromString("FE ED"));
            NPOI.HSSF.Record.Record contB2 = new ContinueRecord(HexRead.ReadFromString("FA CE"));
            NPOI.HSSF.Record.Record[] recs = {
				new HeaderRecord("&LSales Figures"),
				new FooterRecord("&LInventory"),
				new HCenterRecord(),
				new VCenterRecord(),
				plsA,
				plsB, contB1, contB2, // make sure continuing PLS is still OK
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb;
            try
            {
                psb = new PageSettingsBlock(rs);
            }
            catch (RecordFormatException e)
            {
                if ("Duplicate PageSettingsBlock record (sid=0x4d)".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47415");
                }
                throw e;
            }

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            // records were assembled in standard order, so this simple check is OK
            Assert.IsTrue(Arrays.Equals(recs, outRecs));
        }