1 11 package org.eclipse.jdt.internal.compiler.classfmt; 12 13 abstract public class ClassFileStruct { 14 byte[] reference; 15 int[] constantPoolOffsets; 16 int structOffset; 17 public ClassFileStruct(byte[] classFileBytes, int[] offsets, int offset) { 18 reference = classFileBytes; 19 constantPoolOffsets = offsets; 20 structOffset = offset; 21 } 22 public double doubleAt(int relativeOffset) { 23 return (Double.longBitsToDouble(this.i8At(relativeOffset))); 24 } 25 public float floatAt(int relativeOffset) { 26 return (Float.intBitsToFloat(this.i4At(relativeOffset))); 27 } 28 public int i4At(int relativeOffset) { 29 int position = relativeOffset + structOffset; 30 return ((reference[position++] & 0xFF) << 24) | ((reference[position++] & 0xFF) << 16) | ((reference[position++] & 0xFF) << 8) + (reference[position] & 0xFF); 31 } 32 public long i8At(int relativeOffset) { 33 int position = relativeOffset + structOffset; 34 return (((long) (reference[position++] & 0xFF)) << 56) 35 | (((long) (reference[position++] & 0xFF)) << 48) 36 | (((long) (reference[position++] & 0xFF)) << 40) 37 | (((long) (reference[position++] & 0xFF)) << 32) 38 | (((long) (reference[position++] & 0xFF)) << 24) 39 | (((long) (reference[position++] & 0xFF)) << 16) 40 | (((long) (reference[position++] & 0xFF)) << 8) 41 | (reference[position++] & 0xFF); 42 } 43 protected void reset() { 44 this.reference = null; 45 this.constantPoolOffsets = null; 46 } 47 public int u1At(int relativeOffset) { 48 return (reference[relativeOffset + structOffset] & 0xFF); 49 } 50 public int u2At(int relativeOffset) { 51 int position = relativeOffset + structOffset; 52 return ((reference[position++] & 0xFF) << 8) | (reference[position] & 0xFF); 53 } 54 public long u4At(int relativeOffset) { 55 int position = relativeOffset + structOffset; 56 return (((reference[position++] & 0xFFL) << 24) | ((reference[position++] & 0xFF) << 16) | ((reference[position++] & 0xFF) << 8) | (reference[position] & 0xFF)); 57 } 58 public char[] utf8At(int relativeOffset, int bytesAvailable) { 59 int length = bytesAvailable; 60 char outputBuf[] = new char[bytesAvailable]; 61 int outputPos = 0; 62 int readOffset = this.structOffset + relativeOffset; 63 64 while (length != 0) { 65 int x = this.reference[readOffset++] & 0xFF; 66 length--; 67 if ((0x80 & x) != 0) { 68 if ((x & 0x20) != 0) { 69 length-=2; 70 x = ((x & 0xF) << 12) | ((this.reference[readOffset++] & 0x3F) << 6) | (this.reference[readOffset++] & 0x3F); 71 } else { 72 length--; 73 x = ((x & 0x1F) << 6) | (this.reference[readOffset++] & 0x3F); 74 } 75 } 76 outputBuf[outputPos++] = (char) x; 77 } 78 79 if (outputPos != bytesAvailable) { 80 System.arraycopy(outputBuf, 0, (outputBuf = new char[outputPos]), 0, outputPos); 81 } 82 return outputBuf; 83 } 84 } 85 | Popular Tags |