/** * Read the contents from the named URL and place into a String, * with any error messages put in the return String. * * @param urlString the URL to read from. * @return String holding the contents, or an error message. */ static public String readURLcontents(String urlString) { try { return readURLcontentsWithException(urlString); } catch (IOException e) { return e.getMessage(); } }
/** * Read the contents from the named URL and place into a String, * with any error messages put in the return String. * * @param urlString the URL to read from. * @return String holding the contents, or an error message. */ static public String readURLcontents(String urlString) { try { return readURLcontentsWithException(urlString); } catch (IOException e) { return e.getMessage(); } }
/** * Read the contents from the named URL and place into a String, * with any error messages put in the return String. * * @param urlString the URL to read from. * @return String holding the contents, or an error message. */ static public String readURLcontents(String urlString) { try { return readURLcontentsWithException(urlString); } catch (IOException e) { return e.getMessage(); } }
/** * Add an entity for resolution. Specify a local resource, and/or a URL. Look * for the local Resource first. * * @param entityName name of entity, eg the namespace String * @param resourceName resolve using this Resource, found on the class path * @param urlName resolve using this Resource, found on the class path */ static public void initEntity( String entityName, String resourceName, String urlName) { String entity = null; try (InputStream is = ucar.nc2.util.IO.getFileResource( resourceName)) { // try to read from local file resource, eg from catalog.jar ByteArrayOutputStream sbuff = new ByteArrayOutputStream(3000); if (is != null) { IO.copy(is, sbuff); entity = new String(sbuff.toByteArray(), CDM.utf8Charset); logger.debug(" *** entity " + entityName + " mapped to local resource at " + resourceName); } else if (urlName != null) { // otherwise, get from network entity = IO.readURLcontentsWithException(urlName); logger.debug(" *** entity "+entityName+" mapped to remote URL at "+urlName); } } catch (IOException e) { System.out.println(" *** FAILED to map entity "+entityName+" locally at "+resourceName+" or remotely at "+urlName); // e.printStackTrace(); } entityHash.put( entityName, entity); entityHash.put( urlName, entity); // also map it to the remote URL }
private void showRead(String url) throws IOException { System.out.println("****************\n"); System.out.println(url+"\n"); String contents = IO.readURLcontentsWithException( url); System.out.println(contents); }
private void showRead(String url) throws IOException { logger.debug("****************"); logger.debug(url); String contents = IO.readURLcontentsWithException( url); logger.debug(contents); } }
/** * Add an entity for resolution. Specify a local resource, and/or a URL. Look * for the local Resource first. * * @param entityName name of entity, eg the namespace String * @param resourceName resolve using this Resource, found on the class path * @param urlName resolve using this Resource, found on the class path */ static public void initEntity( String entityName, String resourceName, String urlName) { String entity = null; try (InputStream is = ucar.nc2.util.IO.getFileResource( resourceName)) { // try to read from local file resource, eg from catalog.jar ByteArrayOutputStream sbuff = new ByteArrayOutputStream(3000); if (is != null) { IO.copy(is, sbuff); entity = new String(sbuff.toByteArray(), CDM.utf8Charset); if (debugEntityResolution) System.out.println(" *** entity "+entityName+" mapped to local resource at "+resourceName); } else if (urlName != null) { // otherwise, get from network entity = IO.readURLcontentsWithException(urlName); if (debugEntityResolution) System.out.println(" *** entity "+entityName+" mapped to remote URL at "+urlName); } } catch (IOException e) { System.out.println(" *** FAILED to map entity "+entityName+" locally at "+resourceName+" or remotely at "+urlName); // e.printStackTrace(); } entityHash.put( entityName, entity); entityHash.put( urlName, entity); // also map it to the remote URL }
/** * Add an entity for resolution. Specify a local resource, and/or a URL. Look * for the local Resource first. * * @param entityName name of entity, eg the namespace String * @param resourceName resolve using this Resource, found on the class path * @param urlName resolve using this Resource, found on the class path */ static public void initEntity( String entityName, String resourceName, String urlName) { String entity = null; try { // try to read from local file resource, eg from catalog.jar ByteArrayOutputStream sbuff = new ByteArrayOutputStream(3000); InputStream is = ucar.nc2.util.IO.getFileResource( resourceName); if (is != null) { IO.copy(is, sbuff); entity = sbuff.toString(); if (debugEntityResolution) System.out.println(" *** entity "+entityName+" mapped to local resource at "+resourceName); } else if (urlName != null) { // otherwise, get from network entity = IO.readURLcontentsWithException(urlName); if (debugEntityResolution) System.out.println(" *** entity "+entityName+" mapped to remote URL at "+urlName); } } catch (IOException e) { System.out.println(" *** FAILED to map entity "+entityName+" locally at "+resourceName+" or remotely at "+urlName); // e.printStackTrace(); } entityHash.put( entityName, entity); entityHash.put( urlName, entity); // also map it to the remote URL }
@Test public void testRead() throws IOException { if (catPath.endsWith(".xml")) { Catalog cat = TdsLocalCatalog.open(catPath); assert cat != null; } else { catPath = TestOnLocalServer.withHttpPath(catPath); System.out.printf("Open html page %s%n", catPath); IO.readURLcontentsWithException(catPath); } } }