1 2 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 if ((fc & 0x40000000) == 0) 47 { 48 unicode = true; 49 } 50 else 51 { 52 unicode = false; 53 fc &= ~(0x40000000); 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 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 o) 102 { 103 PieceDescriptor pd = (PieceDescriptor)o; 104 105 return descriptor == pd.descriptor && prm == pd.prm && unicode == pd.unicode; 106 } 107 } 108 | Popular Tags |