List of usage examples for org.springframework.core.io.buffer DataBuffer read
DataBuffer read(byte[] destination);
From source file:org.springframework.http.codec.multipart.DefaultMultipartMessageReader.java
/** * Convert the given data buffer into a {@link HttpHeaders} instance. The given string is read * as US-ASCII, then split along \r\n line boundaries, each line containing a header name and * value(s)./*from www.ja v a2s .c o m*/ */ private static HttpHeaders toHeaders(DataBuffer dataBuffer) { byte[] bytes = new byte[dataBuffer.readableByteCount()]; dataBuffer.read(bytes); DataBufferUtils.release(dataBuffer); String string = new String(bytes, StandardCharsets.US_ASCII); String[] lines = string.split(HEADER_SEPARATOR); HttpHeaders result = new HttpHeaders(); for (String line : lines) { int idx = line.indexOf(':'); if (idx != -1) { String name = line.substring(0, idx); String value = line.substring(idx + 1); while (value.startsWith(" ")) { value = value.substring(1); } String[] tokens = StringUtils.tokenizeToStringArray(value, ","); for (String token : tokens) { result.add(name, token); } } } return result; }