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.hslf.record;
019:
020: import java.io.IOException;
021: import java.io.OutputStream;
022:
023: import org.apache.poi.util.LittleEndian;
024:
025: /**
026: * Tne atom that holds the seed info used by a ExObjList
027: *
028: * @author Nick Burch
029: */
030:
031: public class ExObjListAtom extends RecordAtom {
032: /**
033: * Record header.
034: */
035: private byte[] _header;
036:
037: /**
038: * Record data.
039: */
040: private byte[] _data;
041:
042: /**
043: * Constructs a brand new link related atom record.
044: */
045: protected ExObjListAtom() {
046: _header = new byte[8];
047: _data = new byte[4];
048:
049: LittleEndian.putShort(_header, 2, (short) getRecordType());
050: LittleEndian.putInt(_header, 4, _data.length);
051:
052: // It is fine for the other values to be zero
053: }
054:
055: /**
056: * Constructs the link related atom record from its
057: * source data.
058: *
059: * @param source the source data as a byte array.
060: * @param start the start offset into the byte array.
061: * @param len the length of the slice in the byte array.
062: */
063: protected ExObjListAtom(byte[] source, int start, int len) {
064: // Get the header.
065: _header = new byte[8];
066: System.arraycopy(source, start, _header, 0, 8);
067:
068: // Get the record data.
069: _data = new byte[len - 8];
070: System.arraycopy(source, start + 8, _data, 0, len - 8);
071:
072: // Must be at least 4 bytes long
073: if (_data.length < 4) {
074: throw new IllegalArgumentException(
075: "The length of the data for a ExObjListAtom must be at least 4 bytes, but was only "
076: + _data.length);
077: }
078: }
079:
080: /**
081: * Gets the object ID seed, which will be used as the unique
082: * OLE identifier for the next OLE object added
083: * @return the object ID seed
084: */
085: public long getObjectIDSeed() {
086: return LittleEndian.getUInt(_data, 0);
087: }
088:
089: /**
090: * Sets the object ID seed
091: * @param seed the new ID seed
092: */
093: public void setObjectIDSeed(int seed) {
094: LittleEndian.putInt(_data, 0, seed);
095: }
096:
097: /**
098: * Gets the record type.
099: * @return the record type.
100: */
101: public long getRecordType() {
102: return RecordTypes.ExObjListAtom.typeID;
103: }
104:
105: /**
106: * Write the contents of the record back, so it can be written
107: * to disk
108: *
109: * @param out the output stream to write to.
110: * @throws IOException if an error occurs.
111: */
112: public void writeOut(OutputStream out) throws IOException {
113: out.write(_header);
114: out.write(_data);
115: }
116: }
|