use of lucee.commons.net.http.httpclient.entity.EmptyHttpEntity in project Lucee by lucee.
the class HTTPEngine4Impl method toHttpEntity.
/**
* convert input to HTTP Entity
*
* @param value
* @param mimetype
* not used for binary input
* @param charset
* not used for binary input
* @return
* @throws IOException
*/
private static HttpEntity toHttpEntity(Object value, String mimetype, String charset) throws IOException {
if (value instanceof HttpEntity)
return (HttpEntity) value;
// content type
ContentType ct = HTTPEngine.toContentType(mimetype, charset);
try {
if (value instanceof TemporaryStream) {
if (ct != null)
return new TemporaryStreamHttpEntity((TemporaryStream) value, ct);
return new TemporaryStreamHttpEntity((TemporaryStream) value, null);
} else if (value instanceof InputStream) {
if (ct != null)
return new ByteArrayEntity(IOUtil.toBytes((InputStream) value), ct);
return new ByteArrayEntity(IOUtil.toBytes((InputStream) value));
} else if (Decision.isCastableToBinary(value, false)) {
if (ct != null)
return new ByteArrayEntity(Caster.toBinary(value), ct);
return new ByteArrayEntity(Caster.toBinary(value));
} else {
boolean wasNull = false;
if (ct == null) {
wasNull = true;
ct = ContentType.APPLICATION_OCTET_STREAM;
}
String str = Caster.toString(value);
if (str.equals("<empty>")) {
return new EmptyHttpEntity(ct);
}
if (wasNull && !StringUtil.isEmpty(charset, true))
return new StringEntity(str, charset.trim());
else
return new StringEntity(str, ct);
}
} catch (Exception e) {
throw ExceptionUtil.toIOException(e);
}
}
Aggregations