Verifies the MultipartBody by reading the individual parts
and copying them to a new MultipartBody instance which
will be written out in the multipart/mixed format.

@param body the incoming MultipartBody
@return new MultipartBody
13095
private MultipartBody duplicateMultipartBody(MultipartBody body) {
        
        // It is possible to access individual parts by the Content-Id values
        // This MultipartBody is expected to contain 3 parts, 
        // "book1", "book2" and "image". 
        
        // These individual parts have their Content-Type set to 
        // application/xml, application/json and application/octet-stream
        
        // MultipartBody will use the Content-Type value of the individual
        // part to read its data in a type safe way by delegating to a matching 
        // JAX-RS MessageBodyReader provider
        
        Book jaxbBook = body.getAttachmentObject("book1", Book.class);
        Book jsonBook = body.getAttachmentObject("book2", Book.class);
        
        // Accessing individual attachment part, its DataHandler will be 
        // used to access the underlying input stream, the type-safe access
        // is also possible
        
        Attachment imageAtt = body.getAttachment("image");
        
        if ("JAXB".equals(jaxbBook.getName()) && 1L == jaxbBook.getId()
            && "JSON".equals(jsonBook.getName()) && 2L == jsonBook.getId()
            && imageAtt != null) {
            return createMultipartBody(jaxbBook, jsonBook, imageAtt.getDataHandler());
        }
        throw new RuntimeException("Received Book attachment is corrupted");
    }
39646
private static void checkPartForTextType(HashMap<String, Collection<String>> bodies, Part part) throws IOException, MessagingException {
        Object content = part.getContent();
        if (content instanceof CharSequence) {
            String ct = part.getContentType();
            Collection<String> value = bodies.get(ct);
            if (value != null) {
                value.add(content.toString());
            } else {
                value = new LinkedList<>();
                value.add(content.toString());
                bodies.put(ct, value);
            }
        } else if (content instanceof Multipart) {
            Multipart mp = (Multipart) content;
            for(int i = 0; i < mp.getCount(); i++) {
                checkPartForTextType(bodies, mp.getBodyPart(i));
            }
        }
    }
523251
@Override
    protected Request.Builder setBody(Request.Builder builder) {
        if (body != null) {
            MultipartBody.Builder bodyBuilder = createMultipartBody();
            RequestBody requestBody = bodyBuilder.build();
            if ("PUT".equalsIgnoreCase(method))
                builder.put(requestBody);
            else if ("POST".equalsIgnoreCase(method))
                builder.post(requestBody);
        }
        return builder;
    }
79570
public static byte[] hash(byte[] body) {
        if (HASH_DIGEST != null) {
            return HASH_DIGEST.digest(body);
        } else {
            throw new EvernoteUtilException(EDAM_HASH_ALGORITHM + " not supported", new NoSuchAlgorithmException(EDAM_HASH_ALGORITHM));
        }
    }
471895
function _setResponseBody(body) {
    verifyRequestSent(this);
    verifyHeadersReceived(this);
    verifyResponseBodyType(body);

    var chunkSize = this.chunkSize || 10;
    var index = 0;
    this.responseText = "";

    do {
      if (this.async) {
        this._readyStateChange(FakeXMLHttpRequest.LOADING);
      }

      this.responseText += body.substring(index, index + chunkSize);
      index += chunkSize;
    } while (index < body.length);

    var type = this.getResponseHeader("Content-Type");

    if (this.responseText && (!type || /(text\/xml)|(application\/xml)|(\+xml)/.test(type))) {
      try {
        this.responseXML = parseXML(this.responseText);
      } catch (e) {
        // Unable to parse XML - no biggie
      }
    }

    if (this.async) {
      this._readyStateChange(FakeXMLHttpRequest.DONE);
    } else {
      this.readyState = FakeXMLHttpRequest.DONE;
    }
  }
798057
public MockResponse setChunkedBody(byte[] body, int maxChunkSize) {
        removeHeader("Content-Length");
        headers.add(CHUNKED_BODY_HEADER);

        try {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            int pos = 0;
            while (pos < body.length) {
                int chunkSize = Math.min(body.length - pos, maxChunkSize);
                bytesOut.write(Integer.toHexString(chunkSize).getBytes(US_ASCII));
                bytesOut.write("\r\n".getBytes(US_ASCII));
                bytesOut.write(body, pos, chunkSize);
                bytesOut.write("\r\n".getBytes(US_ASCII));
                pos += chunkSize;
            }
            bytesOut.write("0\r\n\r\n".getBytes(US_ASCII)); // last chunk + empty trailer + crlf

            this.body = bytesOut.toByteArray();
            return this;
        } catch (IOException e) {
            throw new AssertionError(); // In-memory I/O doesn't throw IOExceptions.
        }
    }
1126498
public MailRequest newTextMailRequest(String subject, String body) {
        return createMailRequest(generateRequestId(), false, subject, body);
    }
317621
private static JsJmsMessage decodeTextBody(String body) throws MessageDecodeFailedException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "decodeTextBody");
        JsJmsTextMessage result = new JsJmsTextMessageImpl(MfpConstants.CONSTRUCTOR_NO_OP);
        if (body != null) {
            result.setText(URLDecode(body));
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "decodeTextBody");
        return result;
    }
1250395
@SuppressWarnings(
        {
            "PMD.InsufficientStringBufferDeclaration",
            "PMD.AvoidInstantiatingObjectsInLoops"
        })
    private static StringBuilder fakeBody(final Request... parts)
        throws IOException {
        final StringBuilder builder = new StringBuilder();
        for (final Request part : parts) {
            builder.append(String.format("--%s", RqMtFake.BOUNDARY))
                .append(RqMtFake.CRLF)
                .append("Content-Disposition: ")
                .append(
                    new RqHeaders.Smart(
                        new RqHeaders.Base(part)
                    ).single("Content-Disposition")
                ).append(RqMtFake.CRLF);
            final String body = new RqPrint(part).printBody();
            if (!(RqMtFake.CRLF.equals(body) || body.isEmpty())) {
                builder.append(RqMtFake.CRLF)
                    .append(body)
                    .append(RqMtFake.CRLF);
            }
        }
        builder.append("Content-Transfer-Encoding: utf-8")
            .append(RqMtFake.CRLF)
            .append(String.format("--%s--", RqMtFake.BOUNDARY));
        return builder;
    }
1078432
protected String serializeBody(Request request)
    {
        try
        {
            return objectMapper.writeValueAsString(request.getRequestBody());
        }
        catch (JsonProcessingException e)
        {
            throw new ClientMarshallingException("Error writing request.",e);
        }
    }
1261448
public MailBuilder content(Body body) {
        return text(body.text()).html(body.html());
    }
505861
public PactDslRequestWithoutPath body(String body, ContentType mimeType) {
        return body(body, mimeType.toString());
    }
428922
public static HttpResponse response(String body) {
        return new HttpResponse().withStatusCode(OK_200.code()).withReasonPhrase(OK_200.reasonPhrase()).withBody(body);
    }
814433
public void setResponseBody(HttpResponseBody resBody) {
		if (resBody == null) {
			throw new IllegalArgumentException("The parameter resBody must not be null.");
		}
		mResBody = resBody;
	    getResponseBody().setCharset(getResponseHeader().getCharset());

	}
1013309
@Override
    public <T> T receiveBody(Class<T> paramClass) throws MessageFormatRuntimeException, JMSRuntimeException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "receiveBody", new Object[] { paramClass });

        try {
            // pass timeOut as 0
            return receiveBody(paramClass, 0);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "receiveBody");
        }

    }
712838
private RequestBody getBody(Map<String, String> data, @Nullable Map<String, File> files, @Nullable Map<String,
            InputStream> fileStreams) throws LocalOperationException {
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);

        if (files != null) {
            for (Map.Entry<String, File> entry : files.entrySet()) {
                File file = entry.getValue();
                String mimeType = URLConnection.guessContentTypeFromName(file.getName());

                if (mimeType == null) {
                    mimeType = "application/octet-stream";
                }

                builder.addFormDataPart(entry.getKey(), file.getName(),
                        RequestBody.create(MediaType.parse(mimeType), file));
            }
        }

        if (fileStreams != null) {
            for (Map.Entry<String, InputStream> entry : fileStreams.entrySet()) {
                byte[] bytes;
                InputStream stream = entry.getValue();
                try {
                    bytes = new byte[stream.available()];
                    stream.read(bytes);

                } catch (IOException e) {
                    throw new LocalOperationException(e);
                }
                builder.addFormDataPart(entry.getKey(), null,
                        RequestBody.create(MediaType.parse("application/octet-stream"), bytes));
            }
        }

        for (Map.Entry<String, String> entry : data.entrySet()) {
            builder.addFormDataPart(entry.getKey(), entry.getValue());
        }

        return builder.build();
    }
949315
public void setBody(CharSequence body) {
        String bodyString;
        if (body != null) {
            bodyString = body.toString();
        } else {
            bodyString = null;
        }
        setBody(bodyString);
    }