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

org.opalj.bi.reader.SkipUnknown_attributeReader.scala Maven / Gradle / Ivy

The newest version!
/* BSD 2-Clause License - see OPAL/LICENSE for details. */
package org.opalj
package bi
package reader

import java.io.DataInputStream

import org.opalj.log.OPALLogger

/**
 * Template method to skip an unknown attribute. I.e., the information will
 * not be represented at runtime.
 */
trait SkipUnknown_attributeReader
    extends Unknown_attributeAbstractions
    with ClassFileReaderConfiguration {
    this: Constant_PoolReader ⇒

    //
    // TYPE DEFINITIONS AND FACTORY METHODS
    //

    type Unknown_attribute = Null

    //
    // IMPLEMENTATION
    //

    def Unknown_attribute(
        cp:                   Constant_Pool,
        ap:                   AttributeParent,
        ap_name_index:        Constant_Pool_Index,
        ap_descriptor_index:  Constant_Pool_Index,
        attribute_name_index: Constant_Pool_Index,
        in:                   DataInputStream
    ): Null = {
        val size: Int = in.readInt
        var skipped: Int = 0
        while (skipped < size) {
            val actuallySkipped = in skipBytes (size - skipped) // skip returns a long value...
            if (actuallySkipped > 0)
                skipped += actuallySkipped
            else {
                OPALLogger.error(
                    "class file reader",
                    s"skipping over unknown attribute ${cp(attribute_name_index).asString} failed"
                )
                return null;
            }
        }
        null
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy