com.gemstone.gemfire.codeAnalysis.decode.CompiledClass Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-junit Show documentation
Show all versions of gemfire-junit Show documentation
SnappyData store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.codeAnalysis.decode;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.codeAnalysis.decode.cp.Cp;
import com.gemstone.gemfire.codeAnalysis.decode.cp.CpClass;
import com.gemstone.gemfire.codeAnalysis.decode.cp.CpDouble;
import com.gemstone.gemfire.codeAnalysis.decode.cp.CpLong;
/**
* Decoder represents a jdk ClassFile header
*/
public class CompiledClass implements Comparable {
public long magic;
public int minor_version;
public int major_version;
public int constant_pool_count;
public Cp constant_pool[];
public int access_flags;
public int this_class; // ptr into constant_pool
public int super_class; // ptr into constant_pool
public int interfaces_count;
public int interfaces[];
public int fields_count;
public CompiledField fields[];
public int methods_count;
public CompiledMethod methods[];
public int attributes_count;
public CompiledAttribute attributes[];
public static CompiledClass getInstance( File classFile ) throws IOException {
FileInputStream fstream = new FileInputStream(classFile);
DataInputStream source = new DataInputStream(fstream);
CompiledClass instance = new CompiledClass(source);
fstream.close();
return instance;
}
public static CompiledClass getInstance( InputStream classStream ) throws IOException {
DataInputStream source = new DataInputStream(classStream);
CompiledClass instance = new CompiledClass(source);
classStream.close();
return instance;
}
/**
* read a ClassFile structure from the given input source (usually a file)
*/
public CompiledClass( DataInputStream source ) throws IOException {
int idx;
magic = (long)source.readInt();
minor_version = source.readUnsignedShort();
major_version = source.readUnsignedShort();
// the first constant-pool slot is reserved by Java and is not in the classes file
constant_pool_count = source.readUnsignedShort();
// read the constant pool list
constant_pool = new Cp[constant_pool_count];
constant_pool[0] = null;
for (idx=1; idx