List of usage examples for java.net URLConnection getDoInput
public boolean getDoInput()
From source file:org.openbel.framework.core.protocol.handler.AbstractProtocolHandler.java
/** * Retrieves a resource from the {@code urlc} and save it to * {@code downloadLocation}./*w w w .jav a 2s. c o m*/ * * @param urlc {@link URLConnection}, the url connection * @param downloadLocation {@link String}, the location to save the * resource content to * @throws IOException Thrown if an io error occurred downloading the * resource * @throws ResourceDownloadError Thrown if there was an I/O error * downloading the resource */ protected File downloadResource(URLConnection urlc, String downloadLocation) throws ResourceDownloadError { if (!urlc.getDoInput()) { urlc.setDoInput(true); } File downloadFile = new File(downloadLocation); try { File downloaded = File.createTempFile(ProtocolHandlerConstants.BEL_FRAMEWORK_TMP_FILE_PREFIX, null); IOUtils.copy(urlc.getInputStream(), new FileOutputStream(downloaded)); FileUtils.copyFile(downloaded, downloadFile); // delete temp file holding download if (!downloaded.delete()) { downloaded.deleteOnExit(); } } catch (IOException e) { final String url = urlc.getURL().toString(); final String msg = "I/O error"; throw new ResourceDownloadError(url, msg, e); } return downloadFile; }