Created
January 4, 2012 15:02
-
-
Save marianogonzalez/1560407 to your computer and use it in GitHub Desktop.
MultipartHttpToMapTransformer aux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected Map<String, String> parseHeaders(String headerPart) | |
{ | |
Map<String, String> headers = new HashMap<String, String>(); | |
char buffer[] = new char[1024]; | |
boolean done = false; | |
int j = 0; | |
int i; | |
String header, headerName, headerValue; | |
try | |
{ | |
while (!done) | |
{ | |
i = 0; | |
// Copy a single line of characters into the buffer, | |
// omitting trailing CRLF. | |
while (i < 2 || buffer[i - 2] != '\r' || buffer[i - 1] != '\n') | |
{ | |
buffer[i++] = headerPart.charAt(j++); | |
} | |
header = new String(buffer, 0, i - 2); | |
if (header.equals("")) | |
{ | |
done = true; | |
} | |
else | |
{ | |
if (header.indexOf(':') == -1) | |
{ | |
// This header line is malformed, skip it. | |
continue; | |
} | |
headerName = header.substring(0, header.indexOf(':')) | |
.trim().toLowerCase(); | |
headerValue = | |
header.substring(header.indexOf(':') + 1).trim(); | |
if ((String)headers.get(headerName.toLowerCase()) != null) | |
{ | |
// More that one heder of that name exists, | |
// append to the list. | |
headers.put(headerName, | |
headers.get(headerName.toLowerCase()) + ',' | |
+ headerValue); | |
} | |
else | |
{ | |
headers.put(headerName, headerValue); | |
} | |
} | |
} | |
} | |
catch (IndexOutOfBoundsException e) | |
{ | |
if (logger.isDebugEnabled()) { | |
logger.debug("Headers were malformed. continue with all that was parsed."); | |
} | |
} | |
return headers; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment