anupam409 / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

close the streams #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the product are you using? On what operating system?
from subversion

Please provide any additional information below.
I suggest you close streams like below in order to avoid memory leaks.

    HttpURLConnection connection = (HttpURLConnection)new
URL(url.toString()).openConnection();
    InputStream in = connection.getInputStream();
    try {
      connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;
MSIE 7.0; Windows NT 5.1)");

      String page = toString(in);
      int resultBox = page.indexOf("<div id=result_box dir=");

      if (resultBox < 0) {
        throw new Error("No translation result returned.");
      }

      String start = page.substring(resultBox);
      return start.substring(27, start.indexOf("</div>"));
    } finally {
      // http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html
      in.close();

      InputStream error = connection.getErrorStream();
      if (error != null) {
        error.close();
      }
    }

Original issue reported on code.google.com by evernat@free.fr on 1 Dec 2007 at 1:42

GoogleCodeExporter commented 9 years ago
Thanks, this should be committed now and available in the next build which I'll
probably do today/tomorrow.

Original comment by rich.mid...@gmail.com on 1 Dec 2007 at 2:20

GoogleCodeExporter commented 9 years ago
New build is available now.

Original comment by rich.mid...@gmail.com on 1 Dec 2007 at 2:33

GoogleCodeExporter commented 9 years ago
If you'd like to be listed as a contributer please let me know the name and/or 
email
address you'd like to be listed under.

Thanks

Original comment by rich.mid...@gmail.com on 11 Dec 2007 at 9:59

GoogleCodeExporter commented 9 years ago
Yes I would be glad to be listed as a contributer. My name is Emeric Vernat. (I 
live
in France.)
Thank you

Original comment by evernat@free.fr on 13 Dec 2007 at 10:02