@Override protected CollageRegionData performLoad() throws Exception { final File filesDir = CommonUtils.getCacheFileDir(); if (null == filesDir) { throw new DiskWriteException(); } final File outputFile = new File(filesDir, String.format(IMAGE_NAME, mCollageRegion.getId())); if (outputFile.exists() && !outputFile.delete()) { throw new DiskWriteException(); } final HttpURLConnection connection = (HttpURLConnection) new URL(mPost.getStandardResolutionImage().getUrl()).openConnection(); connection.setUseCaches(true); final int responseCode = connection.getResponseCode(); if (responseCode >= 300) { connection.disconnect(); throw new InternalServerException(); } CommonUtils.writeNetworkStreamToAnOtherStream( connection.getInputStream(), new FileOutputStream(outputFile)); connection.disconnect(); if (outputFile.exists()) { return new CollageRegionData(outputFile); } else { throw new DiskWriteException(); } }