public int getIntHeader(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); Object value = (header != null ? header.getValue() : null); if (value instanceof Number) { return ((Number) value).intValue(); } else if (value instanceof String) { return Integer.parseInt((String) value); } else if (value != null) { throw new NumberFormatException("Value for header '" + name + "' is not a Number: " + value); } else { return -1; } }
public long getDateHeader(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); Object value = (header != null ? header.getValue() : null); if (value instanceof Date) { return ((Date) value).getTime(); } else if (value instanceof Number) { return ((Number) value).longValue(); } else if (value != null) { throw new IllegalArgumentException( "Value for header '" + name + "' is neither a Date nor a Number: " + value); } else { return -1L; } }
@Override public String getHeader(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); return (header != null ? header.getValue().toString() : null); }
/** * Return the primary value for the given header, if any. * * <p>Will return the first value in case of multiple values. * * @param name the name of the header * @return the associated header value, or {@code null} if none */ public Object getHeaderValue(String name) { HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name); return (header != null ? header.getValue() : null); }