KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > textmining > text > extraction > sprm > SprmOperation


1 /* Copyright 2004 Ryan Ackley
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package org.textmining.text.extraction.sprm;
17
18 import org.apache.poi.util.BitField;
19 import org.apache.poi.util.LittleEndian;
20
21 public class SprmOperation
22 {
23   final static private BitField OP_BITFIELD = new BitField(0x1ff);
24   final static private BitField SPECIAL_BITFIELD = new BitField(0x200);
25   final static private BitField TYPE_BITFIELD = new BitField(0x1c00);
26   final static private BitField SIZECODE_BITFIELD = new BitField(0xe000);
27
28   private int _type;
29   //private boolean _variableLen;
30
private int _operation;
31   private int _operand;
32   private byte[] _varOperand;
33   private int _sizeNeeded;
34
35   public SprmOperation(byte[] grpprl, int offset)
36   {
37     short sprmStart = LittleEndian.getShort(grpprl, offset);
38     offset += 2;
39
40     _operation = OP_BITFIELD.getValue(sprmStart);
41     _type = TYPE_BITFIELD.getValue(sprmStart);
42     int sizeCode = SIZECODE_BITFIELD.getValue(sprmStart);
43
44     switch (sizeCode)
45     {
46       case 0:
47       case 1:
48         _operand = LittleEndian.getUnsignedByte(grpprl, offset);
49         _sizeNeeded = 3;
50         break;
51       case 2:
52       case 4:
53       case 5:
54         _operand = LittleEndian.getShort(grpprl, offset);
55         _sizeNeeded = 4;
56         break;
57       case 3:
58         _operand = LittleEndian.getInt(grpprl, offset);
59         _sizeNeeded = 6;
60         break;
61       case 6:
62         _varOperand = new byte[grpprl[offset++]];
63         System.arraycopy(grpprl, offset, _varOperand, 0, _varOperand.length);
64         _sizeNeeded = _varOperand.length + 3;
65         break;
66       case 7:
67         byte threeByteInt[] = new byte[4];
68         threeByteInt[0] = grpprl[offset];
69         threeByteInt[1] = grpprl[offset + 1];
70         threeByteInt[2] = grpprl[offset + 2];
71         threeByteInt[3] = (byte)0;
72         _operand = LittleEndian.getInt(threeByteInt, 0);
73         _sizeNeeded = 5;
74         break;
75
76     }
77   }
78
79   public int getType()
80   {
81     return _type;
82   }
83
84   public int getOperation()
85   {
86     return _operation;
87   }
88
89   public int getOperand()
90   {
91     return _operand;
92   }
93
94   public int size()
95   {
96     return _sizeNeeded;
97   }
98 }
Popular Tags