Overall clean-up on Headers and its subtypes
Motivation: - There are still various inspector warnings to fix. - ValueConverter.convert() methods need to end with the type name like other methods in Headers, such as setInt() and addInt(), for more consistency Modifications: - Fix all inspector warnings - Rename ValueConverter.convert() to convert<type>() Result: - Cleaner code - Consistency
This commit is contained in:
parent
a1d7a84271
commit
36b41570a4
@ -47,12 +47,12 @@ public class DefaultHttpHeaders extends DefaultTextHeaders implements HttpHeader
|
||||
private static final class HttpHeadersValidationConverter extends DefaultTextValueTypeConverter {
|
||||
private final boolean validate;
|
||||
|
||||
public HttpHeadersValidationConverter(boolean validate) {
|
||||
HttpHeadersValidationConverter(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(Object value) {
|
||||
public CharSequence convertObject(Object value) {
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
@ -80,12 +80,90 @@ public class DefaultHttpHeaders extends DefaultTextHeaders implements HttpHeader
|
||||
|
||||
return seq;
|
||||
}
|
||||
|
||||
private static void validateValue(AsciiString seq) {
|
||||
int state = 0;
|
||||
// Start looping through each of the character
|
||||
final int start = seq.arrayOffset();
|
||||
final int end = start + seq.length();
|
||||
final byte[] array = seq.array();
|
||||
for (int index = start; index < end; index++) {
|
||||
state = validateValueChar(seq, state, (char) (array[index] & 0xFF));
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
throw new IllegalArgumentException("a header value must not end with '\\r' or '\\n':" + seq);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateValue(CharSequence seq) {
|
||||
int state = 0;
|
||||
// Start looping through each of the character
|
||||
for (int index = 0; index < seq.length(); index++) {
|
||||
state = validateValueChar(seq, state, seq.charAt(index));
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
throw new IllegalArgumentException("a header value must not end with '\\r' or '\\n':" + seq);
|
||||
}
|
||||
}
|
||||
|
||||
private static int validateValueChar(CharSequence seq, int state, char character) {
|
||||
/*
|
||||
* State:
|
||||
* 0: Previous character was neither CR nor LF
|
||||
* 1: The previous character was CR
|
||||
* 2: The previous character was LF
|
||||
*/
|
||||
if ((character & HIGHEST_INVALID_VALUE_CHAR_MASK) == 0) {
|
||||
// Check the absolutely prohibited characters.
|
||||
switch (character) {
|
||||
case 0x0b: // Vertical tab
|
||||
throw new IllegalArgumentException("a header value contains a prohibited character '\\v': " + seq);
|
||||
case '\f':
|
||||
throw new IllegalArgumentException("a header value contains a prohibited character '\\f': " + seq);
|
||||
}
|
||||
}
|
||||
|
||||
// Check the CRLF (HT | SP) pattern
|
||||
switch (state) {
|
||||
case 0:
|
||||
switch (character) {
|
||||
case '\r':
|
||||
state = 1;
|
||||
break;
|
||||
case '\n':
|
||||
state = 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
switch (character) {
|
||||
case '\n':
|
||||
state = 2;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("only '\\n' is allowed after '\\r': " + seq);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (character) {
|
||||
case '\t':
|
||||
case ' ':
|
||||
state = 0;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("only ' ' and '\\t' are allowed after '\\n': " + seq);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
static class HttpHeadersNameConverter implements NameConverter<CharSequence> {
|
||||
protected final boolean validate;
|
||||
|
||||
public HttpHeadersNameConverter(boolean validate) {
|
||||
HttpHeadersNameConverter(boolean validate) {
|
||||
this.validate = validate;
|
||||
}
|
||||
|
||||
@ -101,6 +179,47 @@ public class DefaultHttpHeaders extends DefaultTextHeaders implements HttpHeader
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private static void validateName(AsciiString name) {
|
||||
// Go through each characters in the name
|
||||
final int start = name.arrayOffset();
|
||||
final int end = start + name.length();
|
||||
final byte[] array = name.array();
|
||||
for (int index = start; index < end; index ++) {
|
||||
byte b = array[index];
|
||||
|
||||
// Check to see if the character is not an ASCII character
|
||||
if (b < 0) {
|
||||
throw new IllegalArgumentException("a header name cannot contain non-ASCII characters: " + name);
|
||||
}
|
||||
|
||||
// Check for prohibited characters.
|
||||
validateNameChar(name, b);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateName(CharSequence name) {
|
||||
// Go through each characters in the name
|
||||
for (int index = 0; index < name.length(); index++) {
|
||||
char character = name.charAt(index);
|
||||
|
||||
// Check to see if the character is not an ASCII character
|
||||
if (character > 127) {
|
||||
throw new IllegalArgumentException("a header name cannot contain non-ASCII characters: " + name);
|
||||
}
|
||||
|
||||
// Check for prohibited characters.
|
||||
validateNameChar(name, character);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateNameChar(CharSequence name, int character) {
|
||||
if ((character & HIGHEST_INVALID_NAME_CHAR_MASK) == 0 && LOOKUP_TABLE[character] != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"a header name cannot contain the following prohibited characters: =,;: \\t\\r\\n\\v\\f: " +
|
||||
name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final HttpHeadersValidationConverter
|
||||
@ -115,129 +234,13 @@ public class DefaultHttpHeaders extends DefaultTextHeaders implements HttpHeader
|
||||
}
|
||||
|
||||
public DefaultHttpHeaders(boolean validate) {
|
||||
this(true, validate ? VALIDATE_NAME_CONVERTER : NO_VALIDATE_NAME_CONVERTER);
|
||||
this(true, validate? VALIDATE_NAME_CONVERTER : NO_VALIDATE_NAME_CONVERTER);
|
||||
}
|
||||
|
||||
protected DefaultHttpHeaders(boolean validate, NameConverter<CharSequence> nameConverter) {
|
||||
super(true, validate ? VALIDATE_OBJECT_CONVERTER : NO_VALIDATE_OBJECT_CONVERTER, nameConverter);
|
||||
}
|
||||
|
||||
private static void validateName(AsciiString name) {
|
||||
// Go through each characters in the name
|
||||
final int start = name.arrayOffset();
|
||||
final int end = start + name.length();
|
||||
final byte[] array = name.array();
|
||||
for (int index = start; index < end; index ++) {
|
||||
byte b = array[index];
|
||||
|
||||
// Check to see if the character is not an ASCII character
|
||||
if (b < 0) {
|
||||
throw new IllegalArgumentException("a header name cannot contain non-ASCII characters: " + name);
|
||||
}
|
||||
|
||||
// Check for prohibited characters.
|
||||
validateNameChar(name, b);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateName(CharSequence name) {
|
||||
// Go through each characters in the name
|
||||
for (int index = 0; index < name.length(); index++) {
|
||||
char character = name.charAt(index);
|
||||
|
||||
// Check to see if the character is not an ASCII character
|
||||
if (character > 127) {
|
||||
throw new IllegalArgumentException("a header name cannot contain non-ASCII characters: " + name);
|
||||
}
|
||||
|
||||
// Check for prohibited characters.
|
||||
validateNameChar(name, character);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateNameChar(CharSequence name, int character) {
|
||||
if ((character & HIGHEST_INVALID_NAME_CHAR_MASK) == 0 && LOOKUP_TABLE[character] != 0) {
|
||||
throw new IllegalArgumentException("a header name cannot contain the following prohibited characters: "
|
||||
+ "=,;: \\t\\r\\n\\v\\f: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateValue(AsciiString seq) {
|
||||
int state = 0;
|
||||
// Start looping through each of the character
|
||||
final int start = seq.arrayOffset();
|
||||
final int end = start + seq.length();
|
||||
final byte[] array = seq.array();
|
||||
for (int index = start; index < end; index++) {
|
||||
state = validateValueChar(seq, state, (char) (array[index] & 0xFF));
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
throw new IllegalArgumentException("a header value must not end with '\\r' or '\\n':" + seq);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateValue(CharSequence seq) {
|
||||
int state = 0;
|
||||
// Start looping through each of the character
|
||||
for (int index = 0; index < seq.length(); index++) {
|
||||
state = validateValueChar(seq, state, seq.charAt(index));
|
||||
}
|
||||
|
||||
if (state != 0) {
|
||||
throw new IllegalArgumentException("a header value must not end with '\\r' or '\\n':" + seq);
|
||||
}
|
||||
}
|
||||
|
||||
private static int validateValueChar(CharSequence seq, int state, char character) {
|
||||
/*
|
||||
* State: 0: Previous character was neither CR nor LF 1: The previous character was CR 2: The previous character
|
||||
* was LF
|
||||
*/
|
||||
if ((character & HIGHEST_INVALID_VALUE_CHAR_MASK) == 0) {
|
||||
// Check the absolutely prohibited characters.
|
||||
switch (character) {
|
||||
case 0x0b: // Vertical tab
|
||||
throw new IllegalArgumentException("a header value contains a prohibited character '\\v': " + seq);
|
||||
case '\f':
|
||||
throw new IllegalArgumentException("a header value contains a prohibited character '\\f': " + seq);
|
||||
}
|
||||
}
|
||||
|
||||
// Check the CRLF (HT | SP) pattern
|
||||
switch (state) {
|
||||
case 0:
|
||||
switch (character) {
|
||||
case '\r':
|
||||
state = 1;
|
||||
break;
|
||||
case '\n':
|
||||
state = 2;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
switch (character) {
|
||||
case '\n':
|
||||
state = 2;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("only '\\n' is allowed after '\\r': " + seq);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (character) {
|
||||
case '\t':
|
||||
case ' ':
|
||||
state = 0;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("only ' ' and '\\t' are allowed after '\\n': " + seq);
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders add(CharSequence name, CharSequence value) {
|
||||
super.add(name, value);
|
||||
|
@ -15,9 +15,6 @@
|
||||
*/
|
||||
package io.netty.handler.codec.http;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.TRAILER;
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.TRANSFER_ENCODING;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.AsciiString;
|
||||
@ -25,6 +22,8 @@ import io.netty.util.internal.StringUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaders.Names.*;
|
||||
|
||||
/**
|
||||
* The default {@link LastHttpContent} implementation.
|
||||
*/
|
||||
@ -112,7 +111,7 @@ public class DefaultLastHttpContent extends DefaultHttpContent implements LastHt
|
||||
|
||||
private static final class TrailingHttpHeaders extends DefaultHttpHeaders {
|
||||
private static final class TrailingHttpHeadersNameConverter extends HttpHeadersNameConverter {
|
||||
public TrailingHttpHeadersNameConverter(boolean validate) {
|
||||
TrailingHttpHeadersNameConverter(boolean validate) {
|
||||
super(validate);
|
||||
}
|
||||
|
||||
|
@ -510,27 +510,27 @@ public interface HttpHeaders extends TextHeaders {
|
||||
public static final AsciiString WEBSOCKET = new AsciiString("WebSocket");
|
||||
/**
|
||||
* {@code "name"}
|
||||
* See {@link #HttpHeaders.Names.CONTENT_DISPOSITION}
|
||||
* See {@link Names#CONTENT_DISPOSITION}
|
||||
*/
|
||||
public static final AsciiString NAME = new AsciiString("name");
|
||||
/**
|
||||
* {@code "filename"}
|
||||
* See {@link #HttpHeaders.Names.CONTENT_DISPOSITION}
|
||||
* See {@link Names#CONTENT_DISPOSITION}
|
||||
*/
|
||||
public static final AsciiString FILENAME = new AsciiString("filename");
|
||||
/**
|
||||
* {@code "form-data"}
|
||||
* See {@link #HttpHeaders.Names.CONTENT_DISPOSITION}
|
||||
* See {@link Names#CONTENT_DISPOSITION}
|
||||
*/
|
||||
public static final AsciiString FORM_DATA = new AsciiString("form-data");
|
||||
/**
|
||||
* {@code "attachment"}
|
||||
* See {@link #HttpHeaders.Names.CONTENT_DISPOSITION}
|
||||
* See {@link Names#CONTENT_DISPOSITION}
|
||||
*/
|
||||
public static final AsciiString ATTACHMENT = new AsciiString("attachment");
|
||||
/**
|
||||
* {@code "file"}
|
||||
* See {@link #HttpHeaders.Names.CONTENT_DISPOSITION}
|
||||
* See {@link Names#CONTENT_DISPOSITION}
|
||||
*/
|
||||
public static final AsciiString FILE = new AsciiString("file");
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class DefaultSpdyHeaders extends DefaultTextHeaders implements SpdyHeader
|
||||
private static final Headers.ValueConverter<CharSequence> SPDY_VALUE_CONVERTER =
|
||||
new DefaultTextValueTypeConverter() {
|
||||
@Override
|
||||
public CharSequence convert(Object value) {
|
||||
public CharSequence convertObject(Object value) {
|
||||
CharSequence seq;
|
||||
if (value instanceof CharSequence) {
|
||||
seq = (CharSequence) value;
|
||||
|
@ -29,7 +29,7 @@ public interface Http2Headers extends BinaryHeaders {
|
||||
/**
|
||||
* HTTP/2 pseudo-headers names.
|
||||
*/
|
||||
public enum PseudoHeaderName {
|
||||
enum PseudoHeaderName {
|
||||
/**
|
||||
* {@code :method}.
|
||||
*/
|
||||
|
@ -25,13 +25,13 @@ public interface BinaryHeaders extends Headers<AsciiString> {
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface EntryVisitor extends Headers.EntryVisitor<AsciiString> {
|
||||
interface EntryVisitor extends Headers.EntryVisitor<AsciiString> {
|
||||
}
|
||||
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface NameVisitor extends Headers.NameVisitor<AsciiString> {
|
||||
interface NameVisitor extends Headers.NameVisitor<AsciiString> {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,7 @@ public interface ConvertibleHeaders<UnconvertedType, ConvertedType> extends Head
|
||||
/**
|
||||
* Interface to do conversions to and from the two generic type parameters
|
||||
*/
|
||||
public interface TypeConverter<UnconvertedType, ConvertedType> {
|
||||
interface TypeConverter<UnconvertedType, ConvertedType> {
|
||||
/**
|
||||
* Convert a native value
|
||||
* @param value The value to be converted
|
||||
@ -91,21 +91,21 @@ public interface ConvertibleHeaders<UnconvertedType, ConvertedType> extends Head
|
||||
|
||||
/**
|
||||
* Invokes {@link Headers#entries()} and lazily does a conversion on the results as they are accessed
|
||||
* @param name The name of entry to get
|
||||
*
|
||||
* @return The values corresponding to {@code name} and then lazily converted
|
||||
*/
|
||||
List<Map.Entry<ConvertedType, ConvertedType>> entriesConverted();
|
||||
|
||||
/**
|
||||
* Invokes {@link Headers#iterator()} and lazily does a conversion on the results as they are accessed
|
||||
* @param name The name of entry to get
|
||||
*
|
||||
* @return Iterator which will provide converted values corresponding to {@code name}
|
||||
*/
|
||||
Iterator<Entry<ConvertedType, ConvertedType>> iteratorConverted();
|
||||
|
||||
/**
|
||||
* Invokes {@link Headers#names()} and does a conversion on the results
|
||||
* @param name The name of entry to get
|
||||
*
|
||||
* @return The values corresponding to {@code name} and then converted
|
||||
*/
|
||||
Set<ConvertedType> namesAndConvert(Comparator<ConvertedType> comparator);
|
||||
|
@ -14,11 +14,12 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import static io.netty.handler.codec.AsciiString.CASE_INSENSITIVE_ORDER;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import static io.netty.handler.codec.AsciiString.*;
|
||||
|
||||
public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements BinaryHeaders {
|
||||
private static final HashCodeGenerator<AsciiString> ASCII_HASH_CODE_GENERATOR =
|
||||
new HashCodeGenerator<AsciiString>() {
|
||||
@ -30,42 +31,43 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
|
||||
|
||||
private static final ValueConverter<AsciiString> OBJECT_TO_ASCII = new ValueConverter<AsciiString>() {
|
||||
@Override
|
||||
public AsciiString convert(Object value) {
|
||||
public AsciiString convertObject(Object value) {
|
||||
if (value instanceof AsciiString) {
|
||||
return (AsciiString) value;
|
||||
} else if (value instanceof CharSequence) {
|
||||
}
|
||||
if (value instanceof CharSequence) {
|
||||
return new AsciiString((CharSequence) value);
|
||||
}
|
||||
return new AsciiString(value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(int value) {
|
||||
public AsciiString convertInt(int value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(long value) {
|
||||
public AsciiString convertLong(long value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(double value) {
|
||||
public AsciiString convertDouble(double value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(char value) {
|
||||
public AsciiString convertChar(char value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(boolean value) {
|
||||
public AsciiString convertBoolean(boolean value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(float value) {
|
||||
public AsciiString convertFloat(float value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(short value) {
|
||||
public AsciiString convertShort(short value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
@ -120,7 +122,7 @@ public class DefaultBinaryHeaders extends DefaultHeaders<AsciiString> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsciiString convert(byte value) {
|
||||
public AsciiString convertByte(byte value) {
|
||||
return new AsciiString(String.valueOf(value));
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class DefaultConvertibleHeaders<UnconvertedType, ConvertedType> extends D
|
||||
}
|
||||
|
||||
private final class ConvertedIterator implements Iterator<Entry<ConvertedType, ConvertedType>> {
|
||||
private Iterator<Entry<UnconvertedType, UnconvertedType>> iter = iterator();
|
||||
private final Iterator<Entry<UnconvertedType, UnconvertedType>> iter = iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@ -146,7 +146,7 @@ public class DefaultConvertibleHeaders<UnconvertedType, ConvertedType> extends D
|
||||
private ConvertedType name;
|
||||
private ConvertedType value;
|
||||
|
||||
public ConvertedEntry(Entry<UnconvertedType, UnconvertedType> entry) {
|
||||
ConvertedEntry(Entry<UnconvertedType, UnconvertedType> entry) {
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import static io.netty.util.internal.ObjectUtil.checkNotNull;
|
||||
import io.netty.util.collection.CollectionUtils;
|
||||
import io.netty.util.collection.IntObjectHashMap;
|
||||
import io.netty.util.collection.IntObjectMap;
|
||||
@ -39,6 +38,8 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static io.netty.util.internal.ObjectUtil.*;
|
||||
|
||||
public class DefaultHeaders<T> implements Headers<T> {
|
||||
/**
|
||||
* Allows users of this interface to specify a hash code other than the default {@link Object#hashCode()}
|
||||
@ -85,7 +86,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
private final EntryVisitor<T> setAllVisitor = new EntryVisitor<T>() {
|
||||
@Override
|
||||
public boolean visit(Entry<T, T> entry) {
|
||||
DefaultHeaders.this.set(entry.getKey(), entry.getValue());
|
||||
set(entry.getKey(), entry.getValue());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -93,7 +94,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
private final EntryVisitor<T> addAllVisitor = new EntryVisitor<T>() {
|
||||
@Override
|
||||
public boolean visit(Entry<T, T> entry) {
|
||||
DefaultHeaders.this.add(entry.getKey(), entry.getValue());
|
||||
add(entry.getKey(), entry.getValue());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -335,47 +336,47 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
|
||||
@Override
|
||||
public boolean containsObject(T name, Object value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsBoolean(T name, int value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsByte(T name, byte value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsChar(T name, char value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsShort(T name, byte value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsInt(T name, int value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsLong(T name, long value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsFloat(T name, float value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsDouble(T name, double value) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return contains(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -412,7 +413,8 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
@Override
|
||||
public boolean containsObject(T name, Object value, Comparator<? super T> keyComparator,
|
||||
Comparator<? super T> valueComparator) {
|
||||
return contains(name, valueConverter.convert(checkNotNull(value, "value")), keyComparator, valueComparator);
|
||||
return contains(
|
||||
name, valueConverter.convertObject(checkNotNull(value, "value")), keyComparator, valueComparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -495,7 +497,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
|
||||
@Override
|
||||
public Headers<T> addObject(T name, Object value) {
|
||||
return add(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return add(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -509,7 +511,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
if (o == null) {
|
||||
break;
|
||||
}
|
||||
T converted = valueConverter.convert(o);
|
||||
T converted = valueConverter.convertObject(o);
|
||||
checkNotNull(converted, "converted");
|
||||
add0(h, i, name, converted);
|
||||
}
|
||||
@ -527,7 +529,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
if (o == null) {
|
||||
break;
|
||||
}
|
||||
T converted = valueConverter.convert(o);
|
||||
T converted = valueConverter.convertObject(o);
|
||||
checkNotNull(converted, "converted");
|
||||
add0(h, i, name, converted);
|
||||
}
|
||||
@ -536,42 +538,42 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
|
||||
@Override
|
||||
public Headers<T> addInt(T name, int value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertInt(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addLong(T name, long value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertLong(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addDouble(T name, double value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertDouble(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addChar(T name, char value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertChar(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addBoolean(T name, boolean value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertBoolean(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addFloat(T name, float value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertFloat(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addByte(T name, byte value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertByte(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> addShort(T name, short value) {
|
||||
return add(name, valueConverter.convert(value));
|
||||
return add(name, valueConverter.convertShort(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -631,7 +633,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
|
||||
@Override
|
||||
public Headers<T> setObject(T name, Object value) {
|
||||
return set(name, valueConverter.convert(checkNotNull(value, "value")));
|
||||
return set(name, valueConverter.convertObject(checkNotNull(value, "value")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -646,7 +648,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
if (o == null) {
|
||||
break;
|
||||
}
|
||||
T converted = valueConverter.convert(o);
|
||||
T converted = valueConverter.convertObject(o);
|
||||
checkNotNull(converted, "converted");
|
||||
add0(h, i, name, converted);
|
||||
}
|
||||
@ -666,7 +668,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
if (o == null) {
|
||||
break;
|
||||
}
|
||||
T converted = valueConverter.convert(o);
|
||||
T converted = valueConverter.convertObject(o);
|
||||
checkNotNull(converted, "converted");
|
||||
add0(h, i, name, converted);
|
||||
}
|
||||
@ -676,42 +678,42 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
|
||||
@Override
|
||||
public Headers<T> setInt(T name, int value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertInt(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setLong(T name, long value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertLong(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setDouble(T name, double value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertDouble(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setFloat(T name, float value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertFloat(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setChar(T name, char value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertChar(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setBoolean(T name, boolean value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertBoolean(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setByte(T name, byte value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertByte(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers<T> setShort(T name, short value) {
|
||||
return set(name, valueConverter.convert(value));
|
||||
return set(name, valueConverter.convertShort(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -799,7 +801,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToBoolean(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -818,7 +820,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToByte(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -837,7 +839,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToChar(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -856,7 +858,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToShort(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -875,7 +877,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToInt(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -894,7 +896,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToLong(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -913,7 +915,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToFloat(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -932,7 +934,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToDouble(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -951,7 +953,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToTimeMillis(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -970,7 +972,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToBoolean(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -989,7 +991,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToByte(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1008,7 +1010,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToChar(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1027,7 +1029,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToShort(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1046,7 +1048,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToInt(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1065,7 +1067,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToLong(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1084,7 +1086,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToFloat(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1103,7 +1105,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToDouble(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1122,7 +1124,7 @@ public class DefaultHeaders<T> implements Headers<T> {
|
||||
}
|
||||
try {
|
||||
return valueConverter.convertToTimeMillis(v);
|
||||
} catch (Throwable t) {
|
||||
} catch (Throwable ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@
|
||||
|
||||
package io.netty.handler.codec;
|
||||
|
||||
import static io.netty.handler.codec.AsciiString.CHARSEQUENCE_CASE_INSENSITIVE_ORDER;
|
||||
import static io.netty.handler.codec.AsciiString.CHARSEQUENCE_CASE_SENSITIVE_ORDER;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Comparator;
|
||||
|
||||
import static io.netty.handler.codec.AsciiString.*;
|
||||
|
||||
public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence, String> implements TextHeaders {
|
||||
private static final HashCodeGenerator<CharSequence> CHARSEQUECE_CASE_INSENSITIVE_HASH_CODE_GENERATOR =
|
||||
new HashCodeGenerator<CharSequence>() {
|
||||
@ -42,7 +42,7 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
|
||||
|
||||
public static class DefaultTextValueTypeConverter implements ValueConverter<CharSequence> {
|
||||
@Override
|
||||
public CharSequence convert(Object value) {
|
||||
public CharSequence convertObject(Object value) {
|
||||
if (value instanceof CharSequence) {
|
||||
return (CharSequence) value;
|
||||
}
|
||||
@ -50,32 +50,32 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(int value) {
|
||||
public CharSequence convertInt(int value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(long value) {
|
||||
public CharSequence convertLong(long value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(double value) {
|
||||
public CharSequence convertDouble(double value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(char value) {
|
||||
public CharSequence convertChar(char value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(boolean value) {
|
||||
public CharSequence convertBoolean(boolean value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(float value) {
|
||||
public CharSequence convertFloat(float value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(byte value) {
|
||||
public CharSequence convertByte(byte value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public class DefaultTextHeaders extends DefaultConvertibleHeaders<CharSequence,
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence convert(short value) {
|
||||
public CharSequence convertShort(short value) {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
|
@ -505,12 +505,12 @@ public class EmptyHeaders<T> implements Headers<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<T, T> forEachEntry(io.netty.handler.codec.Headers.EntryVisitor<T> visitor) throws Exception {
|
||||
public Entry<T, T> forEachEntry(Headers.EntryVisitor<T> visitor) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T forEachName(io.netty.handler.codec.Headers.NameVisitor<T> visitor) throws Exception {
|
||||
public T forEachName(Headers.NameVisitor<T> visitor) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface EntryVisitor<T> {
|
||||
interface EntryVisitor<T> {
|
||||
/**
|
||||
* @return <ul>
|
||||
* <li>{@code true} if the processor wants to continue the loop and handle the entry.</li>
|
||||
@ -38,7 +38,7 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface NameVisitor<T> {
|
||||
interface NameVisitor<T> {
|
||||
/**
|
||||
* @return <ul>
|
||||
* <li>{@code true} if the processor wants to continue the loop and handle the entry.</li>
|
||||
@ -51,40 +51,40 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
|
||||
/**
|
||||
* Converts to/from a generic object to the type of the name for this map
|
||||
*/
|
||||
public interface ValueConverter<T> {
|
||||
T convert(Object value);
|
||||
interface ValueConverter<T> {
|
||||
T convertObject(Object value);
|
||||
|
||||
T convert(boolean value);
|
||||
T convertBoolean(boolean value);
|
||||
|
||||
boolean convertToBoolean(T value);
|
||||
|
||||
T convert(byte value);
|
||||
T convertByte(byte value);
|
||||
|
||||
byte convertToByte(T value);
|
||||
|
||||
T convert(char value);
|
||||
T convertChar(char value);
|
||||
|
||||
char convertToChar(T value);
|
||||
|
||||
T convert(short value);
|
||||
T convertShort(short value);
|
||||
|
||||
short convertToShort(T value);
|
||||
|
||||
T convert(int value);
|
||||
T convertInt(int value);
|
||||
|
||||
int convertToInt(T value);
|
||||
|
||||
T convert(long value);
|
||||
T convertLong(long value);
|
||||
|
||||
long convertToLong(T value);
|
||||
|
||||
long convertToTimeMillis(T value);
|
||||
|
||||
T convert(float value);
|
||||
T convertFloat(float value);
|
||||
|
||||
float convertToFloat(T value);
|
||||
|
||||
T convert(double value);
|
||||
T convertDouble(double value);
|
||||
|
||||
double convertToDouble(T value);
|
||||
}
|
||||
@ -1042,9 +1042,9 @@ public interface Headers<T> extends Iterable<Map.Entry<T, T>> {
|
||||
Headers<T> set(Headers<T> headers);
|
||||
|
||||
/**
|
||||
* Retains all current headers but calls {@link #set(AsciiString, Object)} for each entry in {@code headers}
|
||||
* Retains all current headers but calls {@link #set(Object, Object)} for each entry in {@code headers}
|
||||
*
|
||||
* @param headers The headers used to {@link #set(AsciiString, Object)} values in this instance
|
||||
* @param headers The headers used to {@link #set(Object, Object)} values in this instance
|
||||
* @return {@code this}
|
||||
*/
|
||||
Headers<T> setAll(Headers<T> headers);
|
||||
|
@ -19,7 +19,7 @@ package io.netty.handler.codec;
|
||||
/**
|
||||
* A typical string multimap used by text protocols such as HTTP for the representation of arbitrary key-value data. One
|
||||
* thing to note is that it uses {@link CharSequence} as its primary key and value type rather than {@link String}. When
|
||||
* you invoke the operations that produce {@link String}s such as {@link #get(CharSequence)}, a {@link CharSequence} is
|
||||
* you invoke the operations that produce {@link String}s such as {@link #get(Object)}, a {@link CharSequence} is
|
||||
* implicitly converted to a {@link String}. This is particularly useful for speed optimization because this multimap
|
||||
* can hold a special {@link CharSequence} implementation that a codec can treat specially, such as {@link CharSequence}
|
||||
* .
|
||||
@ -28,13 +28,13 @@ public interface TextHeaders extends ConvertibleHeaders<CharSequence, String> {
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface EntryVisitor extends Headers.EntryVisitor<CharSequence> {
|
||||
interface EntryVisitor extends Headers.EntryVisitor<CharSequence> {
|
||||
}
|
||||
|
||||
/**
|
||||
* A visitor that helps reduce GC pressure while iterating over a collection of {@link Headers}.
|
||||
*/
|
||||
public interface NameVisitor extends Headers.NameVisitor<CharSequence> {
|
||||
interface NameVisitor extends Headers.NameVisitor<CharSequence> {
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user