Use BufferedInputStream in SimpleMetaDataReader to double performance

Issue: SPR-9528
This commit is contained in:
Juergen Hoeller 2012-07-02 22:10:04 +02:00 committed by unknown
parent 309e51ba5b
commit fdb9de1445
1 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.core.type.classreading; package org.springframework.core.type.classreading;
import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -38,21 +39,25 @@ import org.springframework.core.type.ClassMetadata;
final class SimpleMetadataReader implements MetadataReader { final class SimpleMetadataReader implements MetadataReader {
private final Resource resource; private final Resource resource;
private final ClassMetadata classMetadata; private final ClassMetadata classMetadata;
private final AnnotationMetadata annotationMetadata; private final AnnotationMetadata annotationMetadata;
SimpleMetadataReader(Resource resource, ClassLoader classLoader) throws IOException { SimpleMetadataReader(Resource resource, ClassLoader classLoader) throws IOException {
InputStream is = resource.getInputStream(); InputStream is = new BufferedInputStream(resource.getInputStream());
ClassReader classReader = null; ClassReader classReader = null;
try { try {
classReader = new ClassReader(is); classReader = new ClassReader(is);
} finally { }
finally {
is.close(); is.close();
} }
AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader); AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader);
classReader.accept(visitor, true); classReader.accept(visitor, true);
this.annotationMetadata = visitor; this.annotationMetadata = visitor;
// (since AnnotationMetadataReader extends ClassMetadataReadingVisitor) // (since AnnotationMetadataReader extends ClassMetadataReadingVisitor)
this.classMetadata = visitor; this.classMetadata = visitor;
@ -70,4 +75,5 @@ final class SimpleMetadataReader implements MetadataReader {
public AnnotationMetadata getAnnotationMetadata() { public AnnotationMetadata getAnnotationMetadata() {
return this.annotationMetadata; return this.annotationMetadata;
} }
}
}