Skip to content

Commit

Permalink
Merge pull request #773 from mygreen/improve-urldecoder-peformance
Browse files Browse the repository at this point in the history
Improved the StrutsUrlDecoder so that charset retrieval is performed only once.
  • Loading branch information
lukaszlenart authored Oct 25, 2023
2 parents fc5d1ca + faa98d7 commit b15b83d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@

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)
Expand Down Expand Up @@ -107,7 +110,7 @@ private byte convertHexDigit(byte b) {
}

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;
}
Expand Down

0 comments on commit b15b83d

Please sign in to comment.