Defer Charset.availableCharsets() call
Change the `StringHttpMessageConverter` to defer calling Charset.availableCharsets() until absolutely necessary to help improve startup times. Issue: SPR-15502
This commit is contained in:
parent
226cddadef
commit
ee40310c92
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -43,7 +43,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
|||
public static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");
|
||||
|
||||
|
||||
private final List<Charset> availableCharsets;
|
||||
private volatile List<Charset> availableCharsets;
|
||||
|
||||
private boolean writeAcceptCharset = true;
|
||||
|
||||
|
|
@ -62,7 +62,6 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
|||
*/
|
||||
public StringHttpMessageConverter(Charset defaultCharset) {
|
||||
super(defaultCharset, MediaType.TEXT_PLAIN, MediaType.ALL);
|
||||
this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -115,6 +114,10 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
|||
* @return the list of accepted charsets
|
||||
*/
|
||||
protected List<Charset> getAcceptedCharsets() {
|
||||
if (this.availableCharsets == null) {
|
||||
this.availableCharsets = new ArrayList<Charset>(
|
||||
Charset.availableCharsets().values());
|
||||
}
|
||||
return this.availableCharsets;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue