Merge pull request #773 from mygreen/improve-urldecoder-peformance

Improved the StrutsUrlDecoder so that charset retrieval is performed only once.
This commit is contained in:
Lukasz Lenart
2023-10-25 12:12:44 +02:00
committed by GitHub
@@ -27,11 +27,14 @@ import org.apache.struts2.StrutsConstants;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Collection;
public class StrutsUrlDecoder implements UrlDecoder {
private static final Logger LOG = LogManager.getLogger(StrutsUrlDecoder.class);
private static final Collection<Charset> AVAILABLE_CHARSETS = Charset.availableCharsets().values();
private String encoding = "UTF-8";
@Inject(value = StrutsConstants.STRUTS_I18N_ENCODING, required = false)
@@ -107,7 +110,7 @@ public class StrutsUrlDecoder implements UrlDecoder {
}
private Charset getCharset(String encoding) throws UnsupportedEncodingException {
for (Charset charset : Charset.availableCharsets().values()) {
for (Charset charset : AVAILABLE_CHARSETS) {
if (encoding.equalsIgnoreCase(charset.name())) {
return charset;
}