/** * Return a data uri from the JAR. The data must be less than 32k * * @param path the path in the jar * @param mime the mime type * @return a URI or null if conversion could not take place */ public URI getDataURI(String path, String mime, int max) throws Exception { Resource r = getResource(path); if (r.size() >= max || r.size() <= 0) return null; byte[] data = new byte[(int) r.size()]; try (DataInputStream din = new DataInputStream(r.openInputStream())) { din.readFully(data); String encoded = Base64.encodeBase64(data); return new URI("data:" + mime + ";base64," + encoded); } }
/** * Return a data uri from the JAR. The data must be less than 32k * * @param path the path in the jar * @param mime the mime type * @return a URI or null if conversion could not take place */ public URI getDataURI(String path, String mime, int max) throws Exception { Resource r = getResource(path); if (r.size() >= max || r.size() <= 0) return null; byte[] data = new byte[(int) r.size()]; try (DataInputStream din = new DataInputStream(r.openInputStream())) { din.readFully(data); String encoded = Base64.encodeBase64(data); return new URI("data:" + mime + ";base64," + encoded); } }
/** * Return a data uri from the JAR. The data must be less than 32k * * @param jar * The jar to load the data from * @param path * the path in the jar * @param mime * the mime type * @return a URI or null if conversion could not take place */ public URI getDataURI(String path, String mime, int max) throws Exception { Resource r = getResource(path); if (r.size() >= max || r.size() <= 0) return null; byte[] data = new byte[(int) r.size()]; DataInputStream din = new DataInputStream(r.openInputStream()); try { din.readFully(data); String encoded = Base64.encodeBase64(data); return new URI("data:" + mime + ";base64," + encoded); } finally { din.close(); } }
/** * Return a data uri from the JAR. The data must be less than 32k * * @param jar * The jar to load the data from * @param path * the path in the jar * @param mime * the mime type * @return a URI or null if conversion could not take place */ public URI getDataURI(String path, String mime, int max) throws Exception { Resource r = getResource(path); if (r.size() >= max || r.size() <= 0) return null; byte[] data = new byte[(int) r.size()]; DataInputStream din = new DataInputStream(r.openInputStream()); try { din.readFully(data); String encoded = Base64.encodeBase64(data); return new URI("data:" + mime + ";base64," + encoded); } finally { din.close(); } }
/** * Return a data uri from the JAR. The data must be less than 32k * * @param jar * The jar to load the data from * @param path * the path in the jar * @param mime * the mime type * @return a URI or null if conversion could not take place */ public URI getDataURI(String path, String mime, int max) throws Exception { Resource r = getResource(path); if (r.size() >= max || r.size() <= 0) return null; byte[] data = new byte[(int) r.size()]; DataInputStream din = new DataInputStream(r.openInputStream()); try { din.readFully(data); String encoded = Base64.encodeBase64(data); return new URI("data:" + mime + ";base64," + encoded); } finally { din.close(); } }
@Description("List files int a JAR file, equivalent jar command t[vf] (syntax supported)") public void _type(typeOptions opts) throws Exception { Jar jar; if (opts.file() != null) { File f = getFile(opts.file()); if (!f.isFile()) { messages.NoSuchFile_(f); return; } jar = new Jar(f); } else { jar = new Jar("cin", System.in); } try { Instructions instructions = new Instructions(opts._()); Collection<String> selected = instructions.select(jar.getResources().keySet(), true); for (String path : selected) { if (opts.verbose()) { Resource r = jar.getResource(path); err.printf("%8s %-32s %s\n", r.size(), new Date(r.lastModified()), path); } else err.printf("%s\n", path); } } finally { jar.close(); } }