Parses the HTTP payload and returns a result body element. @param type media type @param encoding content encoding @return body element @throws IOException I/O exception @throws QueryException query exception
(final MediaType type, final String encoding)
| 71 | * @throws QueryException query exception |
| 72 | */ |
| 73 | FNode parse(final MediaType type, final String encoding) throws IOException, QueryException { |
| 74 | final FBuilder body; |
| 75 | if(type.isMultipart()) { |
| 76 | // multipart response |
| 77 | final byte[] boundary = boundary(type); |
| 78 | body = FElem.build(Q_HTTP_MULTIPART).attr(Q_BOUNDARY, boundary); |
| 79 | final GNodeList parts = new GNodeList(); |
| 80 | extractParts(concat(DASHES, boundary), parts); |
| 81 | for(final GNode node : parts) body.node(node); |
| 82 | } else { |
| 83 | // single part response |
| 84 | body = FElem.build(Q_HTTP_BODY); |
| 85 | if(payloads != null) { |
| 86 | final InputStream in = GZIP.equals(encoding) ? new GZIPInputStream(input) : input; |
| 87 | payloads.add(parse(BufferInput.get(in).content(), type)); |
| 88 | } |
| 89 | } |
| 90 | return body.attr(Q_MEDIA_TYPE, type.type()).finish(); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Returns all payloads. |