org.apache.http.entity.mime.MIME Java Examples

The following examples show how to use org.apache.http.entity.mime.MIME. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DelayedHttpMultipartEntity.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param status Length
 */
public DelayedHttpMultipartEntity(final String filename, final TransferStatus status, final String boundary) {
    this.status = status;
    final StringBuilder multipartHeader = new StringBuilder();
    multipartHeader.append(TWO_DASHES);
    multipartHeader.append(boundary);
    multipartHeader.append(CR_LF);
    multipartHeader.append(String.format("Content-Disposition: form-data; name=\"file\"; filename=\"%s\"", filename));
    multipartHeader.append(CR_LF);
    multipartHeader.append(String.format("%s: %s", HTTP.CONTENT_TYPE, StringUtils.isBlank(status.getMime()) ? MimeTypeService.DEFAULT_CONTENT_TYPE : status.getMime()));
    multipartHeader.append(CR_LF);
    multipartHeader.append(CR_LF);
    header = encode(MIME.DEFAULT_CHARSET, multipartHeader.toString()).buffer();
    final StringBuilder multipartFooter = new StringBuilder();
    multipartFooter.append(CR_LF);
    multipartFooter.append(TWO_DASHES);
    multipartFooter.append(boundary);
    multipartFooter.append(TWO_DASHES);
    multipartFooter.append(CR_LF);
    footer = encode(MIME.DEFAULT_CHARSET, multipartFooter.toString()).buffer();
}
 
Example #2
Source File: HttpSender.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected FormBodyPart createMultipartBodypart(String name, String message, String contentType) {
	ContentType cType = ContentType.create("text/plain", getCharSet());
	if(StringUtils.isNotEmpty(contentType))
		cType = ContentType.create(contentType, getCharSet());

	FormBodyPartBuilder bodyPart = FormBodyPartBuilder.create()
		.setName(name)
		.setBody(new StringBody(message, cType));

	if (StringUtils.isNotEmpty(getMtomContentTransferEncoding()))
		bodyPart.setField(MIME.CONTENT_TRANSFER_ENC, getMtomContentTransferEncoding());

	return bodyPart.build();
}
 
Example #3
Source File: HttpGenericOperationUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public String getTransferEncoding() {
    return MIME.ENC_BINARY;
}
 
Example #4
Source File: MultipartForm.java    From iaf with Apache License 2.0 4 votes vote down vote up
private static void writeBytes(
		final String s, final OutputStream out) throws IOException {
	final ByteArrayBuffer b = encode(MIME.DEFAULT_CHARSET, s);
	writeBytes(b, out);
}
 
Example #5
Source File: MultipartForm.java    From iaf with Apache License 2.0 3 votes vote down vote up
/**
 * Creates an instance with the specified settings.
 *
 * @param charset the character set to use. May be {@code null}, in which case {@link MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
 * @param boundary to use  - must not be {@code null}
 * @throws IllegalArgumentException if charset is null or boundary is null
 */
public MultipartForm(final Charset charset, final String boundary, final List<FormBodyPart> parts) {
	Args.notNull(boundary, "Multipart boundary");
	this.charset = charset != null ? charset : MIME.DEFAULT_CHARSET;
	this.boundary = boundary;
	this.parts = parts;
}