/** * Returns an URL object for the given URL specification. * * @param specification * the URL specification. * @return * an URL object; if the URL is of "classpath://" type, it will return an URL * whose connection will be opened by a specialised stream handler. * @throws MalformedURLException */ public static URL makeURL(String specification) throws MalformedURLException { logger.trace("retrieving URL for specification: '{}'", specification); if(specification.startsWith("classpath:")) { logger.trace("URL is of type 'classpath'"); return new URL(null, specification, new ClassPathURLStreamHandler()); } logger.trace("URL is of normal type"); return new URL(specification); }
public static Font loadDefaultFont(int style, int size) { Font font = null; try(InputStream input = URLFactory.makeURL("classpath:org/dihedron/ui/verdana.ttf").openStream()) { font = Font.createFont(Font.TRUETYPE_FONT, input).deriveFont(style, size); } catch (FontFormatException | IOException e) { logger.error("error loading font", e); } return font; }
/** * @see org.dihedron.patterns.cache.Storage#retrieve(java.lang.String) */ @Override public InputStream retrieve(String resource) { InputStream stream = null; try { if(contains(resource)) { logger.trace("retrieving resource at URL '{}'", resource); URL url = URLFactory.makeURL(resource); stream = url.openConnection(proxy != null ? proxy : Proxy.NO_PROXY).getInputStream(); } } catch (MalformedURLException e) { logger.error("error parsing URL", e); } catch (IOException e) { logger.error("error opening connection", e); } return stream; }
/** * Returns an URL object for the given URL specification. * * @param specification * the URL specification. * @return * an URL object; if the URL is of "classpath://" type, it will return an URL * whose connection will be opened by a specialised stream handler. * @throws MalformedURLException */ public static URL makeURL(String specification) throws MalformedURLException { logger.trace("retrieving URL for specification: '{}'", specification); if(specification.startsWith("classpath:")) { logger.trace("URL is of type 'classpath'"); return new URL(null, specification, new ClassPathURLStreamHandler()); } logger.trace("URL is of normal type"); return new URL(specification); }
/** * Reads a resource from an URL, specified as a string; since this class makes * use of the URL factory, URLs may also represent resources in the class * path, re (in the format "classpath:org/dihedron/resources/MyResource.png"). * * @param url * a string presenting an URL. * @return * an input stream to access the URL. * @throws IOException * if the URL is malformed or an error occurs opening the stream. */ public static InputStream fromURL(String url) throws IOException { if(Strings.isValid(url)) { return fromURL(URLFactory.makeURL(url)); } return null; }
/** * Returns an URL object for the given URL specification. * * @param specification * the URL specification. * @return * an URL object; if the URL is of "classpath://" type, it will return an URL * whose connection will be opened by a specialised stream handler. * @throws MalformedURLException */ public static URL makeURL(String specification) throws MalformedURLException { logger.trace("retrieving URL for specification: '{}'", specification); if(specification.startsWith("classpath:")) { logger.trace("URL is of type 'classpath'"); return new URL(null, specification, new ClassPathURLStreamHandler()); } logger.trace("URL is of normal type"); return new URL(specification); }
/** * Reads a resource from an URL, specified as a string; since this class makes * use of the URL factory, URLs may also represent resources in the class * path, re (in the format "classpath:org/dihedron/resources/MyResource.png"). * * @param url * a string presenting an URL. * @return * an input stream to access the URL. * @throws IOException * if the URL is malformed or an error occurs opening the stream. */ public static InputStream fromURL(String url) throws IOException { if(Strings.isValid(url)) { return fromURL(URLFactory.makeURL(url)); } return null; }
/** * Reads a resource from an URL, specified as a string; since this class makes * use of the URL factory, URLs may also represent resources in the class * path, re (in the format "classpath:org/dihedron/resources/MyResource.png"). * * @param url * a string presenting an URL. * @return * an input stream to access the URL. * @throws IOException * if the URL is malformed or an error occurs opening the stream. */ public static InputStream fromURL(String url) throws IOException { if(Strings.isValid(url)) { return fromURL(URLFactory.makeURL(url)); } return null; }