in google-http-client/src/main/java/com/google/api/client/http/MultipartContent.java [61:114]
public void writeTo(OutputStream out) throws IOException {
Writer writer = new OutputStreamWriter(out, getCharset());
String boundary = getBoundary();
for (Part part : parts) {
HttpHeaders headers = new HttpHeaders().setAcceptEncoding(null);
if (part.headers != null) {
headers.fromHttpHeaders(part.headers);
}
headers.setContentEncoding(null)
.setUserAgent(null)
.setContentType(null)
.setContentLength(null)
.set("Content-Transfer-Encoding", null);
// analyze the content
HttpContent content = part.content;
StreamingContent streamingContent = null;
if (content != null) {
headers.set("Content-Transfer-Encoding", Arrays.asList("binary"));
headers.setContentType(content.getType());
HttpEncoding encoding = part.encoding;
long contentLength;
if (encoding == null) {
contentLength = content.getLength();
streamingContent = content;
} else {
headers.setContentEncoding(encoding.getName());
streamingContent = new HttpEncodingStreamingContent(content, encoding);
contentLength = AbstractHttpContent.computeLength(content);
}
if (contentLength != -1) {
headers.setContentLength(contentLength);
}
}
// write separator
writer.write(TWO_DASHES);
writer.write(boundary);
writer.write(NEWLINE);
// write headers
HttpHeaders.serializeHeadersForMultipartRequests(headers, null, null, writer);
// write content
if (streamingContent != null) {
writer.write(NEWLINE);
writer.flush();
streamingContent.writeTo(out);
writer.write(NEWLINE);
}
}
// write end separator
writer.write(TWO_DASHES);
writer.write(boundary);
writer.write(TWO_DASHES);
writer.write(NEWLINE);
writer.flush();
}