Returns a normalized payload. @param body body @param type media type @return content @throws IOException I/O exception
(final byte[] body, final MediaType type)
| 343 | * @throws IOException I/O exception |
| 344 | */ |
| 345 | private static IOContent prepare(final byte[] body, final MediaType type) throws IOException { |
| 346 | byte[] data = body; |
| 347 | final boolean xml = type.isXml(), text = type.isText(); |
| 348 | if(xml || text) { |
| 349 | // convert text to UTF8; skip redundant XML declaration |
| 350 | data = new NewlineInput(new IOContent(body), type.parameter(CHARSET)).content(); |
| 351 | if(xml && startsWith(data, DECLSTART)) { |
| 352 | final int d = indexOf(data, DECLEND, DECLSTART.length); |
| 353 | if(d != -1) data = substring(data, d + DECLEND.length); |
| 354 | } |
| 355 | } |
| 356 | return new IOContent(data); |
| 357 | } |
| 358 | } |