View | Details | Raw Unified | Return to bug 19739
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/record/ContinueRecord.java (-15 / +33 lines)
Lines 74-79 Link Here
74
{
74
{
75
    public final static short sid = 0x003C;
75
    public final static short sid = 0x003C;
76
    private byte[]            field_1_data;
76
    private byte[]            field_1_data;
77
    private short  size           = 0;
77
78
78
    /**
79
    /**
79
     * default constructor
80
     * default constructor
Lines 84-90 Link Here
84
    }
85
    }
85
86
86
    /**
87
    /**
87
     * Main constructor -- kinda dummy because we don't validate or fill fields
88
     * Main constructor -- just store the data to be processed later
88
     *
89
     *
89
     * @param id record id
90
     * @param id record id
90
     * @param size record size
91
     * @param size record size
Lines 93-103 Link Here
93
94
94
    public ContinueRecord(short id, short size, byte [] data)
95
    public ContinueRecord(short id, short size, byte [] data)
95
    {
96
    {
96
        super(id, size, data);
97
        this(id, size, data,0);
97
    }
98
    }
98
99
99
    /**
100
    /**
100
     * Main constructor -- kinda dummy because we don't validate or fill fields
101
     * Main constructor -- just store the data to be processed later
101
     *
102
     *
102
     * @param id record id
103
     * @param id record id
103
     * @param size record size
104
     * @param size record size
Lines 107-135 Link Here
107
108
108
    public ContinueRecord(short id, short size, byte [] data, int offset)
109
    public ContinueRecord(short id, short size, byte [] data, int offset)
109
    {
110
    {
110
        super(id, size, data, offset);
111
        size    = size;
112
        field_1_data = data;
111
    }
113
    }
112
114
113
    /**
115
    /**
114
     * USE ONLY within "processContinue"
116
     * USE ONLY within "processContinue"
115
     */
117
     */
116
118
117
    public byte [] serialize()
119
    private byte [] serializePC()
118
    {
120
    {
119
        byte[] retval = new byte[ field_1_data.length + 4 ];
121
        byte[] retval = new byte[ field_1_data.length + 4 ];
120
        serialize(0, retval);
122
123
        LittleEndian.putShort(retval, 0, sid);
124
        LittleEndian.putShort(retval, 2, ( short ) field_1_data.length);
125
        System.arraycopy(field_1_data, 0, retval, 4, field_1_data.length);
121
        return retval;
126
        return retval;
122
    }
127
    }
123
128
124
    public int serialize(int offset, byte [] data)
129
    public int serialize(int offset, byte [] data)
125
    {
130
    {
131
        if (field_1_data == null)
132
        {
133
            field_1_data = new byte[ 0 ];
134
        }
135
        LittleEndian.putShort(data, 0 + offset, sid);
136
        LittleEndian.putShort(data, 2 + offset, ( short ) (field_1_data.length));
137
        if (field_1_data.length > 0)
138
        {
139
            System.arraycopy(field_1_data, 0, data, 4 + offset, field_1_data.length);
140
        }
141
        return getRecordSize();
142
    }
143
144
    public int getRecordSize()
145
    {
146
        int retval = 4;
126
147
127
        LittleEndian.putShort(data, offset, sid);
148
        if (field_1_data != null)
128
        LittleEndian.putShort(data, offset + 2, ( short ) field_1_data.length);
149
        {
129
        System.arraycopy(field_1_data, 0, data, offset + 4, field_1_data.length);
150
            retval += field_1_data.length;
130
        return field_1_data.length + 4;
151
        }
131
        // throw new RecordFormatException(
152
        return retval;
132
        //    "You're not supposed to serialize Continue records like this directly");
133
    }
153
    }
134
154
135
    /**
155
    /**
Lines 183-189 Link Here
183
            // System.out.println("arraycopy(data,"+offset+",crdata,"+0+","+arraysize+");");
203
            // System.out.println("arraycopy(data,"+offset+",crdata,"+0+","+arraysize+");");
184
            offset += crdata.length;
204
            offset += crdata.length;
185
            contrec.setData(crdata);
205
            contrec.setData(crdata);
186
            crs.add(contrec.serialize());
206
            crs.add(contrec.serializePC());
187
        }
207
        }
188
        for (int cr = 0; cr < records; cr++)
208
        for (int cr = 0; cr < records; cr++)
189
        {
209
        {
Lines 215-222 Link Here
215
235
216
    protected void fillFields(byte [] ignored_parm1, short ignored_parm2)
236
    protected void fillFields(byte [] ignored_parm1, short ignored_parm2)
217
    {
237
    {
218
        this.field_1_data = ignored_parm1;
219
        // throw new RecordFormatException("Are you crazy?  Don't fill a continue record");
220
        // do nothing
238
        // do nothing
221
    }
239
    }
222
240
(-)src/java/org/apache/poi/hssf/record/Record.java (+10 lines)
Lines 222-227 Link Here
222
    }
222
    }
223
223
224
    /**
224
    /**
225
     * Does this record want to process a Continue record?
226
     *
227
     */
228
229
    public boolean isContinueRecordAware()
230
    {
231
        return false;
232
    }
233
234
    /**
225
     * Process a continuation record; default handling is to ignore
235
     * Process a continuation record; default handling is to ignore
226
     * it -- TODO add logging
236
     * it -- TODO add logging
227
     *
237
     *
(-)src/java/org/apache/poi/hssf/record/RecordFactory.java (-4 / +7 lines)
Lines 209-224 Link Here
209
209
210
                        if (record != null)
210
                        if (record != null)
211
                        {
211
                        {
212
                            if (rectype == ContinueRecord.sid &&
212
                            if (rectype == ContinueRecord.sid)
213
                                ! (last_record instanceof ContinueRecord) && // include continuation records after
214
                                ! (last_record instanceof UnknownRecord) )   // unknown records or previous continuation records
215
                            {
213
                            {
216
                                if (last_record == null)
214
                                if (last_record == null)
217
                                {
215
                                {
218
                                    throw new RecordFormatException(
216
                                    throw new RecordFormatException(
219
                                        "First record is a ContinueRecord??");
217
                                        "First record is a ContinueRecord??");
220
                                }
218
                                }
221
                                last_record.processContinueRecord(data);
219
                               if(last_record.isContinueRecordAware()){
220
                                  last_record.processContinueRecord(data);
221
                               }else{
222
                                  last_record = record;
223
                                  records.add(record);
224
                               }
222
                            }
225
                            }
223
                            else
226
                            else
224
                            {
227
                            {
(-)src/java/org/apache/poi/hssf/record/SSTDeserializer.java (+5 lines)
Lines 277-282 Link Here
277
        return byte_count / ( wideChar ? LittleEndianConsts.SHORT_SIZE : LittleEndianConsts.BYTE_SIZE );
277
        return byte_count / ( wideChar ? LittleEndianConsts.SHORT_SIZE : LittleEndianConsts.BYTE_SIZE );
278
    }
278
    }
279
279
280
    public boolean isContinueRecordAware()
281
    {
282
        return true;
283
    }
284
280
    /**
285
    /**
281
     * Process a Continue record. A Continue record for an SST record
286
     * Process a Continue record. A Continue record for an SST record
282
     * contains the same kind of data that the SST record contains,
287
     * contains the same kind of data that the SST record contains,
(-)src/java/org/apache/poi/hssf/record/SSTRecord.java (+5 lines)
Lines 531-536 Link Here
531
        return deserializer;
531
        return deserializer;
532
    }
532
    }
533
533
534
    public boolean isContinueRecordAware()
535
    {
536
        return true;
537
    }
538
534
    /**
539
    /**
535
     * Strange to handle continue records this way.  Is it a smell?
540
     * Strange to handle continue records this way.  Is it a smell?
536
     */
541
     */

Return to bug 19739