Polishing

This commit is contained in:
Juergen Hoeller 2023-11-16 11:22:09 +01:00
parent b0e29acd23
commit 99378fe947
7 changed files with 28 additions and 27 deletions

View File

@ -33,12 +33,13 @@ import org.springframework.util.ClassUtils;
*/
class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
private static final boolean aspectjPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
AspectJAdvisorBeanRegistrationAotProcessor.class.getClassLoader());
@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (aspectJPresent) {
if (aspectjPresent) {
Class<?> beanClass = registeredBean.getBeanClass();
if (AbstractAspectJAdvisorFactory.compiledByAjc(beanClass)) {
return new AspectJAdvisorContribution(beanClass);
@ -47,6 +48,7 @@ class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotP
return null;
}
private static class AspectJAdvisorContribution implements BeanRegistrationAotContribution {
private final Class<?> beanClass;

View File

@ -40,11 +40,12 @@ import org.springframework.util.ClassUtils;
*/
class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
private static final boolean aspectJPresent = ClassUtils.isPresent(
"org.aspectj.lang.annotation.Pointcut", AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());
private static final boolean aspectJPresent = ClassUtils.isPresent("org.aspectj.lang.annotation.Pointcut",
AspectJBeanFactoryInitializationAotProcessor.class.getClassLoader());
@Nullable
@Override
@Nullable
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
if (aspectJPresent) {
return AspectDelegate.processAheadOfTime(beanFactory);
@ -52,6 +53,7 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
return null;
}
/**
* Inner class to avoid a hard dependency on AspectJ at runtime.
*/
@ -63,7 +65,6 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
List<Advisor> advisors = builder.buildAspectJAdvisors();
return (advisors.isEmpty() ? null : new AspectContribution(advisors));
}
}
@ -84,7 +85,6 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial
}
}
}
}
}

View File

@ -42,14 +42,14 @@ import org.springframework.util.MimeTypeUtils;
*/
public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuffer> {
public CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes) {
super(delimiters, stripDelimiter, mimeTypes);
}
@Override
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) {
return elementType.resolve() == CharBuffer.class && super.canDecode(elementType, mimeType);
return (elementType.resolve() == CharBuffer.class) && super.canDecode(elementType, mimeType);
}
@Override
@ -69,9 +69,8 @@ public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuf
/**
* Create a {@code CharBufferDecoder} for {@code "text/plain"}.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting input strings
*/
public static CharBufferDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);
@ -87,9 +86,8 @@ public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuf
/**
* Create a {@code CharBufferDecoder} that supports all MIME types.
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting
* input strings
* @param delimiters delimiter strings to use to split the input stream
* @param stripDelimiter whether to remove delimiters from the resulting input strings
*/
public static CharBufferDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) {
var textPlain = new MimeType("text", "plain", DEFAULT_CHARSET);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -51,8 +51,7 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
*/
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar =
new ConcurrentHashMap<>(3);
private final ConcurrentMap<Charset, Float> charsetToMaxBytesPerChar = new ConcurrentHashMap<>(3);
private CharSequenceEncoder(MimeType... mimeTypes) {
@ -105,8 +104,8 @@ public final class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
}
int calculateCapacity(CharSequence sequence, Charset charset) {
float maxBytesPerChar = this.charsetToMaxBytesPerChar
.computeIfAbsent(charset, cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesPerChar = this.charsetToMaxBytesPerChar.computeIfAbsent(charset,
cs -> cs.newEncoder().maxBytesPerChar());
float maxBytesForSequence = sequence.length() * maxBytesPerChar;
return (int) Math.ceil(maxBytesForSequence);
}

View File

@ -68,8 +68,8 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
public void subscribe(Subscriber<? super DataBuffer> subscriber) {
Objects.requireNonNull(subscriber, "Subscriber must not be null");
OutputStreamSubscription subscription = new OutputStreamSubscription(subscriber, this.outputStreamConsumer,
this.bufferFactory, this.chunkSize);
OutputStreamSubscription subscription = new OutputStreamSubscription(
subscriber, this.outputStreamConsumer, this.bufferFactory, this.chunkSize);
subscriber.onSubscribe(subscription);
this.executor.execute(subscription::invokeHandler);
@ -80,7 +80,6 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private static final Object READY = new Object();
private final Subscriber<? super DataBuffer> actual;
private final Consumer<OutputStream> outputStreamHandler;
@ -98,7 +97,6 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
private long produced;
OutputStreamSubscription(Subscriber<? super DataBuffer> actual,
Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, int chunkSize) {
@ -351,4 +349,5 @@ final class OutputStreamPublisher implements Publisher<DataBuffer> {
return res;
}
}
}

View File

@ -22,8 +22,9 @@ import io.micrometer.context.ContextSnapshotFactory;
import org.springframework.core.task.TaskDecorator;
/**
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution} of
* tasks, assisting with context propagation.
* {@link TaskDecorator} that {@link ContextSnapshot#wrap(Runnable) wraps the execution}
* of tasks, assisting with context propagation.
*
* <p>This operation is only useful when the task execution is scheduled on a different
* thread than the original call stack; this depends on the choice of
* {@link org.springframework.core.task.TaskExecutor}. This is particularly useful for
@ -39,6 +40,7 @@ public class ContextPropagatingTaskDecorator implements TaskDecorator {
private final ContextSnapshotFactory factory;
/**
* Create a new decorator that uses a default instance of the {@link ContextSnapshotFactory}.
*/
@ -54,6 +56,7 @@ public class ContextPropagatingTaskDecorator implements TaskDecorator {
this.factory = factory;
}
@Override
public Runnable decorate(Runnable runnable) {
return this.factory.captureAll().wrap(runnable);

View File

@ -54,7 +54,7 @@ public interface StreamingHttpOutputMessage extends HttpOutputMessage {
/**
* Indicates whether this body is capable of
* {@linkplain #writeTo(OutputStream) writing its data} more than
* once. Default implementation returns {@code false}.
* once. The default implementation returns {@code false}.
* @return {@code true} if this body can be written repeatedly,
* {@code false} otherwise
* @since 6.1