01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hssf.record;
18:
19: import org.apache.poi.util.LittleEndian;
20:
21: public class DrawingRecord extends Record {
22: public static final short sid = 0xEC;
23:
24: private byte[] recordData;
25: private byte[] contd;
26:
27: public DrawingRecord() {
28: }
29:
30: public DrawingRecord(RecordInputStream in) {
31: super (in);
32: }
33:
34: /**
35: * Checks the sid matches the expected side for this record
36: *
37: * @param id the expected sid.
38: */
39: protected void validateSid(short id) {
40: if (id != sid) {
41: throw new RecordFormatException("Not a MSODRAWING record");
42: }
43: }
44:
45: protected void fillFields(RecordInputStream in) {
46: recordData = in.readRemainder();
47: }
48:
49: public void processContinueRecord(byte[] record) {
50: //don't merge continue record with the drawing record, it must be serialized separately
51: contd = record;
52: }
53:
54: public int serialize(int offset, byte[] data) {
55: if (recordData == null) {
56: recordData = new byte[0];
57: }
58: LittleEndian.putShort(data, 0 + offset, sid);
59: LittleEndian.putShort(data, 2 + offset,
60: (short) (recordData.length));
61: if (recordData.length > 0) {
62: System.arraycopy(recordData, 0, data, 4 + offset,
63: recordData.length);
64: }
65: return getRecordSize();
66: }
67:
68: public int getRecordSize() {
69: int retval = 4;
70:
71: if (recordData != null) {
72: retval += recordData.length;
73: }
74: return retval;
75: }
76:
77: public short getSid() {
78: return sid;
79: }
80:
81: public byte[] getData() {
82: if (contd != null) {
83: byte[] newBuffer = new byte[recordData.length
84: + contd.length];
85: System.arraycopy(recordData, 0, newBuffer, 0,
86: recordData.length);
87: System.arraycopy(contd, 0, newBuffer, recordData.length,
88: contd.length);
89: return newBuffer;
90: } else {
91: return recordData;
92: }
93: }
94:
95: public void setData(byte[] thedata) {
96: this.recordData = thedata;
97: }
98:
99: }
|