@Test public void ofThrowsOnNull() { try { Headers.of("User-Agent", null); fail(); } catch (IllegalArgumentException expected) { } }
public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); }
Headers { public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); } }
Headers { public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); } private  Headers(Builder builder); private  Headers(String[] namesAndValues); }
Headers { public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); } private  Headers(Builder builder); private  Headers(String[] namesAndValues); String get(String name); Date getDate(String name); int size(); String name(int index); String value(int index); Set<String> names(); List<String> values(String name); Builder newBuilder(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Map<String, List<String>> toMultimap(); Map<String, String> toMap(); static Headers of(String... namesAndValues); static Headers of(Map<String, String> headers); static Headers ofMMap(Map<String, List<String>> headers); }
Headers { public static Headers of(String... namesAndValues) { if (namesAndValues == null) throw new NullPointerException("namesAndValues == null"); if (namesAndValues.length % 2 != 0) { throw new IllegalArgumentException("Expected alternating header names and values"); } namesAndValues = namesAndValues.clone(); for (int i = 0; i < namesAndValues.length; i++) { if (namesAndValues[i] == null) throw new IllegalArgumentException("Headers cannot be null"); namesAndValues[i] = namesAndValues[i].trim(); } for (int i = 0; i < namesAndValues.length; i += 2) { String name = namesAndValues[i]; String value = namesAndValues[i + 1]; if (name.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } } return new Headers(namesAndValues); } private  Headers(Builder builder); private  Headers(String[] namesAndValues); String get(String name); Date getDate(String name); int size(); String name(int index); String value(int index); Set<String> names(); List<String> values(String name); Builder newBuilder(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Map<String, List<String>> toMultimap(); Map<String, String> toMap(); static Headers of(String... namesAndValues); static Headers of(Map<String, String> headers); static Headers ofMMap(Map<String, List<String>> headers);  }