001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Continue Record - Helper class used primarily for SST Records <P>
024: * Description: handles overflow for prior record in the input
025: * stream; content is tailored to that prior record<P>
026: * @author Marc Johnson (mjohnson at apache dot org)
027: * @author Andrew C. Oliver (acoliver at apache dot org)
028: * @author Csaba Nagy (ncsaba at yahoo dot com)
029: * @version 2.0-pre
030: */
031:
032: public class ContinueRecord extends Record {
033: public final static short sid = 0x003C;
034: private byte[] field_1_data;
035:
036: /**
037: * default constructor
038: */
039:
040: public ContinueRecord() {
041: }
042:
043: /**
044: * Main constructor -- kinda dummy because we don't validate or fill fields
045: *
046: * @param in the RecordInputstream to read the record from
047: */
048:
049: public ContinueRecord(RecordInputStream in) {
050: super (in);
051: }
052:
053: /**
054: * USE ONLY within "processContinue"
055: */
056:
057: public byte[] serialize() {
058: byte[] retval = new byte[field_1_data.length + 4];
059: serialize(0, retval);
060: return retval;
061: }
062:
063: public int serialize(int offset, byte[] data) {
064:
065: LittleEndian.putShort(data, offset, sid);
066: LittleEndian.putShort(data, offset + 2,
067: (short) field_1_data.length);
068: System.arraycopy(field_1_data, 0, data, offset + 4,
069: field_1_data.length);
070: return field_1_data.length + 4;
071: // throw new RecordFormatException(
072: // "You're not supposed to serialize Continue records like this directly");
073: }
074:
075: /*
076: * @param data raw data
077: */
078:
079: public void setData(byte[] data) {
080: field_1_data = data;
081: }
082:
083: /**
084: * get the data for continuation
085: * @return byte array containing all of the continued data
086: */
087:
088: public byte[] getData() {
089: return field_1_data;
090: }
091:
092: /**
093: * Make sure we have a good id
094: *
095: * @param id the alleged id
096: */
097:
098: protected void validateSid(short id) {
099: if (id != ContinueRecord.sid) {
100: throw new RecordFormatException("Not a Continue Record");
101: }
102: }
103:
104: /**
105: * Debugging toString
106: *
107: * @return string representation
108: */
109:
110: public String toString() {
111: StringBuffer buffer = new StringBuffer();
112:
113: buffer.append("[CONTINUE RECORD]\n");
114: buffer.append(" .id = ").append(
115: Integer.toHexString(sid)).append("\n");
116: buffer.append("[/CONTINUE RECORD]\n");
117: return buffer.toString();
118: }
119:
120: public short getSid() {
121: return sid;
122: }
123:
124: /**
125: * Fill the fields. Only thing is, this record has no fields --
126: *
127: * @param in the RecordInputstream to read the record from
128: */
129:
130: protected void fillFields(RecordInputStream in) {
131: field_1_data = in.readRemainder();
132: }
133:
134: /**
135: * Clone this record.
136: */
137: public Object clone() {
138: ContinueRecord clone = new ContinueRecord();
139: clone.setData(field_1_data);
140: return clone;
141: }
142:
143: }
|