<commit_before>package com.chinamobile.iot.onenet;

import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class BaseBinRequest implements IRequest {

    private ResponseListener mListener;

    public BaseBinRequest(ResponseListener listener) {
        mListener = listener;
    }

    protected void execute(AsyncHttpClient client, String url, File file) {

        RequestParams params = new RequestParams();
        try {
            params.put("file", file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        post(client, url, params);
    }

    protected void execute(AsyncHttpClient client, String url, InputStream stream) {
        RequestParams params = new RequestParams();
        params.put("file", stream);
        post(client, url, params);
    }

    protected void execute(AsyncHttpClient client, String url, String value) {
        RequestParams params = new RequestParams();
        params.put("text", value);
        post(client, url, params);
    }

    protected void execute(AsyncHttpClient client, String url, byte[] value) {
        RequestParams params = new RequestParams();
        params.put("text", value);
        post(client, url, params);
    }

    private void post(AsyncHttpClient client, final String url, RequestParams params) {
        client.post(url, params, new AsyncHttpResponseHandler() {<commit_msg>修改发送命令方式<commit_after>package com.chinamobile.iot.onenet;

import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.json.JSONObject;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class BaseBinRequest implements IRequest {

    private ResponseListener mListener;

    public BaseBinRequest(ResponseListener listener) {
        mListener = listener;
    }

    @Deprecated
    protected void execute(AsyncHttpClient client, String url, File file) {
        HttpEntity entity = new FileEntity(file, "application/octet-stream");
        post(client, url, entity, "application/octet-stream");
    }

    @Deprecated
    protected void execute(AsyncHttpClient client, String url, InputStream stream) {
        byte[] bytes = new byte[1024 * 64];
        try {
            stream.read(bytes, 0, stream.available());
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpEntity entity = new ByteArrayEntity(bytes);
        post(client, url, entity, "application/octet-stream");
    }

    protected void execute(AsyncHttpClient client, String url, String value) {
        HttpEntity entity = null;
        try {
            entity = new StringEntity(value, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        post(client, url, entity, "text/plain");
    }

    protected void execute(AsyncHttpClient client, String url, byte[] value) {
        ByteArrayEntity entity = new ByteArrayEntity(value);
        entity.setContentEncoding("utf-8");
        post(client, url, entity, "application/octet-stream");
    }

    private void post(AsyncHttpClient client, final String url, HttpEntity entity, String contentType) {
        client.post(null, url, entity, contentType, new AsyncHttpResponseHandler() {
{'fraction_non_alphanumeric': 0.09857035364936043, 'fraction_numerical': 0.002257336343115124, 'mean_word_length': 3.431111111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3636477', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1063, 'n_words': 274}