/*
Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.google.security.zynamics.zylib.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

public class WebsiteReader {
  public static String read(final String url) throws IOException {
    // Create a URL for the desired page
    final URL url_ = new URL(url);

    final BufferedReader in = new BufferedReader(new InputStreamReader(url_.openStream()));

    final StringBuilder sb = new StringBuilder();

    String str;

    while ((str = in.readLine()) != null) {
      sb.append(str);
    }

    in.close();

    return sb.toString();
  }

  public static String sendPost(final String urlString, final String encodedData)
      throws IOException {
    final URL url = new URL(urlString);

    final URLConnection conn = url.openConnection();

    conn.setDoOutput(true);

    final OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    try {
      wr.write(encodedData);
      wr.flush();
    } finally {
      wr.close();
    }

    // Get the response
    final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

    final StringBuilder ret = new StringBuilder();

    String line;

    try {
      while ((line = rd.readLine()) != null) {
        ret.append(line);
      }
    } finally {
      rd.close();
    }

    return ret.toString();
  }
}

@@ -1494,22 +1494,21 @@
 );%0A%0A    
-final 
+try (
 OutputSt
@@ -1573,17 +1573,9 @@
 m())
-;%0A    try
+)
  %7B%0A 
@@ -1629,164 +1629,33 @@
    %7D
- finally %7B%0A      wr.close();%0A    %7D%0A%0A    // Get the response%0A    final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));%0A
+%0A%0A    // Get the response
 %0A   
@@ -1694,33 +1694,32 @@
 tringBuilder();%0A
-%0A
     String line;
@@ -1727,16 +1727,103 @@
 %0A    try
+ (BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())))
  %7B%0A     
@@ -1907,42 +1907,8 @@
    %7D
- finally %7B%0A      rd.close();%0A    %7D
 %0A%0A  

Update WebsiteReader.java