Permalink
Browse files

Fixes for StatusLine resourse-leak warning.

Also fixes the original HttpReaderWriter, from which StatusLine was based.
Issue #520
  • Loading branch information...
1 parent 423937d commit 452e0072912f30ada82deabde49dec55d672f521 @jcookems jcookems committed Jan 9, 2013
@@ -16,6 +16,7 @@
package com.microsoft.windowsazure.services.media.implementation;
import java.io.IOException;
+import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
@@ -28,8 +29,16 @@
private String reason;
public static StatusLine create(DataSource dataSource) {
+ InputStream inputStream;
+ try {
+ inputStream = dataSource.getInputStream();
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ LineInputStream stream = new LineInputStream(inputStream);
try {
- LineInputStream stream = new LineInputStream(dataSource.getInputStream());
String line = stream.readLine();
StringReader lineReader = new StringReader(line);
@@ -43,6 +52,14 @@ public static StatusLine create(DataSource dataSource) {
catch (IOException e) {
throw new RuntimeException(e);
}
+ finally {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
private static void expect(Reader reader, String string) {
@@ -38,8 +38,17 @@ public HttpReaderWriter() {
}
public StatusLine parseStatusLine(DataSource ds) {
+ InputStream inputStream;
+ try {
+ inputStream = ds.getInputStream();
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ LineInputStream stream = new LineInputStream(inputStream);
+
try {
- LineInputStream stream = new LineInputStream(ds.getInputStream());
String line = stream.readLine();
StringReader lineReader = new StringReader(line);
@@ -53,6 +62,14 @@ public StatusLine parseStatusLine(DataSource ds) {
catch (IOException e) {
throw new RuntimeException(e);
}
+ finally {
+ try {
+ stream.close();
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
public InternetHeaders parseHeaders(DataSource ds) {

0 comments on commit 452e007

Please sign in to comment.