Example usage for java.util Map toString

List of usage examples for java.util Map toString

Introduction

In this page you can find the example usage for java.util Map toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:azad.hallaji.farzad.com.masirezendegi.ExplainMoshaver.java

void setAlage() {

    ProgressBar progressbarsandaha = (ProgressBar) findViewById(R.id.progressbarsandaha);
    progressbarsandaha.setVisibility(View.VISIBLE);

    String url = "http://telyar.dmedia.ir/webservice/Set_favourite/";
    StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override//w  ww .  j av  a  2s  . c  om
                public void onResponse(String response) {
                    //This code is executed if the server responds, whether or not the response contains data.
                    //The String 'response' contains the server's response.
                    Log.i("aladfffgree", response);
                    //Toast.makeText(getApplicationContext(), response , Toast.LENGTH_LONG).show();
                    //Toast.makeText(getApplicationContext(), response , Toast.LENGTH_LONG).show();

                    ProgressBar progressbarsandaha = (ProgressBar) findViewById(R.id.progressbarsandaha);
                    progressbarsandaha.setVisibility(View.INVISIBLE);

                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.getString("Status").equals("1")) {
                            IsFavorite = !IsFavorite;
                            if (IsFavorite) {
                                alagestarmoshaver.setImageResource(R.drawable.alage1);
                            } else {
                                alagestarmoshaver.setImageResource(R.drawable.alage0);
                            }
                        }
                        Toast.makeText(getApplicationContext(), jsonObject.getString("Message"),
                                Toast.LENGTH_SHORT).show();

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }
            }, new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
                @Override
                public void onErrorResponse(VolleyError error) {
                    //This code is executed if there is an error.
                }
            }) {
        protected Map<String, String> getParams() {
            String s = IsFavorite ? "-1" : "1";
            Map<String, String> MyData = new HashMap<String, String>();
            //Log.i("asasasasasasa",adviseridm+"/"+GlobalVar.getDeviceID());
            MyData.put("userid", GlobalVar.getUserID()); //Add the data you'd like to send to the server.
            MyData.put("contentid", adviseridm); //Add the data you'd like to send to the server.
            MyData.put("status", s); //Add the data you'd like to send to the server.
            MyData.put("contenttype", "adviser"); //Add the data you'd like to send to the server.
            MyData.put("deviceid", GlobalVar.getDeviceID()); //Add the data you'd like to send to the server.
            Log.i("aladfffgree", MyData.toString());
            return MyData;
        }
    };
    MyRequestQueue.add(MyStringRequest);
}

From source file:com.comcast.oscar.tlv.TlvAssembler.java

/**
 * //from  w  w  w.java 2 s.  c om
 * @param joTlvDictionary   
 * @return TlvBuilder
 * @throws JSONException */
private TlvBuilder buildTlvFromTlvDictionary(JSONObject joTlvDictionary) throws JSONException {

    boolean localDebug = Boolean.FALSE;

    if (localDebug | debug) {
        System.out.println("TlvAssembler.buildTlvFromTlvDictionary(jo): " + joTlvDictionary.toString());
        System.out.println("TlvAssembler.buildTlvFromTlvDictionary.super: " + super.toString());
    }

    TlvBuilder tbLocalTlvBuilder = new TlvBuilder();

    //Need to determine if there is a Value in the Object
    if (joTlvDictionary.has(Dictionary.VALUE)) {

        //Get TLV Value Length
        int iTlvValueLength = joTlvDictionary.getInt(Dictionary.LENGTH_MAX);

        //Get the DataTpe
        String sDataType = joTlvDictionary.getString(Dictionary.DATA_TYPE);

        //Get Type
        int iType = joTlvDictionary.getInt(Dictionary.TYPE);

        /*
         * 140320 -mgarcia
         *    Issue found with submitting no value for the Value Tag.
         *    Only Strings will be allowed to have no Value
         *    Else Return an empty TlvBuilder Object
         */
        if ((joTlvDictionary.getString(Dictionary.VALUE).matches("\\s*"))
                && ((!sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING_NULL_TERMINATED))
                        || (!sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING)))) {
            return tbLocalTlvBuilder;
        }

        //Determine how to encode the value
        if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_INTEGER)) {

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary().DATA_TYPE_INTEGER: "
                        + tbLocalTlvBuilder.toString());

            //Get Integer Value
            int iTlvValue = joTlvDictionary.getInt(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString();
            hsTlvValue.add(iTlvValue);

            //PADD If Necessary
            hsTlvValue.prefixNullPaddToLength(iTlvValueLength);

            //Add Integer TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue);
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("DATA_TYPE_INTEGER: " + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_OID)) {

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary().DATA_TYPE_OID: "
                        + tbLocalTlvBuilder.toString());

            //Convert JSONObject to Map
            //Map<String,Object> msoOidDataTypeValue = JSONTools.toMap(joTlvDictionary.getJSONObject(Dictionary.VALUE));

            JSONArray ja = joTlvDictionary.getJSONArray(Dictionary.VALUE);

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary()->ja.getJSONObject(0): "
                        + ja.getJSONObject(0).toString());

            Map<String, Object> msoOidDataTypeValue = JSONTools.toMap(ja.getJSONObject(0));

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary().msoODV: " + msoOidDataTypeValue.toString());

            OIDBERConversion obcOidDataTypeValue = new OIDBERConversion(msoOidDataTypeValue);

            if (joTlvDictionary.getInt(Dictionary.BYTE_LENGTH) > 1) {

                //In this case, this is using an Extended SNMP OID and create a VarBind TLV
                TlvVariableBinding tvbLocal = new TlvVariableBinding();

                //Build Extended OID to TlvVariableBinding
                try {
                    tvbLocal.add(joTlvDictionary.getInt(Dictionary.TYPE), obcOidDataTypeValue.getBER(),
                            joTlvDictionary.getInt(Dictionary.BYTE_LENGTH));
                } catch (TlvException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                //Added TlvVariableBinding to TlvBuilder
                tbLocalTlvBuilder.add(tvbLocal);

            } else {
                //ADD OID TLV
                try {
                    tbLocalTlvBuilder.add(joTlvDictionary.getInt(Dictionary.TYPE),
                            obcOidDataTypeValue.getBER());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_OID: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY)) {

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary().DATA_TYPE_BYTE_ARRAY: "
                        + tbLocalTlvBuilder.toString());

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(HexString.toByteArray(sTlvValue));

            //Add Integer TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_BYTE_ARRAY: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING_NULL_TERMINATED)) {

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary().DATA_TYPE_STRING_NULL_TERMINATED: "
                        + tbLocalTlvBuilder.toString());

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString();

            //Append Null Terminates at the end of the string
            hsTlvValue.add(sTlvValue, true);

            //Add Integer TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_STRING_NULL_TERMINATED: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING)) {

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary().DATA_TYPE_STRING: "
                        + tbLocalTlvBuilder.toString());

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert String to HexString
            HexString hsTlvValue = new HexString();
            hsTlvValue.add(sTlvValue);

            //Add Integer TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_STRING: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_MULTI_TLV_BYTE_ARRAY)) {

            if (debug | localDebug)
                System.out.println("Type: " + iType
                        + " -> TlvBuilder.buildTlvFromTlvDictionary().DATA_TYPE_MULTI_TLV_BYTE_ARRAY: "
                        + tbLocalTlvBuilder.toString());

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(HexString.toByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out
                        .println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_MULTI_TLV_BYTE_ARRAY: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_STRING_BITS)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_STRING_BITS: " + sTlvValue);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(DataTypeFormatConversion.binaryBitMaskToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_STRING_BITS: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_DOUBLE_BYTE_ARRAY)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(DataTypeFormatConversion.doubleByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_DOUBLE_BYTE_ARRAY: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY_IPV4_ADDR)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(DataTypeFormatConversion.inetAddressToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out
                        .println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_BYTE_ARRAY_IPV4_ADDR: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE_ARRAY_IPV6_ADDR)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(DataTypeFormatConversion.inetAddressToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out
                        .println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_BYTE_ARRAY_IPV6_ADDR: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_IPV4_ADDR)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(
                    DataTypeFormatConversion.ipv4TransportAddressToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_TRANSPORT_ADDR_IPV4_ADDR: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_IPV6_ADDR)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(
                    DataTypeFormatConversion.ipv6TransportAddressToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_TRANSPORT_ADDR_IPV6_ADDR: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_TRANSPORT_ADDR_INET_ADDR)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(
                    DataTypeFormatConversion.inetTransportAddressToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println(
                        "TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_TRANSPORT_ADDR_INET_ADDR: "
                                + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_MAC_ADDRESS)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(
                    DataTypeFormatConversion.macAddressFormatToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_MAC_ADDRESS: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_BYTE)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert Integer to Byte Array
            HexString hsTlvValue = new HexString(DataTypeFormatConversion.hexStringToByte(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsTlvValue.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_BYTE: "
                        + tbLocalTlvBuilder.toString());

        } else if (sDataType.equals(DataTypeDictionaryReference.DATA_TYPE_OID_ASN1_OBJECT_6)) {

            //Get String Value HEX String
            String sTlvValue = joTlvDictionary.getString(Dictionary.VALUE);

            //Convert OID to Byte Array
            HexString hsOIDObj6 = new HexString(DataTypeFormatConversion.oidObj6ToByteArray(sTlvValue));

            //Add Byte Array TLV
            try {
                tbLocalTlvBuilder.add(iType, hsOIDObj6.toByteArray());
            } catch (TlvException e) {
                e.printStackTrace();
            }

            if (debug | localDebug)
                System.out.println("TlvAssembler.buildTlvFromTlvDictionary() -> DATA_TYPE_OID_ASN1_OBJECT_6: "
                        + tbLocalTlvBuilder.toString());

        }

    }

    return tbLocalTlvBuilder;
}

From source file:net.di2e.ecdr.source.rest.AbstractCDRSource.java

public void setParameterMap(String parameterMapStr) {
    Map<String, String> convertedMap = SearchUtils.convertToMap(parameterMapStr);
    Map<String, String> translateMap = new HashMap<>(convertedMap.size());
    for (Entry<String, String> entry : convertedMap.entrySet()) {
        if (parameterMatchMap.containsKey(entry.getKey())) {
            translateMap.put(parameterMatchMap.get(entry.getKey()), entry.getValue());
        } else {//w w  w.  jav a  2 s  . co  m
            translateMap.put(entry.getKey(), entry.getValue());
        }
    }
    LOGGER.debug("Updating parameterMap with new entries: {}", convertedMap.toString());
    parameterMap = translateMap;
}

From source file:it.chefacile.app.MainActivity.java

public String[] getSuggestion() {
    int i = 0;//from ww w .j a v a2 s  .c  om
    Map<String, Integer> map;
    map = chefacileDb.getDataInMapIngredient();
    map = sortByValue(map);
    Log.d("MAPPA METODO:", map.toString());

    String[] array = new String[map.size()];

    if (map != null || !map.isEmpty()) {

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            array[i] = entry.getKey();
            i++;

        }

        String[] res = new String[3];

        for (int j = 0; j < 3; j++) {
            res[j] = array[j];
        }

        return res;

    } else
        return null;

}

From source file:it.chefacile.app.MainActivity.java

public String[] getCount() {
    int i = 0;//from   www  . j a  v a2s .c  o m
    Map<String, Integer> map;
    map = chefacileDb.getDataInMapIngredient();
    map = sortByValue(map);
    Log.d("MAPPA METODO:", map.toString());

    String[] array = new String[map.size()];

    if (map != null || !map.isEmpty()) {

        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            array[i] = String.valueOf(entry.getValue());
            i++;

        }

        String[] res = new String[3];

        for (int j = 0; j < 3; j++) {
            res[j] = array[j];
        }

        return res;

    } else
        return null;

}

From source file:org.egov.collection.web.actions.citizen.OnlineReceiptAction.java

public String getMsg() {
    if (responseMsg != null && responseMsg == "") {
        final HttpServletRequest httpRequest = ServletActionContext.getRequest();
        final Enumeration<String> paramNames = httpRequest.getParameterNames();
        final Map<String, String> responseMap = new HashMap<>(0);
        while (paramNames.hasMoreElements()) {
            final String paramName = paramNames.nextElement();
            final String paramValue = httpRequest.getParameter(paramName);
            if (isNotBlank(paramValue))
                responseMap.put(paramName, paramValue);
        }// w  w  w  . ja  v a  2s .  c  o  m
        responseMsg = responseMap.toString();
    }
    LOGGER.debug("responseMsg::::::" + responseMsg);
    return responseMsg;
}

From source file:com.jing.ebike.controller.UserController.java

@SuppressWarnings("unchecked")
@RequestMapping(value = "setDefenceTest")
@ResponseBody//from  ww w. jav  a2s.c o m
@Transactional
public GeneralResponse setDefenceTest(String mobile, String set_status, String carNum,
        HttpServletRequest request, HttpServletResponse response) {
    GeneralResponse message = new GeneralResponse();
    String defenceOperation = "";
    if ("0".equals(set_status))
        defenceOperation = "";
    try {
        String path = "http://122.226.49.30:60001/wy/wy/wx/pandect-getdata.action";
        Map<String, String> map = new HashMap<String, String>();
        map.put("rtype", "1");
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData = new HashMap<String, Object>();
        logger.info("---------------setDefenceTest----------mobile:" + mobile + ",set_status:" + set_status
                + ",carNum:" + carNum);
        mapData.put("\"mobi_num\"", "\"" + mobile + "\"");//???
        mapData.put("\"set_status\"", "\"" + set_status + "\"");//
        mapData.put("\"licenseNumber\"", "\"" + carNum + "\"");//?
        mapData.put("\"md_five\"", "\"itylhogiwuEDjfMK\"");//MD5key=================?
        System.out.println("?=sign?" + mapData.toString());
        String md5Str = MD5Utils.getMD5Str(mapData.toString());//MD5
        mapData.put("\"sign\"", "\"" + md5Str + "\"");//DESsign
        mapData.remove("\"md_five\"");
        //
        String sf_encrypt_Str = DESUtils.encrypt(mapData.toString());
        logger.info("---------------setDefenceTest----------encrypt_Str:" + sf_encrypt_Str);

        map.put("data", sf_encrypt_Str);
        String encode = "utf8";
        HttpRequestUtils instance = new HttpRequestUtils();
        String result = instance.sendHttpClientPost(path, map, encode);
        logger.info("----------setDefenceTest-----result----------" + result);
        String resultAfterDecrypt = DESUtils.decrypt(result);//"Qia0wVT6+gGqDvNHi6qVoHljL16CORbw4afSJ+h2Mv+jwjammp0T2GgCyeZIuEQe"
        logger.info("----------setDefenceTest-----resultAfterDecrypt----------" + resultAfterDecrypt);
        if (resultAfterDecrypt.indexOf("true") > 0) {
            JSONObject strjsonObject = JSONObject.fromObject(resultAfterDecrypt);
            Map<String, Object> map1Json = new HashMap<String, Object>();
            map1Json = JSONObject.fromObject(strjsonObject);
            String lastaddr = map1Json.get("lastaddr").toString();
            logger.info(
                    "------setDefenceTest---------lastaddr1----------" + map1Json.get("lastaddr").toString());
            message.setRes(lastaddr == null ? "" : lastaddr);
            CarNumber carNumber = new CarNumber();
            carNumber.setCarNum(carNum);
            carNumber.setDefenceStatus(Integer.valueOf(set_status));
            carNumberService.updateByNum(carNumber);
            message.setCode(1);
            message.setMsg("" + carNum + defenceOperation + "?" + ",lastaddr:" + lastaddr);
        } else {
            message.setCode(0);
            message.setMsg("" + carNum + defenceOperation + "");
        }
    } catch (Exception e) {
        message.setCode(0);
        message.setMsg(e.getMessage());
    }
    return message;
}

From source file:org.apache.zeppelin.submarine.job.thread.TensorboardRunThread.java

public void run() {
    SubmarineUI submarineUI = submarineJob.getSubmarineUI();

    boolean tryLock = lockRunning.tryLock();

    try {//from  w ww  . j  a v  a  2s  .  c  om
        Properties properties = submarineJob.getProperties();
        String tensorboardName = SubmarineUtils.getTensorboardName(submarineJob.getUserName());
        if (true == running.get()) {
            String message = String.format("tensorboard %s already running.", tensorboardName);
            submarineUI.outputLog("WARN", message);
            LOGGER.warn(message);
            return;
        }
        running.set(true);

        HashMap jinjaParams = SubmarineUtils.propertiesToJinjaParams(properties, submarineJob, false);
        // update jobName -> tensorboardName
        jinjaParams.put(SubmarineConstants.JOB_NAME, tensorboardName);

        URL urlTemplate = Resources.getResource(SubmarineJob.SUBMARINE_TENSORBOARD_JINJA);
        String template = Resources.toString(urlTemplate, Charsets.UTF_8);
        Jinjava jinjava = new Jinjava();
        String submarineCmd = jinjava.render(template, jinjaParams);
        // If the first line is a newline, delete the newline
        int firstLineIsNewline = submarineCmd.indexOf("\n");
        if (firstLineIsNewline == 0) {
            submarineCmd = submarineCmd.replaceFirst("\n", "");
        }
        StringBuffer sbLogs = new StringBuffer(submarineCmd);
        submarineUI.outputLog("Submarine submit command", sbLogs.toString());

        long timeout = Long
                .valueOf(properties.getProperty(SubmarineJob.TIMEOUT_PROPERTY, SubmarineJob.defaultTimeout));
        CommandLine cmdLine = CommandLine.parse(SubmarineJob.shell);
        cmdLine.addArgument(submarineCmd, false);
        DefaultExecutor executor = new DefaultExecutor();
        ExecuteWatchdog watchDog = new ExecuteWatchdog(timeout);
        executor.setWatchdog(watchDog);
        StringBuffer sbLogOutput = new StringBuffer();
        executor.setStreamHandler(new PumpStreamHandler(new LogOutputStream() {
            @Override
            protected void processLine(String line, int level) {
                line = line.trim();
                if (!StringUtils.isEmpty(line)) {
                    sbLogOutput.append(line + "\n");
                }
            }
        }));

        if (Boolean.valueOf(properties.getProperty(SubmarineJob.DIRECTORY_USER_HOME))) {
            executor.setWorkingDirectory(new File(System.getProperty("user.home")));
        }

        Map<String, String> env = new HashMap<>();
        String launchMode = (String) jinjaParams.get(SubmarineConstants.INTERPRETER_LAUNCH_MODE);
        if (StringUtils.equals(launchMode, "yarn")) {
            // Set environment variables in the container
            String javaHome, hadoopHome, hadoopConf;
            javaHome = (String) jinjaParams.get(SubmarineConstants.DOCKER_JAVA_HOME);
            hadoopHome = (String) jinjaParams.get(SubmarineConstants.DOCKER_HADOOP_HDFS_HOME);
            hadoopConf = (String) jinjaParams.get(SubmarineConstants.SUBMARINE_HADOOP_CONF_DIR);
            env.put("JAVA_HOME", javaHome);
            env.put("HADOOP_HOME", hadoopHome);
            env.put("HADOOP_HDFS_HOME", hadoopHome);
            env.put("HADOOP_CONF_DIR", hadoopConf);
            env.put("YARN_CONF_DIR", hadoopConf);
            env.put("CLASSPATH", "`$HADOOP_HDFS_HOME/bin/hadoop classpath --glob`");
        }

        LOGGER.info("Execute EVN: {}, Command: {} ", env.toString(), submarineCmd);

        AtomicBoolean cmdLineRunning = new AtomicBoolean(true);
        executor.execute(cmdLine, env, new DefaultExecuteResultHandler() {
            @Override
            public void onProcessComplete(int exitValue) {
                String message = String.format("jobName %s ProcessComplete exit value is : %d", tensorboardName,
                        exitValue);
                LOGGER.info(message);
                submarineUI.outputLog("TENSORBOARD RUN COMPLETE", message);
                cmdLineRunning.set(false);
            }

            @Override
            public void onProcessFailed(ExecuteException e) {
                String message = String.format("jobName %s ProcessFailed exit value is : %d, exception is : %s",
                        tensorboardName, e.getExitValue(), e.getMessage());
                LOGGER.error(message);
                submarineUI.outputLog("TENSORBOARD RUN FAILED", message);
                cmdLineRunning.set(false);
            }
        });
        int loopCount = 100;
        while ((loopCount-- > 0) && cmdLineRunning.get() && running.get()) {
            Thread.sleep(1000);
        }
        if (watchDog.isWatching()) {
            watchDog.destroyProcess();
            Thread.sleep(1000);
        }
        if (watchDog.isWatching()) {
            watchDog.killedProcess();
        }

        // Check if it has been submitted to YARN
        Map<String, Object> jobState = submarineJob.getJobStateByYarn(tensorboardName);
        loopCount = 50;
        while ((loopCount-- > 0) && !jobState.containsKey("state") && running.get()) {
            Thread.sleep(3000);
            jobState = submarineJob.getJobStateByYarn(tensorboardName);
        }

        if (!jobState.containsKey("state")) {
            String message = String.format("tensorboard %s was not submitted to YARN!", tensorboardName);
            LOGGER.error(message);
            submarineUI.outputLog("JOR RUN FAILED", message);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        submarineUI.outputLog("Exception", e.getMessage());
    } finally {
        running.set(false);
        lockRunning.unlock();
    }
}

From source file:com.aerospike.load.AsWriterTask.java

private boolean processLine() {
    log.debug("processing  File:line " + Utils.getFileName(fileName) + this.lineNumber);
    bins = new ArrayList<Bin>();
    boolean lineProcessed = false;
    long errorTotal = 0;
    try {//ww w.j a v  a2 s  .c o m
        if (columns.size() != counters.write.colTotal) {
            if (columns.size() < counters.write.colTotal) {
                log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber
                        + " Number of column mismatch:Columns in data file is less than number of column in config file.");
            } else {
                throw new ParseException(lineNumber);
            }
        }

        //retrieve set name first
        for (ColumnDefinition metadataColumn : this.metadataMapping) {
            if (metadataColumn.staticValue
                    && metadataColumn.getBinNameHeader().equalsIgnoreCase(Constants.SET)) {
                this.set = metadataColumn.binValueHeader;
            } else {
                String metadataRawText = this.columns.get(metadataColumn.getBinValuePos());
                if (metadataColumn.getBinNameHeader().equalsIgnoreCase(Constants.SET)) {
                    if (this.set == null) {
                        this.set = metadataRawText;
                    }
                }
            }
        }
        // use set name to create key
        for (ColumnDefinition metadataColumn : this.metadataMapping) {
            if (metadataColumn.getBinNameHeader().equalsIgnoreCase(Constants.KEY)) {
                String metadataRawText = this.columns.get(metadataColumn.getBinValuePos());
                if (metadataColumn.getSrcType() == SrcColumnType.INTEGER) {
                    Long integer = Long.parseLong(metadataRawText);
                    this.key = new Key(this.nameSpace, this.set, integer);
                } else {
                    this.key = new Key(this.nameSpace, this.set, metadataRawText);
                }
            }
        }

        for (ColumnDefinition binColumn : this.binMapping) {
            Bin bin = null;

            if (!binColumn.staticName) {
                binColumn.binNameHeader = this.columns.get(binColumn.binNamePos);
            }

            if (!binColumn.staticValue) {
                String binRawText = null;
                if (binColumn.binValueHeader != null
                        && binColumn.binValueHeader.toLowerCase().equals(Constants.SYSTEM_TIME)) {
                    SimpleDateFormat sdf = new SimpleDateFormat(binColumn.getEncoding());//dd/MM/yyyy
                    Date now = new Date();
                    binRawText = sdf.format(now);
                } else {
                    binRawText = this.columns.get(binColumn.getBinValuePos());
                }

                if (binRawText.equals(""))
                    continue;

                switch (binColumn.getSrcType()) {
                case INTEGER:
                    //Server stores all integer type data in 64bit so use long
                    Long integer;
                    try {
                        integer = Long.parseLong(binRawText);
                        bin = new Bin(binColumn.getBinNameHeader(), integer);
                    } catch (Exception pi) {
                        log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber
                                + " Integer/Long Parse Error:" + pi);
                    }

                    break;
                case FLOAT:

                    /**
                     * Floating type data can be stored as 8 byte byte array.
                      */
                    try {
                        float binfloat = Float.parseFloat(binRawText);
                        byte[] byteFloat = ByteBuffer.allocate(8).putFloat(binfloat).array();
                        bin = new Bin(binColumn.getBinNameHeader(), byteFloat);
                    } catch (Exception e) {
                        log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber
                                + " Floating number Parse Error:" + e);
                    }
                    break;
                case STRING:
                    bin = new Bin(binColumn.getBinNameHeader(), binRawText);
                    break;
                case BLOB:
                    if (binColumn.getDstType().equals(DstColumnType.BLOB)) {
                        if (binColumn.encoding.equalsIgnoreCase(Constants.HEX_ENCODING))
                            bin = new Bin(binColumn.getBinNameHeader(), this.toByteArray(binRawText)); //TODO
                    }

                    break;
                case LIST:
                    /*
                     * Assumptions
                     * 1. Items are separated by a colon ','
                     * 2. Item value will be a string
                     * 3. List will be in double quotes
                     * 
                     * No support for nested maps or nested lists
                     * 
                     */
                    List<String> list = new ArrayList<String>();
                    String[] listValues = binRawText.split(Constants.LIST_DELEMITER, -1);
                    if (listValues.length > 0) {
                        for (String value : listValues) {
                            list.add(value.trim());
                        }
                        bin = Bin.asList(binColumn.getBinNameHeader(), list);
                    } else {
                        bin = null;
                        log.error("Error: Cannot parse to a list: " + binRawText);
                    }
                    break;
                case MAP:
                    /*
                     * Asumptions:
                     * 1. Items are separated by a colon ','
                     * 2. Name value pairs are separated by equals ':'
                     * 3. Map key is a string
                     * 4. Map value will be a string
                     * 5. Map will be in double quotes
                     * 
                     * No support for nested maps or nested lists
                     * 
                     */
                    Map<String, Object> map = new HashMap<String, Object>();
                    String[] mapValues = binRawText.split(Constants.MAP_DELEMITER, -1);
                    if (mapValues.length > 0) {
                        for (String value : mapValues) {
                            String[] kv = value.split(Constants.MAPKEY_DELEMITER);
                            if (kv.length != 2)
                                log.error("Error: Cannot parse map <k,v> using: " + kv);
                            else
                                map.put(kv[0].trim(), kv[1].trim());
                        }
                        log.debug(map.toString());
                        bin = Bin.asMap(binColumn.getBinNameHeader(), map);
                    } else {
                        bin = null;
                        log.error("Error: Cannot parse to a map: " + binRawText);
                    }
                    break;
                case JSON:
                    try {
                        log.debug(binRawText);
                        if (jsonParser == null)
                            jsonParser = new JSONParser();

                        Object obj = jsonParser.parse(binRawText);
                        if (obj instanceof JSONArray) {
                            JSONArray jsonArray = (JSONArray) obj;
                            bin = Bin.asList(binColumn.getBinNameHeader(), jsonArray);
                        } else {
                            JSONObject jsonObj = (JSONObject) obj;
                            bin = Bin.asMap(binColumn.getBinNameHeader(), jsonObj);
                        }
                    } catch (ParseException e) {
                        log.error("Failed to parse JSON", e);
                    }
                    break;
                case TIMESTAMP:
                    if (binColumn.getDstType().equals(DstColumnType.INTEGER)) {
                        DateFormat format = new SimpleDateFormat(binColumn.getEncoding());
                        try {
                            Date formatDate = format.parse(binRawText);
                            long miliSecondForDate = formatDate.getTime() - timeZoneOffset;

                            if (binColumn.getEncoding().contains(".SSS")
                                    && binColumn.binValueHeader.toLowerCase().equals(Constants.SYSTEM_TIME)) {
                                //We need time in miliseconds so no need to change it to seconds
                            } else {
                                miliSecondForDate = miliSecondForDate / 1000;
                            }
                            bin = new Bin(binColumn.getBinNameHeader(), miliSecondForDate);
                            log.trace("Date format:" + binRawText + " in seconds:" + miliSecondForDate);
                        } catch (java.text.ParseException e) {
                            e.printStackTrace();
                        }
                    } else if (binColumn.getDstType().equals(DstColumnType.STRING)) {
                        bin = new Bin(binColumn.getBinNameHeader(), binRawText);
                    }
                    break;

                default:

                }
            } else {
                bin = new Bin(binColumn.getBinNameHeader(), binColumn.getBinValueHeader());
            }

            if (bin != null) {
                bins.add(bin);
            }
        }
        lineProcessed = true;
        log.trace("Formed key and bins for line " + lineNumber + " Key: " + this.key.userKey + " Bins:"
                + this.bins.toString());
    } catch (AerospikeException ae) {
        log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber
                + " Aerospike Bin processing Error:" + ae.getResultCode());
        if (log.isDebugEnabled()) {
            ae.printStackTrace();
        }
        counters.write.processingErrors.getAndIncrement();
        counters.write.recordProcessed.addAndGet(this.lineSize);
        errorTotal = (counters.write.readErrors.get() + counters.write.writeErrors.get()
                + counters.write.processingErrors.get());
        if (this.abortErrorCount != 0 && this.abortErrorCount < errorTotal) {
            System.exit(-1);
        }
    } catch (ParseException pe) {
        log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber + " Parsing Error:" + pe);
        if (log.isDebugEnabled()) {
            pe.printStackTrace();
        }
        counters.write.processingErrors.getAndIncrement();
        counters.write.recordProcessed.addAndGet(this.lineSize);
        errorTotal = (counters.write.readErrors.get() + counters.write.writeErrors.get()
                + counters.write.processingErrors.get());
        if (this.abortErrorCount != 0 && this.abortErrorCount < errorTotal) {
            System.exit(-1);
        }
    } catch (Exception e) {
        log.error("File:" + Utils.getFileName(this.fileName) + " Line:" + lineNumber + " Unknown Error:" + e);
        if (log.isDebugEnabled()) {
            e.printStackTrace();
        }
        counters.write.processingErrors.getAndIncrement();
        counters.write.recordProcessed.addAndGet(this.lineSize);
        errorTotal = (counters.write.readErrors.get() + counters.write.writeErrors.get()
                + counters.write.processingErrors.get());
        if (this.abortErrorCount != 0 && this.abortErrorCount < errorTotal) {
            System.exit(-1);
        }
    }

    return lineProcessed;
}

From source file:org.geowebcache.storage.JobObject.java

public void setParameters(Map<String, String> map) {
    if (map == null) {
        encodedParameters = null;/*from   w  w  w.jav a 2 s .  c  o  m*/
    } else {
        try {
            List<String> list = new ArrayList<String>();
            for (Entry<String, String> entry : map.entrySet()) {
                String key = URLEncoder.encode(entry.getKey(), "UTF-8");
                String value = URLEncoder.encode(entry.getValue(), "UTF-8");

                list.add(key + "=" + value);
            }
            encodedParameters = StringUtils.join(list, "&");

        } catch (UnsupportedEncodingException e) {
            log.warn("Couldn't encode parameters, they won't be used. Parameters were:\n" + map.toString(), e);
        }
    }
}