/** * Read the contents from the named URL and place into a String. * * @param urlString the URL to read from. * @return String holding the contents. * @throws IOException if fails */ static public String readURLcontentsWithException(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(20000); copyUrlB(urlString, bout, 20000); return bout.toString(CDM.UTF8); }
/** * Read the contents from the given URL and place into a byte array, * with any error messages put in the return String. * * @param urlString read from this URL. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readURLContentsToByteArray(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(200000); copyUrlB(urlString, bout, 200000); return bout.toByteArray(); }
/** * Read the contents from the named URL and place into a String. * * @param urlString the URL to read from. * @return String holding the contents. * @throws IOException if fails */ static public String readURLcontentsWithException(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(20000); copyUrlB(urlString, bout, 20000); return bout.toString(); }
/** * Read the contents from the given URL and place into a byte array, * with any error messages put in the return String. * * @param urlString read from this URL. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readURLContentsToByteArray(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(200000); copyUrlB(urlString, bout, 200000); return bout.toByteArray(); }
/** * Read the contents from the named URL and place into a String. * * @param urlString the URL to read from. * @return String holding the contents. * @throws IOException if fails */ static public String readURLcontentsWithException(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(20000); copyUrlB(urlString, bout, 20000); return bout.toString(CDM.UTF8); }
/** * Read the contents from the given URL and place into a byte array, * with any error messages put in the return String. * * @param urlString read from this URL. * @return byte[] holding the contents, or an error message. * @throws java.io.IOException on io error */ static public byte[] readURLContentsToByteArray(String urlString) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(200000); copyUrlB(urlString, bout, 200000); return bout.toByteArray(); }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @param buffer_size read/write in this size chunks * @return status or error message. * @throws IOException if failure */ static public String readURLtoFileWithExceptions(String urlString, File file, int buffer_size) throws IOException { try (FileOutputStream fout = new FileOutputStream( file)) { OutputStream out = new BufferedOutputStream(fout); copyUrlB(urlString, out, buffer_size); return "ok"; } }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @param buffer_size read/write in this size chunks * @return status or error message. * @throws IOException if failure */ static public String readURLtoFileWithExceptions(String urlString, File file, int buffer_size) throws IOException { try (FileOutputStream fout = new FileOutputStream( file)) { OutputStream out = new BufferedOutputStream(fout); copyUrlB(urlString, out, buffer_size); return "ok"; } }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @return status or error message. */ static public String readURLtoFile(String urlString, File file) { try (FileOutputStream fout = new FileOutputStream( file)) { OutputStream out = new BufferedOutputStream(fout); copyUrlB(urlString, out, 20000); return "ok"; } catch (FileNotFoundException e) { if (showStackTrace) e.printStackTrace(); return "** IOException opening file: <" + file.getPath() + ">\n" + e.getMessage() + "\n"; } catch (IOException e) { if (showStackTrace) e.printStackTrace(); return "** IOException reading URL: <" + urlString + ">\n" + e.getMessage() + "\n"; } }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @return status or error message. */ static public String readURLtoFile(String urlString, File file) { try (FileOutputStream fout = new FileOutputStream( file)) { OutputStream out = new BufferedOutputStream(fout); copyUrlB(urlString, out, 20000); return "ok"; } catch (FileNotFoundException e) { if (showStackTrace) e.printStackTrace(); return "** IOException opening file: <" + file.getPath() + ">\n" + e.getMessage() + "\n"; } catch (IOException e) { if (showStackTrace) e.printStackTrace(); return "** IOException reading URL: <" + urlString + ">\n" + e.getMessage() + "\n"; } }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @param buffer_size read/write in this size chunks * @return status or error message. * @throws IOException if failure */ static public String readURLtoFileWithExceptions(String urlString, File file, int buffer_size) throws IOException { OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { copyUrlB(urlString, out, buffer_size); return "ok"; } finally { try { out.close(); } catch (IOException e) { return "** IOException closing file : <" + file + ">\n" + e.getMessage() + "\n"; } } }
/** * read the contents from the named URL, write to a file. * * @param urlString the URL to read from. * @param file write to this file * @return status or error message. */ static public String readURLtoFile(String urlString, File file) { OutputStream out; try { out = new BufferedOutputStream(new FileOutputStream(file)); } catch (IOException e) { if (showStackTrace) e.printStackTrace(); return "** IOException opening file: <" + file + ">\n" + e.getMessage() + "\n"; } try { copyUrlB(urlString, out, 20000); return "ok"; } catch (IOException e) { if (showStackTrace) e.printStackTrace(); return "** IOException reading URL: <" + urlString + ">\n" + e.getMessage() + "\n"; } finally { try { out.close(); } catch (IOException e) { return "** IOException closing file : <" + file + ">\n" + e.getMessage() + "\n"; } } }
static public void main(String[] args) throws IOException { FileOutputStream f = new FileOutputStream("C:/TEMP/read.txt"); fout = new Formatter(f); //String url = "http://newmotherlode.ucar.edu:8081/thredds/fileServer/nexrad/level2/KDVN/20080921/Level2_KDVN_20080921_1024.ar2v"; String url = "http://newmotherlode.ucar.edu:8081/thredds/fileServer/fmrc/NCEP/GFS/Global_onedeg/files/GFS_Global_onedeg_20080922_0600.grib2"; long start = System.currentTimeMillis(); IO.copyUrlB(url, null, 1000 * 1000); // read data and throw away double took = .001 * (System.currentTimeMillis() - start); //String url = "http://motherlode.ucar.edu:9080/thredds/ncss/metars?variables=all&north=82.5199&west=88.4499&east=90.4000&south=-90.0000&latitude=&longitude=&spatial=stns&stn=LOWW&time_start=2007-12-02T23%3A45%3A04Z&time_end=present&temporal=point&time=2007-12-02T23%3A45%3A04Z&accept=raw"; //String url2 = "http://motherlode.ucar.edu:8080/thredds/dodsC/fmrc/NCEP/NAM/CONUS_80km/files/NAM_CONUS_80km_20071217_0000.grib1.dods?Total_precipitation"; /* long start = System.currentTimeMillis(); File fileResult = new File("R:/testdata2/bufr/vosclim_2008032301"); String result = readURLtoFile(url, fileResult); double took = .001 * (System.currentTimeMillis() - start); System.out.println(result); System.out.println(" result size = " + result.length()); System.out.println(" file size = " + fileResult.length()); */ fout.flush(); f.close(); System.out.println(" that took = " + took + " sec"); }
@Test public void hitLocalTdsWms() throws IOException { String curUrl; long curUrlResponseSize; for (int i = 0; i < timeStrings.length; i++) { curUrl = baseUrl + timeStrings[i]; curUrlResponseSize = IO.copyUrlB(curUrl, null, 8000); logger.debug("[{}] {}: {}", i, timeStrings[i], curUrlResponseSize); } }
static public void copyURL2null(String url, int bufferSize) throws IOException { long start = System.currentTimeMillis(); long count = IO.copyUrlB(url, null, bufferSize); double len = (double) count / (1000 * 1000); double took = .001 * (System.currentTimeMillis() - start); double rate = len / took ; System.out.println(" copyURL2null (" + url + ") took = " + took + " sec; len= "+len+" Mbytes; rate = " + Format.d(rate, 3) + " Mb/sec"); }
@Test @Category(NeedsExternalResource.class) public void hitMl8081TdsWms() throws IOException { String curUrl; long curUrlResponseSize; for (int i = 0; i < ml8081GfsHalfDegreeBestWmsTimeStrings.length; i++) { curUrl = ml8081GfsHalfDegreeBestWmsGetMapBaseUrl + ml8081GfsHalfDegreeBestWmsTimeStrings[i]; curUrlResponseSize = IO.copyUrlB(curUrl, null, 8000); logger.debug("[{}] {}: {}", i, ml8081GfsHalfDegreeBestWmsTimeStrings[i], curUrlResponseSize); } }