All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.io.classfile.constant.ClassFileConstantPool Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.io.classfile.constant;

import com.softicar.platform.common.io.classfile.ClassFileReader;
import com.softicar.platform.common.io.classfile.constants.ClassFileConstant;
import com.softicar.platform.common.io.classfile.constants.ClassFileConstantClass;
import com.softicar.platform.common.io.classfile.constants.ClassFileConstantUtf8;

public class ClassFileConstantPool {

	private final int size;
	private final ClassFileConstant[] constants;

	public ClassFileConstantPool(ClassFileReader reader) {

		this.size = reader.readInt16();
		this.constants = new ClassFileConstant[size];

		for (int i = 1; i < size; i++) {
			int typeId = reader.readInt8();
			ClassFileConstantType type = ClassFileConstantType.getById(typeId);
			constants[i] = type.parse(reader);

			if (type == ClassFileConstantType.DOUBLE || type == ClassFileConstantType.LONG) {
				// according to the standard, 8-byte constants take too indexes
				// from the standard: `In retrospect, making 8-byte constants take two constant pool entries was a poor
				// choice. `
				i++;
			}
		}
	}

	public int size() {

		return size;
	}

	public ClassFileConstant getConstant(int index) {

		return constants[index];
	}

	public ClassFileConstantClass getConstantClass(int index) {

		return (ClassFileConstantClass) constants[index];
	}

	public ClassFileConstantUtf8 getConstantUtf8(int index) {

		return (ClassFileConstantUtf8) constants[index];
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy