1 23 package com.sun.enterprise.deployment.annotation.introspection; 24 25 import java.nio.channels.ReadableByteChannel ; 26 import java.nio.ByteBuffer ; 27 import java.nio.CharBuffer ; 28 import java.io.IOException ; 29 30 41 public class ClassFile { 42 43 ByteBuffer header; 44 ConstantPoolInfo constantPoolInfo = new ConstantPoolInfo(); 45 46 47 public ClassFile() { 48 header = ByteBuffer.allocate(12000); 49 } 50 51 public void setConstantPoolInfo(ConstantPoolInfo poolInfo) { 52 constantPoolInfo = poolInfo; 53 } 54 55 59 public boolean containsAnnotation(ReadableByteChannel in, long size) throws IOException { 60 61 83 header.clear(); 84 if (size!=-1 && size>header.capacity()) { 85 header = ByteBuffer.allocate((int) size); 87 } 88 long read = (long) in.read(header); 89 if (size!=-1 && read!=size) { 90 return false; 91 } 92 header.rewind(); 93 94 if (header.getInt()!=magic) { 95 return false; 96 } 97 98 majorVersion = header.getShort(); 99 minorVersion = header.getShort(); 100 int constantPoolSize = header.getShort(); 101 102 return constantPoolInfo.containsAnnotation(constantPoolSize, header); 103 104 } 105 106 public short majorVersion; 107 public short minorVersion; 108 public ConstantPoolInfo constantPool[]; 109 public short accessFlags; 110 public ConstantPoolInfo thisClass; 111 public ConstantPoolInfo superClass; 112 public ConstantPoolInfo interfaces[]; 113 120 boolean isValidClass = false; 121 122 private static final int magic = 0xCAFEBABE; 123 124 public static final int ACC_PUBLIC = 0x1; 125 public static final int ACC_PRIVATE = 0x2; 126 public static final int ACC_PROTECTED = 0x4; 127 public static final int ACC_STATIC = 0x8; 128 public static final int ACC_FINAL = 0x10; 129 public static final int ACC_SYNCHRONIZED = 0x20; 130 public static final int ACC_THREADSAFE = 0x40; 131 public static final int ACC_TRANSIENT = 0x80; 132 public static final int ACC_NATIVE = 0x100; 133 public static final int ACC_INTERFACE = 0x200; 134 public static final int ACC_ABSTRACT = 0x400; 135 136 } 137 | Popular Tags |