public TextBody buildText() throws IOException { Charset cs = this.charset != null ? this.charset : Charsets.DEFAULT_CHARSET; if (this.bodyFactory != null) { if (this.text != null) { return this.bodyFactory.textBody(InputStreams.create(this.text, cs), cs.name()); } else if (this.bin != null) { return this.bodyFactory.textBody(InputStreams.create(this.bin), cs.name()); } else { return this.bodyFactory.textBody(InputStreams.create(new byte [] {}), cs.name()); } } else { if (this.text != null) { return BasicBodyFactory.INSTANCE.textBody(this.text, cs); } else if (this.bin != null) { return BasicBodyFactory.INSTANCE.textBody(this.bin, cs); } else { return BasicBodyFactory.INSTANCE.textBody(new byte [] {}, cs); } } }
public void body(BodyDescriptor bd, final InputStream is) throws MimeException, IOException { expect(Entity.class); final Body body; if (bd.getMimeType().startsWith("text/")) { body = bodyFactory.textBody(is, bd.getCharset()); } else { body = bodyFactory.binaryBody(is); } Entity entity = ((Entity) stack.peek()); entity.setBody(body); }
public MultipartBuilder addTextPart(String text, Charset charset) throws IOException { Charset cs = charset != null ? charset : Charsets.ISO_8859_1; TextBody body = bodyFactory != null ? bodyFactory.textBody( InputStreams.create(text, cs), cs.name()) : BasicBodyFactory.INSTANCE.textBody(text, cs); BodyPart bodyPart = BodyPartBuilder.create() .setBody(body) .setContentType("text/plain", new NameValuePair("charset", cs.name())) .setContentTransferEncoding(Charsets.US_ASCII.equals(cs) ? "7bit" : "quoted-printable") .build(); return addBodyPart(bodyPart); }
/** * Sets text of this message with the given MIME subtype and charset. * * @param text * the text. * @param charset * the charset of the text. * @param subtype * the text subtype (e.g. "plain", "html" or * "xml"). */ public Builder setBody(String text, String subtype, Charset charset) throws IOException { String mimeType = "text/" + (subtype != null ? subtype : "plain"); if (charset != null) { setField(Fields.contentType(mimeType, new NameValuePair("charset", charset.name()))); } else { setField(Fields.contentType(mimeType)); } Body textBody; if (bodyFactory != null) { textBody = bodyFactory.textBody( InputStreams.create(text, charset), charset != null ? charset.name() : null); } else { textBody = BasicBodyFactory.INSTANCE.textBody(text, charset); } return setBody(textBody); }
/** * Sets text of this message with the given MIME subtype and charset. * * @param text * the text. * @param charset * the charset of the text. * @param subtype * the text subtype (e.g. "plain", "html" or * "xml"). */ public BodyPartBuilder setBody(String text, String subtype, Charset charset) throws IOException { String mimeType = "text/" + (subtype != null ? subtype : "plain"); if (charset != null) { setField(Fields.contentType(mimeType, new NameValuePair("charset", charset.name()))); } else { setField(Fields.contentType(mimeType)); } Body textBody; if (bodyFactory != null) { textBody = bodyFactory.textBody( InputStreams.create(text, charset), charset != null ? charset.name() : null); } else { textBody = BasicBodyFactory.INSTANCE.textBody(text, charset); } return setBody(textBody); }