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:
18: package org.apache.poi.hslf.record;
19:
20: import org.apache.poi.util.LittleEndian;
21: import java.io.IOException;
22: import java.io.OutputStream;
23:
24: /**
25: * If we come across a record we know has children of (potential)
26: * interest, but where the record itself is boring, but where other
27: * records may care about where this one lives, we create one
28: * of these. It allows us to get at the children, and track where on
29: * disk this is, but not much else.
30: * Anything done using this should quite quickly be transitioned to its
31: * own proper record class!
32: *
33: * @author Nick Burch
34: */
35:
36: public class DummyPositionSensitiveRecordWithChildren extends
37: PositionDependentRecordContainer {
38: private byte[] _header;
39: private long _type;
40:
41: /**
42: * Create a new holder for a boring record with children, but with
43: * position dependent characteristics
44: */
45: protected DummyPositionSensitiveRecordWithChildren(byte[] source,
46: int start, int len) {
47: // Just grab the header, not the whole contents
48: _header = new byte[8];
49: System.arraycopy(source, start, _header, 0, 8);
50: _type = LittleEndian.getUShort(_header, 2);
51:
52: // Find our children
53: _children = Record.findChildRecords(source, start + 8, len - 8);
54: }
55:
56: /**
57: * Return the value we were given at creation
58: */
59: public long getRecordType() {
60: return _type;
61: }
62:
63: /**
64: * Write the contents of the record back, so it can be written
65: * to disk
66: */
67: public void writeOut(OutputStream out) throws IOException {
68: writeOut(_header[0], _header[1], _type, _children, out);
69: }
70: }
|