Guest User

Untitled

a guest
Aug 17th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. public void read() throws IOException {
  2. BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream(), "UTF8"));
  3.  
  4. String requestURL = null;
  5.  
  6. Vector property = new Vector();
  7. String line;
  8. while ((line = in.readLine()) != null) {
  9. if (line.startsWith("GET")) {
  10. requestURL = line.substring(4, line.length() - 9); continue;
  11. }
  12. int separator = line.indexOf(":");
  13. if (separator != -1) {
  14. property.add(new Property(line.substring(0, separator), line.substring(separator + 2)));
  15. if (((Property)property.get(property.size() - 1)).key.equals("Connection"))
  16. {
  17. break;
  18. }
  19. }
  20. }
  21. HttpURLConnection connection = (HttpURLConnection)new URL(requestURL).openConnection();
  22. for (Property p : property)
  23. connection.addRequestProperty(p.key, p.value);
  24. connection.connect();
  25.  
  26. this.headerFields = connection.getHeaderFields();
  27. String contentEncoding = "";
  28. if (this.headerFields.get("Content-Encoding") != null)
  29. contentEncoding = (String)((List)this.headerFields.get("Content-Encoding")).get(0);
  30. BufferedReader reader;
  31. BufferedReader reader;
  32. if (contentEncoding.equals("gzip")) {
  33. reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF8"));
  34. }
  35. else
  36. {
  37. BufferedReader reader;
  38. if (contentEncoding.equals("deflate"))
  39. reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "UTF8"));
  40. else
  41. reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
  42. }
  43. StringBuilder documentBuilder = new StringBuilder();
  44. while ((line = reader.readLine()) != null) {
  45. documentBuilder.append(line).append(System.getProperty("line.separator"));
  46. }
  47.  
  48. this.document = documentBuilder.toString();
  49. connection.disconnect();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment