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.*;
021:
022: /**
023: * Represents a NoteStructure (0xD) sub record.
024: *
025: * <p>
026: * The docs say nothing about it. The length of this record is always 26 bytes.
027: * </p>
028: *
029: * @author Yegor Kozlov
030: */
031: public class NoteStructureSubRecord extends SubRecord {
032: public final static short sid = 0x0D;
033:
034: private byte[] reserved;
035:
036: /**
037: * Construct a new <code>NoteStructureSubRecord</code> and
038: * fill its data with the default values
039: */
040: public NoteStructureSubRecord() {
041: //all we know is that the the length of <code>NoteStructureSubRecord</code> is always 22 bytes
042: reserved = new byte[22];
043: }
044:
045: /**
046: * Constructs a NoteStructureSubRecord and sets its fields appropriately.
047: *
048: */
049: public NoteStructureSubRecord(RecordInputStream in) {
050: super (in);
051:
052: }
053:
054: /**
055: * Checks the sid matches the expected side for this record
056: *
057: * @param id the expected sid.
058: */
059: protected void validateSid(short id) {
060: if (id != sid) {
061: throw new RecordFormatException(
062: "Not a Note Structure record");
063: }
064: }
065:
066: /**
067: * Read the record data from the supplied <code>RecordInputStream</code>
068: */
069: protected void fillFields(RecordInputStream in) {
070: //just grab the raw data
071: reserved = in.readRemainder();
072: }
073:
074: /**
075: * Convert this record to string.
076: * Used by BiffViewer and other utulities.
077: */
078: public String toString() {
079: StringBuffer buffer = new StringBuffer();
080:
081: String nl = System.getProperty("line.separator");
082: buffer.append("[ftNts ]" + nl);
083: buffer.append(" size = ").append(getRecordSize()).append(
084: nl);
085: buffer.append(" reserved = ").append(HexDump.toHex(reserved))
086: .append(nl);
087: buffer.append("[/ftNts ]" + nl);
088: return buffer.toString();
089: }
090:
091: /**
092: * Serialize the record data into the supplied array of bytes
093: *
094: * @param offset offset in the <code>data</code>
095: * @param data the data to serialize into
096: *
097: * @return size of the record
098: */
099: public int serialize(int offset, byte[] data) {
100: LittleEndian.putShort(data, 0 + offset, sid);
101: LittleEndian.putShort(data, 2 + offset,
102: (short) (getRecordSize() - 4));
103: System.arraycopy(reserved, 0, data, offset + 4,
104: getRecordSize() - 4);
105:
106: return getRecordSize();
107: }
108:
109: /**
110: * Size of record
111: */
112: public int getRecordSize() {
113: return 4 + reserved.length;
114: }
115:
116: /**
117: * @return id of this record.
118: */
119: public short getSid() {
120: return sid;
121: }
122: }
|