Search in sources :

Example 6 with KeyValue

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;
}
Also used : KeyValue(org.xutils.common.util.KeyValue) SQLiteStatement(android.database.sqlite.SQLiteStatement) ColumnConverter(org.xutils.db.converter.ColumnConverter)

Example 7 with KeyValue

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);
}
Also used : KeyValue(org.xutils.common.util.KeyValue)

Example 8 with KeyValue

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();
}
Also used : KeyValue(org.xutils.common.util.KeyValue)

Example 9 with KeyValue

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);
    }
}
Also used : KeyValue(org.xutils.common.util.KeyValue)

Example 10 with KeyValue

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();
}
Also used : KeyValue(org.xutils.common.util.KeyValue)

Aggregations

KeyValue (org.xutils.common.util.KeyValue)15 JSONObject (org.json.JSONObject)3 ArrayList (java.util.ArrayList)2 ColumnEntity (org.xutils.db.table.ColumnEntity)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 DbManager (org.xutils.DbManager)1 ColumnConverter (org.xutils.db.converter.ColumnConverter)1 DbModel (org.xutils.db.table.DbModel)1 DbException (org.xutils.ex.DbException)1 BodyItemWrapper (org.xutils.http.body.BodyItemWrapper)1