private Version processScrXml(Resource resource, String path) throws Exception { if (resource == null) { return null; } SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); SAXParser parser = spf.newSAXParser(); SCRContentHandler handler = new SCRContentHandler(); parser.parse(resource.openInputStream(), handler); return handler.highest; }
@Override public void write(final OutputStream out) throws IOException, Exception { OutputStream unclosable = new FilterOutputStream(out) { @Override public void close() { // Ignore } }; for (Resource r : resources) { r.write(unclosable); unclosable.flush(); } }
private Jar buildFromResource(Resource resource) throws Exception { return buildFromInputStream(resource.openInputStream(), resource.lastModified()); }
public PreprocessResource(Processor processor, Resource r) { super(r.lastModified()); this.processor = processor; this.resource = r; setExtra(resource.getExtra()); }
/** * 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); } }
private void writeResource(ZipOutputStream jout, Set<String> directories, String path, Resource resource) throws Exception { if (resource == null) return; try { createDirectories(directories, jout, path); if (path.endsWith(Constants.EMPTY_HEADER)) return; ZipEntry ze = new ZipEntry(path); ze.setMethod(ZipEntry.DEFLATED); long lastModified = resource.lastModified(); if (lastModified == 0L) { lastModified = System.currentTimeMillis(); } ze.setTime(lastModified); if (resource.getExtra() != null) ze.setExtra(resource.getExtra().getBytes("UTF-8")); jout.putNextEntry(ze); resource.write(jout); jout.closeEntry(); } catch (Exception e) { throw new Exception("Problem writing resource " + path, e); } }
private void putEntry(ZipOutputStream jout, ZipEntry entry, Resource r) throws Exception { if (compression == Compression.STORE) { byte[] content = IO.read(r.openInputStream()); entry.setMethod(ZipOutputStream.STORED); CRC32 crc = new CRC32(); crc.update(content); entry.setCrc(crc.getValue()); entry.setSize(content.length); entry.setCompressedSize(content.length); jout.putNextEntry(entry); jout.write(content); } else { jout.putNextEntry(entry); r.write(jout); } jout.closeEntry(); }
public void addResource(Resource r) { lastModified = Math.max(lastModified, r.lastModified()); resources.add(r); }
String x = extra.get("extra"); if (x != null) r.setExtra(x); jar.putResource(name, r); } else {
/** * Turn a resource into a file so that anything in the conversion is * properly caught * * @param r * @throws Exception */ public FileResource(Resource r) throws Exception { file = Files.createTempFile("fileresource", ".resource"); deleteOnClose(true); file.toFile() .deleteOnExit(); try (OutputStream out = IO.outputStream(file)) { r.write(out); } lastModified = r.lastModified(); size = Files.size(file); }
public Set<TypeRef> parseClassFileWithCollector(ClassDataCollector cd) throws Exception { ByteBuffer bb = resource.buffer(); if (bb != null) { return parseClassFileData(ByteBufferDataInput.wrap(bb), cd); } return parseClassFile(resource.openInputStream(), cd); }
@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(); } }
Resource r = contents.get(path); if (r != null) { String extra = r.getExtra(); if (extra != null) {
/** * 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); } }
private void writeResource(ZipOutputStream jout, Set<String> directories, String path, Resource resource) throws Exception { if (resource == null) return; try { createDirectories(directories, jout, path); if (path.endsWith(Constants.EMPTY_HEADER)) return; ZipEntry ze = new ZipEntry(path); ze.setMethod(ZipEntry.DEFLATED); long lastModified = resource.lastModified(); if (lastModified == 0L) { lastModified = System.currentTimeMillis(); } ZipUtil.setModifiedTime(ze,lastModified); if (resource.getExtra() != null) ze.setExtra(resource.getExtra().getBytes("UTF-8")); jout.putNextEntry(ze); resource.write(jout); jout.closeEntry(); } catch (Exception e) { throw new Exception("Problem writing resource " + path, e); } }
public PreprocessResource(Processor processor, Resource r) { super(r.lastModified()); this.processor = processor; this.resource = r; setExtra(resource.getExtra()); }
private void putEntry(ZipOutputStream jout, ZipEntry entry, Resource r) throws Exception { if (compression == Compression.STORE) { byte[] content = IO.read(r.openInputStream()); entry.setMethod(ZipOutputStream.STORED); CRC32 crc = new CRC32(); crc.update(content); entry.setCrc(crc.getValue()); entry.setSize(content.length); entry.setCompressedSize(content.length); jout.putNextEntry(entry); jout.write(content); } else { jout.putNextEntry(entry); r.write(jout); } jout.closeEntry(); }
public void addResource(Resource r) { lastModified = Math.max(lastModified, r.lastModified()); resources.add(r); }
String x = extra.get("extra"); if (x != null) r.setExtra(x); jar.putResource(name, r); } else {
/** * Turn a resource into a file so that anything in the conversion is * properly caught * * @param r * @throws Exception */ public FileResource(Resource r) throws Exception { file = Files.createTempFile("fileresource", ".resource"); deleteOnClose(true); file.toFile() .deleteOnExit(); try (OutputStream out = IO.outputStream(file)) { r.write(out); } lastModified = r.lastModified(); size = Files.size(file); }