protected byte[] request(String url, HttpMethod method, byte[] content, boolean refresh) { NativeDataLoaderCall task = new NativeDataLoaderCall(url, content, refresh, maxInputSize); ExecutorService executorService = Executors.newSingleThreadExecutor(); try { Future<byte[]> result = executorService.submit(task); return timeout > 0 ? result.get(timeout, TimeUnit.MILLISECONDS) : result.get(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new DSSException(e); } catch (ExecutionException | TimeoutException e) { throw new DSSException(e); } finally { executorService.shutdown(); } }
public byte[] call() { OutputStream out = null; InputStream inputStream = null; byte[] result = null; try { URLConnection connection = createConnection(); connection.setUseCaches(useCaches); connection.setDoInput(true); if (content != null) { connection.setDoOutput(true); out = connection.getOutputStream(); Utils.write(content, out); } inputStream = connection.getInputStream(); result = Utils.toByteArray(maxInputSize > 0? new MaxSizeInputStream(inputStream, maxInputSize, url): inputStream); } catch (IOException e) { throw new DSSException(String.format(ERROR_MESSAGE, url, e.getMessage()), e); } finally { Utils.closeQuietly(out); Utils.closeQuietly(inputStream); } return result; }