private static HttpEntity toHttpEntity(Object value,String mimetype,String charset) throws IOException {
  if (value instanceof HttpEntity)   return (HttpEntity)value;
  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);
  }
}

private static HttpEntity toHttpEntity ( Object value , String mimetype , String charset ) throws IOException { if ( value instanceof HttpEntity ) return ( HttpEntity ) value ; 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 ) ; } }
convert input to http entity
