Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

@Deprecated
public static String decode(String s) 

Source Link

Document

Decodes a x-www-form-urlencoded string.

Usage

From source file:Main.java

public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length == 2) {
                params.putString(URLDecoder.decode(v[0]), URLDecoder.decode(v[1]));
            }/*from   ww  w  . j  av  a 2  s .  co  m*/
        }
    }
    return params;
}

From source file:Main.java

public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        params.putString("url", s);
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length > 1)
                params.putString(v[0], URLDecoder.decode(v[1]));
        }/*  ww  w  .  jav  a 2 s.  c o m*/
    }
    return params;
}

From source file:Main.java

public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String[] array = s.split("&");
        String[] arr$ = array;/*  w w w  . j  ava 2s .  c  o m*/
        int len$ = array.length;

        for (int i$ = 0; i$ < len$; ++i$) {
            String parameter = arr$[i$];
            String[] v = parameter.split("=");
            if (v.length >= 2 && v[1] != null) {
                params.putString(URLDecoder.decode(v[0]), URLDecoder.decode(v[1]));
            } else {
                params.putString(URLDecoder.decode(v[0]), "");
            }
        }
    }

    return params;
}

From source file:Main.java

public static Bundle decodeUrl(String query) {
    Bundle ret = new Bundle();
    if (query != null) {
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            String[] keyAndValues = pair.split("=");
            if (keyAndValues != null && keyAndValues.length == 2) {
                String key = keyAndValues[0];
                String value = keyAndValues[1];
                if (!isEmpty(key) && !isEmpty(value)) {
                    ret.putString(URLDecoder.decode(key), URLDecoder.decode(value));
                }/*ww w.j ava 2 s  .  co m*/
            }
        }
    }
    return ret;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            if (v.length > 1) {
                params.putString(v[0], URLDecoder.decode(v[1]));
            }/* www. java2s .c  o m*/
        }
    }
    return params;
}

From source file:Main.java

public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
        String array[] = s.split("&");
        for (String parameter : array) {
            String v[] = parameter.split("=");
            params.putString(URLDecoder.decode(v[0]), URLDecoder.decode(v[1]));
        }/*from   w  ww  .  j  a v a 2  s  . c  o m*/
    }
    return params;
}

From source file:com.ibuildapp.romanblack.CataloguePlugin.imageloader.Utils.java

public static String downloadFile(Context context, String url, String md5) {
    final int BYTE_ARRAY_SIZE = 8024;
    final int CONNECTION_TIMEOUT = 30000;
    final int READ_TIMEOUT = 30000;

    try {/* www .ja va 2  s.c om*/
        for (int i = 0; i < 3; i++) {
            URL fileUrl = new URL(URLDecoder.decode(url));
            HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
            connection.setConnectTimeout(CONNECTION_TIMEOUT);
            connection.setReadTimeout(READ_TIMEOUT);
            connection.connect();

            int status = connection.getResponseCode();

            if (status >= HttpStatus.SC_BAD_REQUEST) {
                connection.disconnect();

                continue;
            }

            BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
            File file = new File(StaticData.getCachePath(context) + md5);

            if (!file.exists()) {
                new File(StaticData.getCachePath(context)).mkdirs();
                file.createNewFile();
            }

            FileOutputStream fileOutputStream = new FileOutputStream(file, false);
            int byteCount;
            byte[] buffer = new byte[BYTE_ARRAY_SIZE];

            while ((byteCount = bufferedInputStream.read(buffer, 0, BYTE_ARRAY_SIZE)) != -1)
                fileOutputStream.write(buffer, 0, byteCount);

            bufferedInputStream.close();
            fileOutputStream.flush();
            fileOutputStream.close();

            return file.getAbsolutePath();
        }
    } catch (Exception e) {
        e.printStackTrace();

        return null;
    }

    return null;
}

From source file:xj.property.ums.common.NetworkUitlity.java

public static MyMessage post(String url, String data) {
    // TODO Auto-generated method stub
    CommonUtil.printLog("ums", url);
    String returnContent = "";
    MyMessage message = new MyMessage();
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {/*from   w  w  w.ja  va 2s  . c o m*/
        StringEntity se = new StringEntity(data, HTTP.UTF_8);
        CommonUtil.printLog("postdata", "content=" + data);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();
        CommonUtil.printLog("ums", status + "");
        String returnXML = EntityUtils.toString(response.getEntity());
        returnContent = URLDecoder.decode(returnXML);
        switch (status) {
        case 200:
            message.setFlag(true);
            message.setMsg(returnContent);
            break;

        default:
            Log.e("error", status + returnContent);
            message.setFlag(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        JSONObject jsonObject = new JSONObject();

        try {
            jsonObject.put("err", e.toString());
            returnContent = jsonObject.toString();
            message.setFlag(false);
            message.setMsg(returnContent);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }

    }
    CommonUtil.printLog("UMSAGENT", message.getMsg());
    return message;
}

From source file:com.wbtech.ums.common.NetworkUitlity.java

public static MyMessage post(String url, String data) {
    // TODO Auto-generated method stub
    CommonUtil.printLog("ums", url);
    String returnContent = "";
    MyMessage message = new MyMessage();
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {//  w  w w  .ja  v  a  2s  .  co m
        StringEntity se = new StringEntity("content=" + data, HTTP.UTF_8);
        CommonUtil.printLog("postdata", "content=" + data);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();
        CommonUtil.printLog("ums", status + "");
        String returnXML = EntityUtils.toString(response.getEntity());
        returnContent = URLDecoder.decode(returnXML);
        switch (status) {
        case 200:
            message.setFlag(true);
            message.setMsg(returnContent);
            break;

        default:
            Log.e("error", status + returnContent);
            message.setFlag(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        JSONObject jsonObject = new JSONObject();

        try {
            jsonObject.put("err", e.toString());
            returnContent = jsonObject.toString();
            message.setFlag(false);
            message.setMsg(returnContent);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }

    }
    CommonUtil.printLog("UMSAGENT", message.getMsg());
    return message;
}

From source file:com.example.android.rowanparkingpass.Networking.Sync.SyncVehicles.java

public synchronized void sync(Context c) {
    if (SaveData.getSync()) {
        SendInfoVehicle sendInfoVehicle = new SendInfoVehicle();
        JSONObject json = sendInfoVehicle.syncVehicles(c);
        JSONArray jsonArray;//  w  ww. j a v a2s  .c  o m
        States[] arrayStates = States.values();
        try {
            String s = json.getString("JSONS");
            s = URLDecoder.decode(s);
            Log.d("Sssssss", s);
            jsonArray = new JSONArray(s);
            Log.d("JSON ARRAY", jsonArray.toString());
            DatabaseHandlerVehicles db = new DatabaseHandlerVehicles(c);
            for (int i = 0; i < jsonArray.length(); i++) {
                //[{"model":"zaz","color":"1","state":"23","user_id":"10","year":"1945","license":"bingling","vehicle_id":"3","make":"me a sammich"}
                JSONObject jsonObj = jsonArray.getJSONObject(i);
                //Log.d("JSONOBJ", jsonObj.toString());
                String model = jsonObj.getString("model");
                String color = jsonObj.getString("color");
                String state = jsonObj.getString("state");
                String year = jsonObj.getString("year");
                String license = jsonObj.getString("license");
                String vehicle_id = jsonObj.getString("vehicle_id");
                String make = jsonObj.getString("make");
                try {
                    db.addVehicle(Integer.parseInt(vehicle_id), Integer.parseInt(year), make, model,
                            arrayStates[Integer.parseInt(state)]
                                    .valueOf(arrayStates[Integer.parseInt(state)].name()).toString(),
                            color, license);
                } catch (SQLiteConstraintException sqlC) {
                    Log.d("SQLite Exception", sqlC.getMessage());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}