List of utility methods to do Resource File
byte[] | put(String resource, Map put URL url; ByteArrayOutputStream baos = null; OutputStreamWriter wr = null; try { url = new URL(resource); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(HTTP_CONNECT_TIMEOUT); urlConnection.setReadTimeout(HTTP_READ_TIMEOUT); ... |
boolean | resourceExists(String s) Resource indicated by s can be a file name or a URL. boolean ret = false; Object o = getSourceForResource(s); if (o != null) { if (o instanceof File) { ret = ((File) o).exists(); } else if (o instanceof URL) { try { ret = ((URL) o).openStream() != null; ... |
URL | runtimeResourceLocation(String src) Attempts to resolve the src to a URL. URL url = null; String[] variants = { src, src + ".class", src.replaceAll("\\.", "\\\\"), src.replaceAll("\\.", "\\\\") + ".class", src.replaceAll("\\.", "/"), src.replaceAll("\\.", "/") + ".class", }; for (int i = 0; url == null && i < variants.length; i++) url = Driver.class.getClassLoader().getResource(variants[i]); return url; |
String | sanitizeResource(String inputResource) Returns a more practical audio resource name. if (inputResource.toLowerCase().endsWith("pls")) { inputResource = parsePLS(inputResource); } else if (inputResource.toLowerCase().endsWith("m3u")) { inputResource = parseM3U(inputResource); } else if (inputResource.toLowerCase().endsWith("asx")) { inputResource = parseASX(inputResource); } else if (inputResource.toLowerCase().endsWith("xspf")) { inputResource = parseXSPF(inputResource); ... |
File | toFile(Class c, String resource) Converts the URL of the specified resource into an abstract pathname. URL resourceUrl = c.getResource(resource); if (resourceUrl == null) return null; try { return new File(new URI(resourceUrl.toExternalForm())); } catch (URISyntaxException e) { throw new AssertionError(e); |
InputStream | toStream(String resource) to Stream if (resource == null) return null; int ind = resource.indexOf(PROTOCOL_DELIM); if (ind > 1) { String protocol = resource.substring(0, ind); resource = resource.substring(ind + PROTOCOL_DELIM_LEN); for (int i = 0; i < URL_PROTOCOLS.length; i++) { String p = URL_PROTOCOLS[i]; ... |
File | unpackDeps(final String resource, final ClassLoader cl) unpack Deps final URL url = cl.getResource(resource); if (url == null) throw new IllegalArgumentException("Can't find " + resource + " in classpath."); final String protocol = url.getProtocol(); if (protocol.equals(JAR_PROTOCOL)) { String path = url.getPath(); final int i = path.indexOf('!'); if (i <= 0) { ... |