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