use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class SqlInfo method buildStatement.
public SQLiteStatement buildStatement(SQLiteDatabase database) {
SQLiteStatement result = database.compileStatement(sql);
if (bindArgs != null) {
for (int i = 1; i < bindArgs.size() + 1; i++) {
KeyValue kv = bindArgs.get(i - 1);
Object value = ColumnUtils.convert2DbValueIfNeeded(kv.value);
if (value == null) {
result.bindNull(i);
} else {
ColumnConverter converter = ColumnConverterFactory.getColumnConverter(value.getClass());
ColumnDbType type = converter.getColumnDbType();
switch(type) {
case INTEGER:
result.bindLong(i, ((Number) value).longValue());
break;
case REAL:
result.bindDouble(i, ((Number) value).doubleValue());
break;
case TEXT:
result.bindString(i, value.toString());
break;
case BLOB:
result.bindBlob(i, (byte[]) value);
break;
default:
result.bindNull(i);
break;
}
// end switch
}
}
}
return result;
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method setHeader.
/**
* 覆盖header
*
* @param name
* @param value
*/
public void setHeader(String name, String value) {
Header header = new Header(name, value, true);
Iterator<Header> it = headers.iterator();
while (it.hasNext()) {
KeyValue kv = it.next();
if (name.equals(kv.key)) {
it.remove();
}
}
this.headers.add(header);
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class HttpRequest method buildQueryUrl.
// build query
@Override
protected String buildQueryUrl(RequestParams params) {
String uri = params.getUri();
StringBuilder queryBuilder = new StringBuilder(uri);
if (!uri.contains("?")) {
queryBuilder.append("?");
} else if (!uri.endsWith("?")) {
queryBuilder.append("&");
}
List<KeyValue> queryParams = params.getQueryStringParams();
if (queryParams != null) {
for (KeyValue kv : queryParams) {
String name = kv.key;
String value = kv.getValueStr();
if (!TextUtils.isEmpty(name) && value != null) {
queryBuilder.append(Uri.encode(name, params.getCharset())).append("=").append(Uri.encode(value, params.getCharset())).append("&");
}
}
}
if (queryBuilder.charAt(queryBuilder.length() - 1) == '&') {
queryBuilder.deleteCharAt(queryBuilder.length() - 1);
}
if (queryBuilder.charAt(queryBuilder.length() - 1) == '?') {
queryBuilder.deleteCharAt(queryBuilder.length() - 1);
}
return queryBuilder.toString();
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class MultipartBody method writeTo.
@Override
public void writeTo(OutputStream out) throws IOException {
if (callBackHandler != null && !callBackHandler.updateProgress(total, current, true)) {
throw new Callback.CancelledException("upload stopped!");
}
for (KeyValue kv : multipartParams) {
String name = kv.key;
Object value = kv.value;
if (!TextUtils.isEmpty(name) && value != null) {
writeEntry(out, name, value);
}
}
writeLine(out, TWO_DASHES_BYTES, BOUNDARY_PREFIX_BYTES, boundaryPostfixBytes, TWO_DASHES_BYTES);
out.flush();
if (callBackHandler != null) {
callBackHandler.updateProgress(total, total, true);
}
}
use of org.xutils.common.util.KeyValue in project xUtils3 by wyouflf.
the class BaseParams method toString.
@Override
public String toString() {
checkBodyParams();
final StringBuilder sb = new StringBuilder();
if (!queryStringParams.isEmpty()) {
for (KeyValue kv : queryStringParams) {
sb.append(kv.key).append("=").append(kv.value).append("&");
}
sb.deleteCharAt(sb.length() - 1);
}
if (HttpMethod.permitsRequestBody(this.method)) {
sb.append("<");
if (!TextUtils.isEmpty(bodyContent)) {
sb.append(bodyContent);
} else {
if (!bodyParams.isEmpty()) {
for (KeyValue kv : bodyParams) {
sb.append(kv.key).append("=").append(kv.value).append("&");
}
sb.deleteCharAt(sb.length() - 1);
}
}
sb.append(">");
}
return sb.toString();
}
Aggregations