KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > FIBShortHandler


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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 JavaDoc;
21
22 import org.apache.poi.util.LittleEndian;
23
24 import org.apache.poi.hwpf.model.io.HWPFOutputStream;
25
26 class FIBShortHandler
27 {
28   public final static int MAGICCREATED = 0;
29   public final static int MAGICREVISED = 1;
30   public final static int MAGICCREATEDPRIVATE = 2;
31   public final static int MAGICREVISEDPRIVATE = 3;
32   public final static int LIDFE = 13;
33
34   final static int START = 0x20;
35
36   short[] _shorts;
37
38   public FIBShortHandler(byte[] mainStream)
39   {
40     int offset = START;
41     int shortCount = LittleEndian.getShort(mainStream, offset);
42     offset += LittleEndian.SHORT_SIZE;
43     _shorts = new short[shortCount];
44
45     for (int x = 0; x < shortCount; x++)
46     {
47       _shorts[x] = LittleEndian.getShort(mainStream, offset);
48       offset += LittleEndian.SHORT_SIZE;
49     }
50   }
51
52   public short getShort(int shortCode)
53   {
54     return _shorts[shortCode];
55   }
56
57   int sizeInBytes()
58   {
59     return (_shorts.length * LittleEndian.SHORT_SIZE) + LittleEndian.SHORT_SIZE;
60   }
61
62   void serialize(byte[] mainStream)
63     throws IOException JavaDoc
64   {
65     int offset = START;
66     LittleEndian.putShort(mainStream, offset, (short)_shorts.length);
67     offset += LittleEndian.SHORT_SIZE;
68     //mainStream.write(holder);
69

70     for (int x = 0; x < _shorts.length; x++)
71     {
72       LittleEndian.putShort(mainStream, offset, _shorts[x]);
73       offset += LittleEndian.SHORT_SIZE;
74     }
75   }
76
77
78 }
79
Popular Tags