Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void read() throws IOException {
- BufferedReader in = new BufferedReader(new InputStreamReader(this.socket.getInputStream(), "UTF8"));
- String requestURL = null;
- Vector property = new Vector();
- String line;
- while ((line = in.readLine()) != null) {
- if (line.startsWith("GET")) {
- requestURL = line.substring(4, line.length() - 9); continue;
- }
- int separator = line.indexOf(":");
- if (separator != -1) {
- property.add(new Property(line.substring(0, separator), line.substring(separator + 2)));
- if (((Property)property.get(property.size() - 1)).key.equals("Connection"))
- {
- break;
- }
- }
- }
- HttpURLConnection connection = (HttpURLConnection)new URL(requestURL).openConnection();
- for (Property p : property)
- connection.addRequestProperty(p.key, p.value);
- connection.connect();
- this.headerFields = connection.getHeaderFields();
- String contentEncoding = "";
- if (this.headerFields.get("Content-Encoding") != null)
- contentEncoding = (String)((List)this.headerFields.get("Content-Encoding")).get(0);
- BufferedReader reader;
- BufferedReader reader;
- if (contentEncoding.equals("gzip")) {
- reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()), "UTF8"));
- }
- else{
- BufferedReader reader;
- if (contentEncoding.equals("deflate"))
- reader = new BufferedReader(new InputStreamReader(new InflaterInputStream(connection.getInputStream()), "UTF8"));
- else
- reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
- }
- StringBuilder documentBuilder = new StringBuilder();
- while ((line = reader.readLine()) != null) {
- documentBuilder.append(line).append(System.getProperty("line.separator"));
- }
- this.document = documentBuilder.toString();
- connection.disconnect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement