| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 package org.chromium.chrome.browser.physicalweb; | 4 package org.chromium.chrome.browser.physicalweb; |
| 5 | 5 |
| 6 import org.chromium.base.ThreadUtils; | 6 import org.chromium.base.ThreadUtils; |
| 7 | 7 |
| 8 import java.io.BufferedInputStream; | 8 import java.io.BufferedInputStream; |
| 9 import java.io.IOException; | 9 import java.io.IOException; |
| 10 import java.io.InputStream; | 10 import java.io.InputStream; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Setup some values | 63 // Setup some values |
| 64 HttpURLConnection urlConnection = null; | 64 HttpURLConnection urlConnection = null; |
| 65 T result = null; | 65 T result = null; |
| 66 InputStream inputStream = null; | 66 InputStream inputStream = null; |
| 67 int responseCode = 0; | 67 int responseCode = 0; |
| 68 IOException ioException = null; | 68 IOException ioException = null; |
| 69 | 69 |
| 70 // Make the request | 70 // Make the request |
| 71 try { | 71 try { |
| 72 urlConnection = (HttpURLConnection) mUrl.openConnection(); | 72 urlConnection = (HttpURLConnection) mUrl.openConnection(); |
| 73 urlConnection.setDoOutput(true); | |
| 74 writeToUrlConnection(urlConnection); | 73 writeToUrlConnection(urlConnection); |
| 75 responseCode = urlConnection.getResponseCode(); | 74 responseCode = urlConnection.getResponseCode(); |
| 76 inputStream = new BufferedInputStream(urlConnection.getInputStream()
); | 75 inputStream = new BufferedInputStream(urlConnection.getInputStream()
); |
| 77 result = readInputStream(inputStream); | 76 result = readInputStream(inputStream); |
| 78 } catch (IOException e) { | 77 } catch (IOException e) { |
| 79 ioException = e; | 78 ioException = e; |
| 80 } finally { | 79 } finally { |
| 81 if (urlConnection != null) { | 80 if (urlConnection != null) { |
| 82 urlConnection.disconnect(); | 81 urlConnection.disconnect(); |
| 83 } | 82 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 108 throws IOException; | 107 throws IOException; |
| 109 | 108 |
| 110 /** | 109 /** |
| 111 * Helper method to read an HTTP response. | 110 * Helper method to read an HTTP response. |
| 112 * @param is The InputStream. | 111 * @param is The InputStream. |
| 113 * @return An object representing the HTTP response. | 112 * @return An object representing the HTTP response. |
| 114 * @throws IOException on error | 113 * @throws IOException on error |
| 115 */ | 114 */ |
| 116 protected abstract T readInputStream(InputStream is) throws IOException; | 115 protected abstract T readInputStream(InputStream is) throws IOException; |
| 117 } | 116 } |
| OLD | NEW |