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.hwpf.model;
19:
20: import java.io.IOException;
21:
22: import org.apache.poi.util.LittleEndian;
23:
24: import org.apache.poi.hwpf.model.io.HWPFOutputStream;
25:
26: class FIBShortHandler {
27: public final static int MAGICCREATED = 0;
28: public final static int MAGICREVISED = 1;
29: public final static int MAGICCREATEDPRIVATE = 2;
30: public final static int MAGICREVISEDPRIVATE = 3;
31: public final static int LIDFE = 13;
32:
33: final static int START = 0x20;
34:
35: short[] _shorts;
36:
37: public FIBShortHandler(byte[] mainStream) {
38: int offset = START;
39: int shortCount = LittleEndian.getShort(mainStream, offset);
40: offset += LittleEndian.SHORT_SIZE;
41: _shorts = new short[shortCount];
42:
43: for (int x = 0; x < shortCount; x++) {
44: _shorts[x] = LittleEndian.getShort(mainStream, offset);
45: offset += LittleEndian.SHORT_SIZE;
46: }
47: }
48:
49: public short getShort(int shortCode) {
50: return _shorts[shortCode];
51: }
52:
53: int sizeInBytes() {
54: return (_shorts.length * LittleEndian.SHORT_SIZE)
55: + LittleEndian.SHORT_SIZE;
56: }
57:
58: void serialize(byte[] mainStream) throws IOException {
59: int offset = START;
60: LittleEndian.putShort(mainStream, offset,
61: (short) _shorts.length);
62: offset += LittleEndian.SHORT_SIZE;
63: //mainStream.write(holder);
64:
65: for (int x = 0; x < _shorts.length; x++) {
66: LittleEndian.putShort(mainStream, offset, _shorts[x]);
67: offset += LittleEndian.SHORT_SIZE;
68: }
69: }
70:
71: }
|