/** * Create a Map instance to be used as column map. * <p>By default, a linked case-insensitive Map will be created. * @param columnCount the column count, to be used as initial * capacity for the Map * @return the new Map instance * @see org.springframework.util.LinkedCaseInsensitiveMap */ protected Map<String, Object> createColumnMap(int columnCount) { return new LinkedCaseInsensitiveMap<>(columnCount); }
@Override public LinkedCaseInsensitiveMap<V> clone() { return new LinkedCaseInsensitiveMap<>(this); }
@Override public LinkedCaseInsensitiveMap<V> clone() { return new LinkedCaseInsensitiveMap<>(this); }
private static Map<String, List<String>> initHeaders(HttpServletRequest request) { Map<String, List<String>> headers = new LinkedCaseInsensitiveMap<>(Locale.ENGLISH); Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); if (!FORWARDED_HEADER_NAMES.contains(name)) { headers.put(name, Collections.list(request.getHeaders(name))); } } return headers; }
/** * Construct a new, empty instance of the {@code HttpHeaders} object. */ public HttpHeaders() { this(CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))); }
/** * Create a WebSocketExtension with the given name and parameters. * @param name the name of the extension * @param parameters the parameters */ public WebSocketExtension(String name, @Nullable Map<String, String> parameters) { Assert.hasLength(name, "Extension name must not be empty"); this.name = name; if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); map.putAll(parameters); this.parameters = Collections.unmodifiableMap(map); } else { this.parameters = Collections.emptyMap(); } }
/** * Create a Map instance to be used as the results map. * <p>If {@link #resultsMapCaseInsensitive} has been set to true, * a {@link LinkedCaseInsensitiveMap} will be created; otherwise, a * {@link LinkedHashMap} will be created. * @return the results Map instance * @see #setResultsMapCaseInsensitive * @see #isResultsMapCaseInsensitive */ protected Map<String, Object> createResultsMap() { if (isResultsMapCaseInsensitive()) { return new LinkedCaseInsensitiveMap<>(); } else { return new LinkedHashMap<>(); } }
private static Map<String, List<String>> initHeaders(HttpServletRequest request) { Map<String, List<String>> headers = new LinkedCaseInsensitiveMap<>(Locale.ENGLISH); Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); if (!FORWARDED_HEADER_NAMES.contains(name)) { headers.put(name, Collections.list(request.getHeaders(name))); } } return headers; }
/** * Construct a new, empty instance of the {@code HttpHeaders} object. */ public HttpHeaders() { this(CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))); }
private static Map<String, String> initParameters(Extension extension) { List<Extension.Parameter> parameters = extension.getParameters(); Map<String, String> result = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); for (Extension.Parameter parameter : parameters) { result.put(parameter.getName(), parameter.getValue()); } return result; }
/** * Create a new {@code MimeType} for the given type, subtype, and parameters. * @param type the primary type * @param subtype the subtype * @param parameters the parameters (may be {@code null}) * @throws IllegalArgumentException if any of the parameters contains illegal characters */ public MimeType(String type, String subtype, @Nullable Map<String, String> parameters) { Assert.hasLength(type, "'type' must not be empty"); Assert.hasLength(subtype, "'subtype' must not be empty"); checkToken(type); checkToken(subtype); this.type = type.toLowerCase(Locale.ENGLISH); this.subtype = subtype.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); parameters.forEach((attribute, value) -> { checkParameters(attribute, value); map.put(attribute, value); }); this.parameters = Collections.unmodifiableMap(map); } else { this.parameters = Collections.emptyMap(); } }
@Nullable /* for testing */ static LinkedCaseInsensitiveMap<String> splitIntoCaseInsensitiveMap(String[] pairs) { if (ObjectUtils.isEmpty(pairs)) { return null; } LinkedCaseInsensitiveMap<String> result = new LinkedCaseInsensitiveMap<>(); for (String element : pairs) { String[] splittedElement = StringUtils.split(element, "="); if (splittedElement == null) { continue; } result.put(splittedElement[0].trim(), splittedElement[1].trim()); } return result; }
if (StringUtils.hasLength(requestEncoding)) { Charset charSet = Charset.forName(requestEncoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charSet.toString());
/** * Create a new {@code MimeType} for the given type, subtype, and parameters. * @param type the primary type * @param subtype the subtype * @param parameters the parameters (may be {@code null}) * @throws IllegalArgumentException if any of the parameters contains illegal characters */ public MimeType(String type, String subtype, @Nullable Map<String, String> parameters) { Assert.hasLength(type, "'type' must not be empty"); Assert.hasLength(subtype, "'subtype' must not be empty"); checkToken(type); checkToken(subtype); this.type = type.toLowerCase(Locale.ENGLISH); this.subtype = subtype.toLowerCase(Locale.ENGLISH); if (!CollectionUtils.isEmpty(parameters)) { Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH); parameters.forEach((attribute, value) -> { checkParameters(attribute, value); map.put(attribute, value); }); this.parameters = Collections.unmodifiableMap(map); } else { this.parameters = Collections.emptyMap(); } }
private static HttpHeaders initHeaders(HttpHeaders headers, HttpServletRequest request) { MediaType contentType = headers.getContentType(); if (contentType == null) { String requestContentType = request.getContentType(); if (StringUtils.hasLength(requestContentType)) { contentType = MediaType.parseMediaType(requestContentType); headers.setContentType(contentType); } } if (contentType != null && contentType.getCharset() == null) { String encoding = request.getCharacterEncoding(); if (StringUtils.hasLength(encoding)) { Charset charset = Charset.forName(encoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charset.toString()); headers.setContentType( new MediaType(contentType.getType(), contentType.getSubtype(), params)); } } if (headers.getContentLength() == -1) { int contentLength = request.getContentLength(); if (contentLength != -1) { headers.setContentLength(contentLength); } } return headers; }
if (StringUtils.hasLength(requestEncoding)) { Charset charSet = Charset.forName(requestEncoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charSet.toString());
private static HttpHeaders initHeaders(HttpHeaders headers, HttpServletRequest request) { MediaType contentType = headers.getContentType(); if (contentType == null) { String requestContentType = request.getContentType(); if (StringUtils.hasLength(requestContentType)) { contentType = MediaType.parseMediaType(requestContentType); headers.setContentType(contentType); } } if (contentType != null && contentType.getCharset() == null) { String encoding = request.getCharacterEncoding(); if (StringUtils.hasLength(encoding)) { Charset charset = Charset.forName(encoding); Map<String, String> params = new LinkedCaseInsensitiveMap<>(); params.putAll(contentType.getParameters()); params.put("charset", charset.toString()); headers.setContentType( new MediaType(contentType.getType(), contentType.getSubtype(), params)); } } if (headers.getContentLength() == -1) { int contentLength = request.getContentLength(); if (contentLength != -1) { headers.setContentLength(contentLength); } } return headers; }
/** * Create a linked case-insensitive Map if possible: This implementation * always returns a {@link org.springframework.util.LinkedCaseInsensitiveMap}. * @param initialCapacity the initial capacity of the Map * @return the new Map instance * @deprecated as of Spring 3.0, for usage on JDK 1.5 or higher */ @Deprecated public static Map createLinkedCaseInsensitiveMapIfPossible(int initialCapacity) { return new LinkedCaseInsensitiveMap(initialCapacity); }
@Parameterized.Parameters(name = "headers [{0}]") public static Object[][] arguments() { return new Object[][] { {CollectionUtils.toMultiValueMap( new LinkedCaseInsensitiveMap<>(8, Locale.ENGLISH))}, {new NettyHeadersAdapter(new DefaultHttpHeaders())}, {new TomcatHeadersAdapter(new MimeHeaders())}, {new UndertowHeadersAdapter(new HeaderMap())}, {new JettyHeadersAdapter(new HttpFields())} }; }
@Override protected Object doTransform(Message<?> message) throws Exception { Object payload = buildJsonPayload(message.getPayload()); Map<String, Object> headers = new LinkedCaseInsensitiveMap<>(); headers.putAll(message.getHeaders()); if (headers.containsKey(MessageHeaders.CONTENT_TYPE)) { if (this.contentTypeExplicitlySet) { // override, unless empty if (StringUtils.hasLength(this.contentType)) { headers.put(MessageHeaders.CONTENT_TYPE, this.contentType); } } } else if (StringUtils.hasLength(this.contentType)) { headers.put(MessageHeaders.CONTENT_TYPE, this.contentType); } this.jsonObjectMapper.populateJavaTypes(headers, message.getPayload()); return getMessageBuilderFactory() .withPayload(payload) .copyHeaders(headers) .build(); }