@Override public List<MediaType> acceptPatches() { List<MediaType> result = all(Http.Header.ACCEPT_PATCH).stream() .flatMap(h -> Utils.tokenize(',', "\"", false, h).stream()) .map(String::trim) .map(MediaType::parse) .collect(Collectors.toList()); return Collections.unmodifiableList(result); }
/** * Gets the content of the underlying {@link ByteBuffer} as an array of bytes. * If the the ByteBuffer was read, the returned array contains only the part of * data that wasn't read yet. On the other hand, calling this method doesn't cause * the underlying {@link ByteBuffer} to be read. * <p> * It is expected the returned byte array holds a reference to data that * will become stale upon calling method {@link #release()}. (For instance, * the memory segment is pooled by the underlying TCP server and is reused * for a subsequent request chunk.) The idea behind this class is to be able to * minimize data copying; ideally, in order to achieve the best performance, * to not copy them at all. However, the implementations may choose otherwise. * <p> * Note that the methods of this instance are expected to be called by a single * thread; if not, external synchronization must be used. * * @return an array of bytes that is guarantied to stay immutable as long as * method {@link #release()} is not called */ default byte[] bytes() { return Utils.toByteArray(data().asReadOnlyBuffer()); }
@Override public List<MediaType> acceptedTypes() { List<MediaType> result = this.acceptedtypesCache; if (result == null) { List<String> acceptValues = all(Http.Header.ACCEPT); result = acceptValues.size() == 1 && HUC_ACCEPT_DEFAULT.equals(acceptValues.get(0)) ? HUC_ACCEPT_DEFAULT_TYPES : acceptValues.stream() .flatMap(h -> Utils.tokenize(',', "\"", false, h).stream()) .map(String::trim) .map(MediaType::parse) .collect(Collectors.toList()); result = Collections.unmodifiableList(result); this.acceptedtypesCache = result; } return result; }
/** * Returns an unmodifiable {@link List} of all comma separated header value parts - <b>Such segmentation is NOT valid for * all header semantics, however it is very common</b>. Refer to actual header semantics standard/description before use. * <p> * Result is composed from all header fields with requested {@code headerName} where each header value is tokenized by * a comma character. Tokenization respects value quoting by <i>double-quote</i> character. * <p> * Always returns a List, which may be empty if the parameter is not present. * * @param headerName the header name * @return a {@code List} of values with zero or greater size, never {@code null} * @throws NullPointerException if {@code headerName} is {@code null} * @see #all(String) * @see #value(String) */ default List<String> values(String headerName) { return all(headerName).stream() .flatMap(val -> Utils.tokenize(',', "\"", true, val).stream()) .collect(Collectors.toList()); } }