Class ReadOnlyHttpHeaders
java.lang.Object
io.netty.handler.codec.http.HttpHeaders
io.netty.handler.codec.http.ReadOnlyHttpHeaders
- All Implemented Interfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String, java.lang.String>>
A variant of
HttpHeaders which only supports read-only methods.
Any array passed to this class may be used directly in the underlying data structures of this class. If these arrays may be modified it is the caller's responsibility to supply this class with a copy of the array.
This may be a good alternative to DefaultHttpHeaders if your have a fixed set of headers which will not
change.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classprivate final classprivate final classprivate final classNested classes/interfaces inherited from class HttpHeaders
HttpHeaders.Names, HttpHeaders.Values -
Field Summary
FieldsFields inherited from class HttpHeaders
EMPTY_HEADERS -
Constructor Summary
ConstructorsConstructorDescriptionReadOnlyHttpHeaders(boolean validateHeaders, java.lang.CharSequence... nameValuePairs) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionadd(java.lang.String name, java.lang.Iterable<?> values) add(java.lang.String name, java.lang.Object value) addInt(java.lang.CharSequence name, int value) Add thenametovalue.addShort(java.lang.CharSequence name, short value) Add thenametovalue.clear()Removes all headers from thisHttpMessage.booleancontains(java.lang.String name) booleancontains(java.lang.String name, java.lang.String value, boolean ignoreCase) booleancontainsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase) Returnstrueif a header with thenameandvalueexists,falseotherwise.java.util.List<java.util.Map.Entry<java.lang.String, java.lang.String>> entries()Returns a newListthat contains all headers in this object.java.lang.Stringget(java.lang.String name) private java.lang.CharSequenceget0(java.lang.CharSequence name) java.util.List<java.lang.String> getAll(java.lang.String name) java.lang.IntegergetInt(java.lang.CharSequence name) Returns the integer value of a header with the specified name.intgetInt(java.lang.CharSequence name, int defaultValue) Returns the integer value of a header with the specified name.java.lang.ShortgetShort(java.lang.CharSequence name) Returns the short value of a header with the specified name.shortgetShort(java.lang.CharSequence name, short defaultValue) Returns the short value of a header with the specified name.java.lang.LonggetTimeMillis(java.lang.CharSequence name) Returns the date value of a header with the specified name.longgetTimeMillis(java.lang.CharSequence name, long defaultValue) Returns the date value of a header with the specified name.booleanisEmpty()Checks if no header exists.java.util.Iterator<java.util.Map.Entry<java.lang.String, java.lang.String>> iterator()java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence, java.lang.CharSequence>> java.util.Set<java.lang.String> names()Returns a newSetthat contains the names of all headers in this object.private static java.lang.IllegalArgumentExceptionremove(java.lang.String name) set(java.lang.String name, java.lang.Iterable<?> values) set(java.lang.String name, java.lang.Object value) setInt(java.lang.CharSequence name, int value) Set thenametovalue.setShort(java.lang.CharSequence name, short value) Set thenametovalue.intsize()Returns the number of headers in this object.private static voidvalidateHeaders(java.lang.CharSequence... keyValuePairs) java.util.Iterator<java.lang.CharSequence> valueCharSequenceIterator(java.lang.CharSequence name) Equivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.java.util.Iterator<java.lang.String> valueStringIterator(java.lang.CharSequence name) Equivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.Methods inherited from class HttpHeaders
add, add, add, addDateHeader, addDateHeader, addHeader, addHeader, addIntHeader, addIntHeader, clearHeaders, contains, contains, containsCommaSeparatedTrimmed, copy, encodeAscii, equalsIgnoreCase, get, get, getAll, getAllAsString, getAsString, getContentLength, getContentLength, getDate, getDate, getDateHeader, getDateHeader, getDateHeader, getDateHeader, getHeader, getHeader, getHeader, getHeader, getHost, getHost, getIntHeader, getIntHeader, getIntHeader, getIntHeader, is100ContinueExpected, isContentLengthSet, isKeepAlive, isTransferEncodingChunked, iteratorAsString, newEntity, remove, removeHeader, removeHeader, removeTransferEncodingChunked, set, set, set, set100ContinueExpected, set100ContinueExpected, setAll, setContentLength, setDate, setDateHeader, setDateHeader, setDateHeader, setDateHeader, setHeader, setHeader, setHeader, setHeader, setHost, setHost, setIntHeader, setIntHeader, setIntHeader, setIntHeader, setKeepAlive, setTransferEncodingChunked, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
nameValuePairs
private final java.lang.CharSequence[] nameValuePairs
-
-
Constructor Details
-
ReadOnlyHttpHeaders
public ReadOnlyHttpHeaders(boolean validateHeaders, java.lang.CharSequence... nameValuePairs) Create a new instance.- Parameters:
validateHeaders-trueto validate the contents of each header name and value.nameValuePairs- An array of the structure[<name,value>,<name,value>,...]. A copy will NOT be made of this array. If the contents of this array may be modified externally you are responsible for passing in a copy.
-
-
Method Details
-
newInvalidArraySizeException
private static java.lang.IllegalArgumentException newInvalidArraySizeException() -
validateHeaders
private static void validateHeaders(java.lang.CharSequence... keyValuePairs) -
get0
private java.lang.CharSequence get0(java.lang.CharSequence name) -
get
public java.lang.String get(java.lang.String name) - Specified by:
getin classHttpHeaders- See Also:
-
getInt
public java.lang.Integer getInt(java.lang.CharSequence name) Description copied from class:HttpHeadersReturns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getIntin classHttpHeaders- Parameters:
name- the name of the header to search- Returns:
- the first header value if the header is found and its value is an integer.
nullif there's no such header or its value is not an integer.
-
getInt
public int getInt(java.lang.CharSequence name, int defaultValue) Description copied from class:HttpHeadersReturns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getIntin classHttpHeaders- Parameters:
name- the name of the header to searchdefaultValue- the default value- Returns:
- the first header value if the header is found and its value is an integer.
defaultValueif there's no such header or its value is not an integer.
-
getShort
public java.lang.Short getShort(java.lang.CharSequence name) Description copied from class:HttpHeadersReturns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getShortin classHttpHeaders- Parameters:
name- the name of the header to search- Returns:
- the first header value if the header is found and its value is a short.
nullif there's no such header or its value is not a short.
-
getShort
public short getShort(java.lang.CharSequence name, short defaultValue) Description copied from class:HttpHeadersReturns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getShortin classHttpHeaders- Parameters:
name- the name of the header to searchdefaultValue- the default value- Returns:
- the first header value if the header is found and its value is a short.
defaultValueif there's no such header or its value is not a short.
-
getTimeMillis
public java.lang.Long getTimeMillis(java.lang.CharSequence name) Description copied from class:HttpHeadersReturns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getTimeMillisin classHttpHeaders- Parameters:
name- the name of the header to search- Returns:
- the first header value if the header is found and its value is a date.
nullif there's no such header or its value is not a date.
-
getTimeMillis
public long getTimeMillis(java.lang.CharSequence name, long defaultValue) Description copied from class:HttpHeadersReturns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.- Specified by:
getTimeMillisin classHttpHeaders- Parameters:
name- the name of the header to searchdefaultValue- the default value- Returns:
- the first header value if the header is found and its value is a date.
defaultValueif there's no such header or its value is not a date.
-
getAll
public java.util.List<java.lang.String> getAll(java.lang.String name) - Specified by:
getAllin classHttpHeaders- See Also:
-
entries
public java.util.List<java.util.Map.Entry<java.lang.String, java.lang.String>> entries()Description copied from class:HttpHeadersReturns a newListthat contains all headers in this object. Note that modifying the returnedListwill not affect the state of this object. If you intend to enumerate over the header entries only, useHttpHeaders.iterator()instead, which has much less overhead.- Specified by:
entriesin classHttpHeaders- See Also:
-
contains
public boolean contains(java.lang.String name) - Specified by:
containsin classHttpHeaders- See Also:
-
contains
public boolean contains(java.lang.String name, java.lang.String value, boolean ignoreCase) - Overrides:
containsin classHttpHeaders- See Also:
-
containsValue
public boolean containsValue(java.lang.CharSequence name, java.lang.CharSequence value, boolean ignoreCase) Description copied from class:HttpHeadersReturnstrueif a header with thenameandvalueexists,falseotherwise. This also handles multiple values that are separated with a,.If
ignoreCaseistruethen a case insensitive compare is done on the value.- Overrides:
containsValuein classHttpHeaders- Parameters:
name- the name of the header to findvalue- the value of the header to findignoreCase-truethen a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
-
valueStringIterator
public java.util.Iterator<java.lang.String> valueStringIterator(java.lang.CharSequence name) Description copied from class:HttpHeadersEquivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.- Overrides:
valueStringIteratorin classHttpHeaders- Parameters:
name- the name of the header to retrieve- Returns:
- an
Iteratorof header values corresponding toname.
-
valueCharSequenceIterator
public java.util.Iterator<java.lang.CharSequence> valueCharSequenceIterator(java.lang.CharSequence name) Description copied from class:HttpHeadersEquivalent toHttpHeaders.getAll(String)but it is possible that no intermediate list is generated.- Overrides:
valueCharSequenceIteratorin classHttpHeaders- Parameters:
name- the name of the header to retrieve- Returns:
- an
Iteratorof header values corresponding toname.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String, java.lang.String>> iterator()- Specified by:
iteratorin interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.String, java.lang.String>>- Specified by:
iteratorin classHttpHeaders
-
iteratorCharSequence
public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence, java.lang.CharSequence>> iteratorCharSequence()- Specified by:
iteratorCharSequencein classHttpHeaders- Returns:
- Iterator over the name/value header pairs.
-
isEmpty
public boolean isEmpty()Description copied from class:HttpHeadersChecks if no header exists.- Specified by:
isEmptyin classHttpHeaders
-
size
public int size()Description copied from class:HttpHeadersReturns the number of headers in this object.- Specified by:
sizein classHttpHeaders
-
names
public java.util.Set<java.lang.String> names()Description copied from class:HttpHeadersReturns a newSetthat contains the names of all headers in this object. Note that modifying the returnedSetwill not affect the state of this object. If you intend to enumerate over the header entries only, useHttpHeaders.iterator()instead, which has much less overhead.- Specified by:
namesin classHttpHeaders
-
add
- Specified by:
addin classHttpHeaders- See Also:
-
add
- Specified by:
addin classHttpHeaders- See Also:
-
addInt
Description copied from class:HttpHeadersAdd thenametovalue.- Specified by:
addIntin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
addShort
Description copied from class:HttpHeadersAdd thenametovalue.- Specified by:
addShortin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
set
- Specified by:
setin classHttpHeaders- See Also:
-
set
- Specified by:
setin classHttpHeaders- See Also:
-
setInt
Description copied from class:HttpHeadersSet thenametovalue. This will remove all previous values associated withname.- Specified by:
setIntin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
setShort
Description copied from class:HttpHeadersSet thenametovalue. This will remove all previous values associated withname.- Specified by:
setShortin classHttpHeaders- Parameters:
name- The name to modifyvalue- The value- Returns:
this
-
remove
- Specified by:
removein classHttpHeaders- See Also:
-
clear
Description copied from class:HttpHeadersRemoves all headers from thisHttpMessage.- Specified by:
clearin classHttpHeaders- Returns:
this
-