/* * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package java.lang.classfile; import java.lang.classfile.constantpool.ClassEntry; import java.lang.classfile.constantpool.ConstantPool; import java.lang.classfile.constantpool.ConstantPoolException; import java.lang.classfile.constantpool.PoolEntry; import java.lang.classfile.constantpool.Utf8Entry; import java.util.Optional; import java.util.function.Function; import jdk.internal.classfile.impl.ClassReaderImpl; /** * Advanced {@code class} file reading support for {@link AttributeMapper}s. * Supports reading arbitrary offsets within a {@code class} file and reading * data of various numeric types (e.g., {@code u2}, {@code u4}) in addition to * constant pool access. *
* All numeric values in the {@code class} file format are {@linkplain * java.nio.ByteOrder#BIG_ENDIAN big endian}. *
* Unless otherwise specified, all out-of-bounds access result in an {@link
* IllegalArgumentException} to indicate the {@code class} file data is
* malformed. Since the {@code class} file data is arbitrary, users should
* sanity-check the structural integrity of the data before attempting to
* interpret the potentially malformed data.
*
* @see AttributeMapper#readAttribute(AttributedElement, ClassReader, int)
* @since 24
*/
public sealed interface ClassReader extends ConstantPool
permits ClassReaderImpl {
// Processing context
/**
* {@return the table of custom attribute mappers} This is derived from
* the processing option {@link ClassFile.AttributeMapperOption}.
*/
Function
* In the conversions, all NaN values of the {@code float} may or may not be
* collapsed into a single {@linkplain Float#NaN "canonical" NaN value}.
*
* @param offset the offset within the {@code class} file
*/
float readFloat(int offset);
/**
* {@return the double value at the specified offset within the {@code
* class} file} Reads 8 bytes of value.
*
* In the conversions, all NaN values of the {@code double} may or may not
* be collapsed into a single {@linkplain Double#NaN "canonical" NaN value}.
*
* @param offset the offset within the {@code class} file
*/
double readDouble(int offset);
/**
* {@return a copy of the bytes at the specified range in the {@code class}
* file}
*
* @param offset the offset within the {@code class} file
* @param len the length of the range
*/
byte[] readBytes(int offset, int len);
/**
* Copy a range of bytes from the {@code class} file to a {@link BufWriter}.
*
* @param buf the {@linkplain BufWriter}
* @param offset the offset within the {@code class} file
* @param len the length of the range
*/
void copyBytesTo(BufWriter buf, int offset, int len);
}