private ContentType getContentOrDefault(final ContentType def) {
return this.contentType != null ? this.contentType : def;
}
public HttpEntity build() {
AbstractHttpEntity e;
if (this.text != null) {
e = new StringEntity(this.text, getContentOrDefault(ContentType.DEFAULT_TEXT));
} else if (this.binary != null) {
e = new ByteArrayEntity(this.binary, getContentOrDefault(ContentType.DEFAULT_BINARY));
} else if (this.stream != null) {
e = new InputStreamEntity(this.stream, 1, getContentOrDefault(ContentType.DEFAULT_BINARY));
} else if (this.parameters != null) {
e = new UrlEncodedFormEntity(this.parameters,
this.contentType != null ? this.contentType.getCharset() : null);
} else if (this.serializable != null) {
e = new SerializableEntity(this.serializable);
e.setContentType(ContentType.DEFAULT_BINARY.toString());
} else if (this.file != null) {
e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY));
} else {
e = new BasicHttpEntity();
}
if (e.getContentType() != null && this.contentType != null) {
e.setContentType(this.contentType.toString());
}
e.setContentEncoding(this.contentEncoding);
e.setChunked(this.chunked);
if (this.gzipCompress) {
return new GzipCompressingEntity(e);
}
return e;
}