+ future = mExecutor.submit(() -> {
+ URL url = new URL(uri);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setConnectTimeout(10000);
+ conn.setReadTimeout(10000);
+ try
+ {
+ if (contentType != null)
+ {
+ conn.setRequestProperty("Content-Type", contentType);
+ }
+ if (data != null)
+ {
+ conn.setDoOutput(true);
+ conn.setFixedLengthStreamingMode(data.length);
+ OutputStream out = new BufferedOutputStream(conn.getOutputStream());
+ out.write(data);
+ out.close();
+ }
+ return streamToArray(conn.getInputStream());
+ }
+ catch (SocketTimeoutException e)
+ {
+ return null;
+ }
+ finally
+ {
+ conn.disconnect();
+ }
+ });
+
+ mFutures.add(future);
+ }
+
+ try
+ {
+ /* this enforces a timeout as the ones set on HttpURLConnection might not work reliably */
+ return future.get(10000, TimeUnit.MILLISECONDS);
+ }
+ catch (InterruptedException|ExecutionException|TimeoutException|CancellationException e)
+ {
+ return null;
+ }
+ finally
+ {
+ synchronized (mLock)