Advertisement
Guest User

Untitled

a guest
Aug 17th, 2012
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void read() throws IOException {
  2.     BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream(), "UTF8"));
  3.     String requestURL = null;
  4.     Vector property = new Vector();
  5.     String line;
  6.  
  7. while ((line = in.readLine()) != null) {
  8.     if (line.startsWith("GET")) {
  9.     requestURL = line.substring(4, line.length() - 9); continue;
  10.     }
  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.  
  22. HttpURLConnection connection = (HttpURLConnection)new URL(requestURL).openConnection();
  23. for (Property p : property)
  24. connection.addRequestProperty(p.key, p.value);
  25. connection.connect();
  26.  
  27. this.headerFields = connection.getHeaderFields();
  28. String contentEncoding = "";
  29. if (this.headerFields.get("Content-Encoding") != null)
  30.     contentEncoding = (String)((List)this.headerFields.get("Content-Encoding")).get(0);
  31. BufferedReader reader;
  32. BufferedReader reader;
  33. if (contentEncoding.equals("gzip")) {
  34.     reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()),         "UTF8"));
  35.     }
  36. else{
  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
Advertisement