Permalink
Browse files

Restructure try-catches to have only one catch.

  • Loading branch information...
1 parent 452e007 commit 2330429aacd353ef1a02c1cab6f230a9330d9b3e @jcookems jcookems committed Jan 9, 2013
@@ -32,34 +32,27 @@ 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 {
- String line = stream.readLine();
- StringReader lineReader = new StringReader(line);
+ LineInputStream stream = new LineInputStream(inputStream);
+ 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);
}
- finally {
- try {
- stream.close();
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+
}
private static void expect(Reader reader, String string) {
@@ -41,35 +41,27 @@ public StatusLine parseStatusLine(DataSource ds) {
InputStream inputStream;
try {
inputStream = ds.getInputStream();
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- LineInputStream stream = new LineInputStream(inputStream);
+ LineInputStream stream = new LineInputStream(inputStream);
- try {
- 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);
}
- finally {
- try {
- stream.close();
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
}
public InternetHeaders parseHeaders(DataSource ds) {

0 comments on commit 2330429

Please sign in to comment.