Returns the payload. @param request request data @return input stream @throws IOException I/O exception
(final Request request)
| 230 | * @throws IOException I/O exception |
| 231 | */ |
| 232 | public static byte[] payload(final Request request) throws IOException { |
| 233 | final ArrayOutput out = new ArrayOutput(); |
| 234 | if(request.isMultipart) { |
| 235 | final String boundary = request.boundary(); |
| 236 | for(final Part part : request.parts) { |
| 237 | // write content to cache |
| 238 | final ArrayOutput ao = new ArrayOutput(); |
| 239 | writePayload(part.contents, part.attributes, ao); |
| 240 | |
| 241 | // write boundary preceded by "--" |
| 242 | out.write(Token.concat("--", boundary, CRLF)); |
| 243 | |
| 244 | // write headers |
| 245 | for(final Entry<String, String> header : part.headers.entrySet()) |
| 246 | writeHeader(header.getKey(), header.getValue(), out); |
| 247 | if(!part.headers.containsKey(CONTENT_TYPE)) |
| 248 | writeHeader(CONTENT_TYPE, part.attributes.get(SerializerOptions.MEDIA_TYPE.name()), out); |
| 249 | |
| 250 | out.write(CRLF); |
| 251 | out.write(ao.finish()); |
| 252 | out.write(CRLF); |
| 253 | } |
| 254 | out.write(Token.concat("--", boundary, "--", CRLF)); |
| 255 | } else { |
| 256 | writePayload(request.payload, request.payloadAtts, out); |
| 257 | } |
| 258 | return out.finish(); |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Writes a single header. |