Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. {
  2. "filename": "vcops-6.0.0-MPforAWS-1.1-1695068.pak",
  3. "links": [
  4. {
  5. "rel": "pak_information",
  6. "href": "https://<IP>:443/casa/upgrade/cluster/pak/MPforAWS-600/information"
  7. },
  8. {
  9. "rel": "pak_file_information",
  10. "href": "https://<IP>:443/casa/upgrade/slice/pak/MPforAWS-600/file_information"
  11. },
  12. {
  13. "rel": "pak_cluster_status",
  14. "href": "https://<IP>:443/casa/upgrade/cluster/pak/MPforAWS-600/status"
  15. }
  16. ],
  17. "pak_id": "MPforAWS-600"
  18. }
  19.  
  20. private String getPakId(InputStream uploadResponse) {
  21. String pakId = null;
  22. try {
  23. String responseString = readInputStream(uploadResponse);
  24. JSONObject jObj = new JSONObject(responseString);
  25. pakId = jObj.getString("pak_id").trim();
  26. Reporter.log("Pak id is=" + pakId, true);
  27. } catch (Exception e) {
  28. Reporter.log("Error in getting pak_id " + e.getMessage(), true);
  29. }
  30. return pakId;
  31. }
  32.  
  33. private String readInputStream(InputStream inputStream) throws IOException {
  34. BufferedReader reader = new BufferedReader(new InputStreamReader(
  35. inputStream, "UTF-8"));
  36. String tmp;
  37. StringBuilder sb = new StringBuilder();
  38. while ((tmp = reader.readLine()) != null) {
  39. sb.append(tmp).append("n");
  40. }
  41. if (sb.length() > 0 && sb.charAt(sb.length() - 1) == 'n') {
  42. sb.setLength(sb.length() - 1);
  43. }
  44. reader.close();
  45. return sb.toString();
  46. }
  47.  
  48. String input = inputStreamObj.toString();
  49. JSONObject jsonObject = new JSONObject(input);
  50. String pakId = jsonObject.getString("pak_id");
  51.  
  52. InputStream is = ...
  53. String line;
  54. StringBuilder text = new StringBuilder();
  55. BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
  56. while((line = reader.readLine()) != null) {
  57. text.append(line).append(" ");
  58. }
  59. String pakId = text.toString().replaceAll(".*"pak_id": "([^"]+)".*", "$1");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement