SHOW:
|
|
- or go back to the newest paste.
| 1 | public void read() throws IOException {
| |
| 2 | - | BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream(), "UTF8")); |
| 2 | + | BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream(), "UTF8")); |
| 3 | String requestURL = null; | |
| 4 | - | String requestURL = null; |
| 4 | + | Vector property = new Vector(); |
| 5 | String line; | |
| 6 | - | Vector property = new Vector(); |
| 6 | + | |
| 7 | - | String line; |
| 7 | + | |
| 8 | if (line.startsWith("GET")) {
| |
| 9 | - | if (line.startsWith("GET")) {
|
| 9 | + | requestURL = line.substring(4, line.length() - 9); continue; |
| 10 | - | 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))); |
| 14 | + | property.add(new Property(line.substring(0, separator), line.substring(separator + 2))); |
| 15 | - | if (((Property)property.get(property.size() - 1)).key.equals("Connection"))
|
| 15 | + | if (((Property)property.get(property.size() - 1)).key.equals("Connection"))
|
| 16 | - | {
|
| 16 | + | {
|
| 17 | - | break; |
| 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 | - | contentEncoding = (String)((List)this.headerFields.get("Content-Encoding")).get(0);
|
| 29 | + | |
| 30 | contentEncoding = (String)((List)this.headerFields.get("Content-Encoding")).get(0);
| |
| 31 | BufferedReader reader; | |
| 32 | BufferedReader reader; | |
| 33 | - | reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF8")); |
| 33 | + | |
| 34 | reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF8")); | |
| 35 | } | |
| 36 | - | {
|
| 36 | + | else{
|
| 37 | BufferedReader reader; | |
| 38 | - | if (contentEncoding.equals("deflate"))
|
| 38 | + | if (contentEncoding.equals("deflate"))
|
| 39 | - | reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "UTF8")); |
| 39 | + | reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "UTF8")); |
| 40 | else | |
| 41 | - | reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8")); |
| 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"));
|
| 45 | + | documentBuilder.append(line).append(System.getProperty("line.separator"));
|
| 46 | } | |
| 47 | ||
| 48 | this.document = documentBuilder.toString(); | |
| 49 | connection.disconnect(); | |
| 50 | } |