PageRenderTime 63ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mcp/src/minecraft/net/minecraft/src/PostHttp.java

https://bitbucket.org/vkorolik/twoleanfour-client
Java | 107 lines | 92 code | 15 blank | 0 comment | 8 complexity | 5418bad840fa1eb42a755c02f34eaaf2 MD5 | raw file
  1. package net.minecraft.src;
  2. import java.io.*;
  3. import java.net.*;
  4. import java.util.*;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. public class PostHttp
  8. {
  9. private PostHttp()
  10. {
  11. }
  12. public static String func_52016_a(Map par0Map)
  13. {
  14. StringBuilder stringbuilder = new StringBuilder();
  15. Iterator iterator = par0Map.entrySet().iterator();
  16. do
  17. {
  18. if (!iterator.hasNext())
  19. {
  20. break;
  21. }
  22. java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next();
  23. if (stringbuilder.length() > 0)
  24. {
  25. stringbuilder.append('&');
  26. }
  27. try
  28. {
  29. stringbuilder.append(URLEncoder.encode((String)entry.getKey(), "UTF-8"));
  30. }
  31. catch (UnsupportedEncodingException unsupportedencodingexception)
  32. {
  33. unsupportedencodingexception.printStackTrace();
  34. }
  35. if (entry.getValue() != null)
  36. {
  37. stringbuilder.append('=');
  38. try
  39. {
  40. stringbuilder.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));
  41. }
  42. catch (UnsupportedEncodingException unsupportedencodingexception1)
  43. {
  44. unsupportedencodingexception1.printStackTrace();
  45. }
  46. }
  47. }
  48. while (true);
  49. return stringbuilder.toString();
  50. }
  51. public static String func_52018_a(URL par0URL, Map par1Map, boolean par2)
  52. {
  53. return func_52017_a(par0URL, func_52016_a(par1Map), par2);
  54. }
  55. public static String func_52017_a(URL par0URL, String par1Str, boolean par2)
  56. {
  57. try
  58. {
  59. String s = par1Str;
  60. HttpURLConnection httpurlconnection = (HttpURLConnection)par0URL.openConnection();
  61. httpurlconnection.setRequestMethod("POST");
  62. httpurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  63. httpurlconnection.setRequestProperty("Content-Length", (new StringBuilder()).append("").append(s.getBytes().length).toString());
  64. httpurlconnection.setRequestProperty("Content-Language", "en-US");
  65. httpurlconnection.setUseCaches(false);
  66. httpurlconnection.setDoInput(true);
  67. httpurlconnection.setDoOutput(true);
  68. DataOutputStream dataoutputstream = new DataOutputStream(httpurlconnection.getOutputStream());
  69. dataoutputstream.writeBytes(s);
  70. dataoutputstream.flush();
  71. dataoutputstream.close();
  72. BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream()));
  73. StringBuffer stringbuffer = new StringBuffer();
  74. String s1;
  75. while ((s1 = bufferedreader.readLine()) != null)
  76. {
  77. stringbuffer.append(s1);
  78. stringbuffer.append('\r');
  79. }
  80. bufferedreader.close();
  81. return stringbuffer.toString();
  82. }
  83. catch (Exception exception)
  84. {
  85. if (!par2)
  86. {
  87. Logger.getLogger("Minecraft").log(Level.SEVERE, (new StringBuilder()).append("Could not post to ").append(par0URL).toString(), exception);
  88. }
  89. }
  90. return "";
  91. }
  92. }