Permalink
Browse files

Merge pull request #24 from jcookems/fix520

Fixes for StatusLine resourse-leak warning.
  • Loading branch information...
2 parents e572a07 + c31e52e commit c6ad717e276dd6778b126ca63e5da0f1a1fc93fe @jcookems jcookems committed Jan 9, 2013
@@ -30,15 +30,20 @@
public static StatusLine create(DataSource dataSource) {
try {
LineInputStream stream = new LineInputStream(dataSource.getInputStream());
- String line = stream.readLine();
- StringReader lineReader = new StringReader(line);
+ try {
+ String line = stream.readLine();
+ StringReader lineReader = new StringReader(line);
- expect(lineReader, "HTTP/1.1");
- expect(lineReader, " ");
- String statusString = extractInput(lineReader, ' ');
- String reason = extractInput(lineReader, -1);
+ expect(lineReader, "HTTP/1.1");
+ expect(lineReader, " ");
+ String statusString = extractInput(lineReader, ' ');
+ String reason = extractInput(lineReader, -1);
- return new StatusLine().setStatus(Integer.parseInt(statusString)).setReason(reason);
+ return new StatusLine().setStatus(Integer.parseInt(statusString)).setReason(reason);
+ }
+ finally {
+ stream.close();
+ }
}
catch (IOException e) {
throw new RuntimeException(e);
@@ -40,15 +40,20 @@ public HttpReaderWriter() {
public StatusLine parseStatusLine(DataSource ds) {
try {
LineInputStream stream = new LineInputStream(ds.getInputStream());
- String line = stream.readLine();
- StringReader lineReader = new StringReader(line);
+ try {
+ String line = stream.readLine();
+ StringReader lineReader = new StringReader(line);
- expect(lineReader, "HTTP/1.1");
- expect(lineReader, " ");
- String statusString = extractInput(lineReader, ' ');
- String reason = extractInput(lineReader, -1);
+ expect(lineReader, "HTTP/1.1");
+ expect(lineReader, " ");
+ String statusString = extractInput(lineReader, ' ');
+ String reason = extractInput(lineReader, -1);
- return new StatusLine().setStatus(Integer.parseInt(statusString)).setReason(reason);
+ return new StatusLine().setStatus(Integer.parseInt(statusString)).setReason(reason);
+ }
+ finally {
+ stream.close();
+ }
}
catch (IOException e) {
throw new RuntimeException(e);

0 comments on commit c6ad717

Please sign in to comment.