KickJava   Java API By Example, From Geeks To Geeks.

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


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
19
20 package org.apache.poi.hwpf.model;
21
22 import org.apache.poi.util.BitField;
23 import org.apache.poi.util.LittleEndian;
24
25 public class PieceDescriptor
26 {
27
28   short descriptor;
29    private static BitField fNoParaLast = new BitField(0x01);
30    private static BitField fPaphNil = new BitField(0x02);
31    private static BitField fCopied = new BitField(0x04);
32   int fc;
33   short prm;
34   boolean unicode;
35
36
37   public PieceDescriptor(byte[] buf, int offset)
38   {
39     descriptor = LittleEndian.getShort(buf, offset);
40     offset += LittleEndian.SHORT_SIZE;
41     fc = LittleEndian.getInt(buf, offset);
42     offset += LittleEndian.INT_SIZE;
43     prm = LittleEndian.getShort(buf, offset);
44
45     // see if this piece uses unicode.
46
if ((fc & 0x40000000) == 0)
47     {
48         unicode = true;
49     }
50     else
51     {
52         unicode = false;
53         fc &= ~(0x40000000);//gives me FC in doc stream
54
fc /= 2;
55     }
56
57   }
58
59   public int getFilePosition()
60   {
61     return fc;
62   }
63
64   public void setFilePosition(int pos)
65   {
66     fc = pos;
67   }
68
69   public boolean isUnicode()
70   {
71     return unicode;
72   }
73
74   protected byte[] toByteArray()
75   {
76     // set up the fc
77
int tempFc = fc;
78     if (!unicode)
79     {
80       tempFc *= 2;
81       tempFc |= (0x40000000);
82     }
83
84     int offset = 0;
85     byte[] buf = new byte[8];
86     LittleEndian.putShort(buf, offset, descriptor);
87     offset += LittleEndian.SHORT_SIZE;
88     LittleEndian.putInt(buf, offset, tempFc);
89     offset += LittleEndian.INT_SIZE;
90     LittleEndian.putShort(buf, offset, prm);
91
92     return buf;
93
94   }
95
96   public static int getSizeInBytes()
97   {
98     return 8;
99   }
100
101   public boolean equals(Object JavaDoc o)
102   {
103     PieceDescriptor pd = (PieceDescriptor)o;
104
105     return descriptor == pd.descriptor && prm == pd.prm && unicode == pd.unicode;
106   }
107 }
108
Popular Tags