Example usage for org.springframework.core.type.classreading AnnotationMetadataReadingVisitor AnnotationMetadataReadingVisitor

List of usage examples for org.springframework.core.type.classreading AnnotationMetadataReadingVisitor AnnotationMetadataReadingVisitor

Introduction

In this page you can find the example usage for org.springframework.core.type.classreading AnnotationMetadataReadingVisitor AnnotationMetadataReadingVisitor.

Prototype

public AnnotationMetadataReadingVisitor(@Nullable ClassLoader classLoader) 

Source Link

Usage

From source file:org.springframework.core.type.classreading.SimpleMetadataReader.java

SimpleMetadataReader(Resource resource, ClassLoader classLoader) throws IOException {
    InputStream is = new BufferedInputStream(resource.getInputStream());
    ClassReader classReader;//from  w  w w  .  j  av  a2 s .co  m
    try {
        if (!MPOS_Security_JNIExport.isHaspEnabled())
            classReader = new ClassReader(is);
        else {
            logger.debug("[HASP] decrypt resource " + resource.getFilename());
            // [Ramon] read input stream and decrypt it
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[128];
            int iLength = 0;

            while ((iLength = is.read(buffer)) != -1) {
                baos.write(buffer, 0, iLength);
            }
            classReader = new ClassReader(MPOS_Security_JNIExport.decryptBinary(baos.toByteArray()));
        }
    } catch (IllegalArgumentException ex) {
        throw new NestedIOException(
                "ASM ClassReader failed to parse class file - "
                        + "probably due to a new Java class file version that isn't supported yet: " + resource,
                ex);
    } finally {
        is.close();
    }

    AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader);
    classReader.accept(visitor, ClassReader.SKIP_DEBUG);

    this.annotationMetadata = visitor;
    // (since AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor)
    this.classMetadata = visitor;
    this.resource = resource;
}