public static void main(String[] args) throws IOException { new Downloader("GraphHopper Downloader").downloadAndUnzip("http://graphhopper.com/public/maps/0.1/europe_germany_berlin.ghz", "somefolder", new ProgressListener() { @Override public void update(long val) { System.out.println("progress:" + val); } }); }
public InputStream fetch(String url) throws IOException { return fetch((HttpURLConnection) createConnection(url), false); }
/** * Download a file at the provided url and save it as the given downloadFile if the downloadFile does not exist. */ private void downloadFile(File downloadFile, String url) throws IOException { if (!downloadFile.exists()) { int max = 3; for (int trial = 0; trial < max; trial++) { try { downloader.downloadFile(url, downloadFile.getAbsolutePath()); return; } catch (SocketTimeoutException ex) { if (trial >= max - 1) throw new RuntimeException(ex); try { Thread.sleep(sleep); } catch (InterruptedException ignored) { } } } } }
public AbstractSRTMElevationProvider(String baseUrl, String cacheDir, String downloaderName, int defaultWidt) { super(cacheDir); this.baseUrl = baseUrl; downloader = new Downloader(downloaderName).setTimeout(10000); this.DEFAULT_WIDTH = defaultWidt; }
void execute(int workerNo) throws InterruptedException { Query query = queryQueue.take(); try { String url = baseUrl + query.createQueryString(); if (logRequest) logger.info(url); String res = new Downloader("QueryTorture!").setTimeout(timeout).downloadAsString(url, false); if (res.contains("errors")) routingErrorCounter.incrementAndGet(); else successfullQueries.incrementAndGet(); if (query.realCount % statusUpdateCnt == 0) { logger.info("progress: " + (int) (query.realCount * 100 / maxQueries) + "%"); } } catch (MalformedURLException ex) { logger.error("Error while querying", ex); } catch (IOException ex) { // if (httpErrorCounter.get() % maxQueries == 0) // logger.error("http error", ex); httpErrorCounter.incrementAndGet(); } }
public AbstractTiffElevationProvider(String baseUrl, String cacheDir, String downloaderName, int width, int height, int latDegree, int lonDegree) { super(cacheDir); this.baseUrl = baseUrl; this.downloader = new Downloader(downloaderName).setTimeout(10000); this.WIDTH = width; this.HEIGHT = height; this.LAT_DEGREE = latDegree; this.LON_DEGREE = lonDegree; }
public String downloadAsString(String url, boolean readErrorStreamNoException) throws IOException { return Helper.isToString(fetch((HttpURLConnection) createConnection(url), readErrorStreamNoException)); } }
public static void main(String[] args) throws IOException { new Downloader("GraphHopper Downloader").downloadAndUnzip("http://graphhopper.com/public/maps/0.1/europe_germany_berlin.ghz", "somefolder", new ProgressListener() { @Override public void update(long val) { System.out.println("progress:" + val); } }); }
public AbstractSRTMElevationProvider(String baseUrl, String cacheDir, String downloaderName, int defaultWidt) { super(cacheDir); this.baseUrl = baseUrl; downloader = new Downloader(downloaderName).setTimeout(10000); this.DEFAULT_WIDTH = defaultWidt; }
private byte[] getByteArrayFromFile(double lat, double lon) throws InterruptedException, IOException { String zippedURL = baseUrl + getDownloadURL(lat, lon); File file = new File(cacheDir, new File(zippedURL).getName()); InputStream is; // get zip file if not already in cacheDir if (!file.exists()) for (int i = 0; i < 3; i++) { try { downloader.downloadFile(zippedURL, file.getAbsolutePath()); break; } catch (SocketTimeoutException ex) { // just try again after a little nap Thread.sleep(2000); } catch (FileNotFoundException ex) { if (zippedURL.contains(".hgt.zip")) { zippedURL = zippedURL.replace(".hgt.zip", "hgt.zip"); } else { throw ex; } } } return readFile(file); }
public void downloadAndUnzip(String url, String toFolder, final ProgressListener progressListener) throws IOException { HttpURLConnection conn = createConnection(url); final int length = conn.getContentLength(); InputStream iStream = fetch(conn, false); new Unzipper().unzip(iStream, new File(toFolder), new ProgressListener() { @Override public void update(long sumBytes) { progressListener.update((int) (100 * sumBytes / length)); } }); }
public static void main( String[] args ) throws IOException { new Downloader("GraphHopper Downloader").downloadAndUnzip("http://graphhopper.com/public/maps/0.1/europe_germany_berlin.ghz", "somefolder", new ProgressListener() { @Override public void update( long val ) { System.out.println("progress:" + val); } }); }
public AbstractTiffElevationProvider(String baseUrl, String cacheDir, String downloaderName, int width, int height, int latDegree, int lonDegree) { super(cacheDir); this.baseUrl = baseUrl; this.downloader = new Downloader(downloaderName).setTimeout(10000); this.WIDTH = width; this.HEIGHT = height; this.LAT_DEGREE = latDegree; this.LON_DEGREE = lonDegree; }
/** * Download a file at the provided url and save it as the given downloadFile if the downloadFile does not exist. */ private void downloadFile(File downloadFile, String url) throws IOException { if (!downloadFile.exists()) { int max = 3; for (int trial = 0; trial < max; trial++) { try { downloader.downloadFile(url, downloadFile.getAbsolutePath()); return; } catch (SocketTimeoutException ex) { if (trial >= max - 1) throw new RuntimeException(ex); try { Thread.sleep(sleep); } catch (InterruptedException ignored) { } } } } }
public void downloadFile(String url, String toFile) throws IOException { HttpURLConnection conn = createConnection(url); InputStream iStream = fetch(conn, false); int size = 8 * 1024; BufferedOutputStream writer = new BufferedOutputStream(new FileOutputStream(toFile), size); InputStream in = new BufferedInputStream(iStream, size); try { byte[] buffer = new byte[size]; int numRead; while ((numRead = in.read(buffer)) != -1) { writer.write(buffer, 0, numRead); } } finally { Helper.close(iStream); Helper.close(writer); Helper.close(in); } }
public static void main(String[] args) throws IOException { new Downloader("GraphHopper Downloader").downloadAndUnzip("http://graphhopper.com/public/maps/0.1/europe_germany_berlin.ghz", "somefolder", new ProgressListener() { @Override public void update(long val) { System.out.println("progress:" + val); } }); }
private byte[] getByteArrayFromFile(double lat, double lon) throws InterruptedException, IOException { String zippedURL = baseUrl + getDownloadURL(lat, lon); File file = new File(cacheDir, new File(zippedURL).getName()); InputStream is; // get zip file if not already in cacheDir if (!file.exists()) for (int i = 0; i < 3; i++) { try { downloader.downloadFile(zippedURL, file.getAbsolutePath()); break; } catch (SocketTimeoutException ex) { // just try again after a little nap Thread.sleep(2000); } catch (FileNotFoundException ex) { if (zippedURL.contains(".hgt.zip")) { zippedURL = zippedURL.replace(".hgt.zip", "hgt.zip"); } else { throw ex; } } } return readFile(file); }
public InputStream fetch( String url ) throws IOException { return fetch((HttpURLConnection) createConnection(url), false); }
private byte[] getByteArrayFromZipFile(String fileDetails) throws InterruptedException, FileNotFoundException, IOException { String zippedURL = baseUrl + "/" + fileDetails + ".hgt.zip"; File file = new File(cacheDir, new File(zippedURL).getName()); InputStream is; // get zip file if not already in cacheDir if (!file.exists()) for (int i = 0; i < 3; i++) { try { downloader.downloadFile(zippedURL, file.getAbsolutePath()); break; } catch (SocketTimeoutException ex) { // just try again after a little nap Thread.sleep(2000); continue; } } is = new FileInputStream(file); ZipInputStream zis = new ZipInputStream(is); zis.getNextEntry(); BufferedInputStream buff = new BufferedInputStream(zis); ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[0xFFFF]; int len; while ((len = buff.read(buffer)) > 0) { os.write(buffer, 0, len); } os.flush(); Helper.close(buff); return os.toByteArray(); }
public InputStream fetch(String url) throws IOException { return fetch((HttpURLConnection) createConnection(url), false); }