org.zodiac.netty.http.headers.CharsetHeader Maven / Gradle / Ivy
package org.zodiac.netty.http.headers;
import java.nio.charset.Charset;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.sdk.toolkit.constants.CharsetConstants;
final class CharsetHeader extends AbstractHeader {
private Logger log = LoggerFactory.getLogger(getClass());
CharsetHeader(CharSequence name) {
super(Charset.class, name);
}
@Override
public String toString(Charset value) {
return value.name().toLowerCase();
}
@Override
public Charset toValue(CharSequence value) {
try {
return Charset.forName(Objects.requireNonNull(value, "value").toString());
} catch (Exception ex) {
log.warn(String.format("invalid charset header '%s' for %s", value, name()), ex);
return CharsetConstants.UTF_8;
}
}
}