예제 #1
0
 public static void processSingle(String data, Map<String, String> variables) throws Exception {
   if (data != null && !data.equals("")) {
     String[] items = data.split("&");
     for (int x = 0; x < items.length; x++) {
       int splitter = items[x].indexOf('=');
       String variable = items[x].substring(0, splitter);
       String value = items[x].substring(splitter + 1);
       variables.put(variable, URLDecoder.decode(value, "UTF-8"));
     }
   }
 }
예제 #2
0
  public static void processMulti(String data, String boundary, Map<String, String> variables) {
    String[] results = data.split(boundary);

    if (results.length > 1) {
      for (int x = 1; x < results.length - 1; x++) {
        String item = results[x].substring(0, results[x].length() - 2).trim();

        int c = item.indexOf("name=") + 6;
        String variable = "";
        int count = 0;
        while (item.charAt(c) != '"' && item.charAt(c) != '\n' && count < 10) {
          variable += (char) item.charAt(c);
          c++;
          count++;
        }

        c = item.indexOf("\n\n") + 2;
        String value = item.substring(c);
        variables.put(variable, value);
      }
    }
  }