/** * Creates a bnd resource that contains the generated dm descriptor. * @param collector * @return * @throws IOException */ private Resource createComponentResource(AnnotationCollector collector) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "UTF-8")); collector.writeTo(pw); pw.close(); byte[] data = out.toByteArray(); out.close(); return new EmbeddedResource(data, 0); }
public Jar(String name, InputStream in, long lastModified) throws IOException { this(name); EmbeddedResource.build(this, in, lastModified); }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
/** * Convenience method to turn an inputstream into a byte array. The method * uses a recursive algorithm to minimize memory usage. * * @param in * stream with data * @param offset * where we are in the stream * @returns byte array filled with data */ static byte[] collect(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); }
@Override public InputStream openInputStream() { return IO.stream(buffer()); }
@Override public String toString() { return ":" + size() + ":"; }
/** * Convenience method to turn an inputstream into a byte array. The method * uses a recursive algorithm to minimize memory usage. * * @param in * stream with data * @param offset * where we are in the stream * @returns byte array filled with data */ static byte[] collect(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); }
@Override public void write(OutputStream out) throws Exception { IO.copy(buffer(), out); }
@Override public String toString() { return ":" + size() + ":"; }
private Jar buildFromInputStream(InputStream in, long lastModified) throws IOException { try (ZipInputStream jin = new ZipInputStream(in)) { for (ZipEntry entry; (entry = jin.getNextEntry()) != null;) { if (entry.isDirectory()) { continue; } int size = (int) entry.getSize(); try (ByteBufferOutputStream bbos = new ByteBufferOutputStream((size == -1) ? BUFFER_SIZE : size + 1)) { bbos.write(jin); putResource(entry.getName(), new EmbeddedResource(bbos.toByteBuffer(), lastModified), true); } } } return this; }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
public Jar(String name, InputStream in, long lastModified) throws IOException { this(name); EmbeddedResource.build(this, in, lastModified); }
/** * Convenience method to turn an inputstream into a byte array. The method * uses a recursive algorithm to minimize memory usage. * * @param in * stream with data * @param offset * where we are in the stream * @returns byte array filled with data */ static byte[] collect(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); }
@Override public void write(OutputStream out) throws Exception { IO.copy(buffer(), out); }
/** * @param jar * @throws IOException */ private void doMavenMetadata( MavenProject currentProject, Jar jar ) throws IOException { String path = "META-INF/maven/" + currentProject.getGroupId() + "/" + currentProject.getArtifactId(); File pomFile = currentProject.getFile(); if ( pomFile == null || !pomFile.exists() ) { pomFile = new File( currentProject.getBasedir(), "pom.xml" ); } if ( pomFile.exists() ) { jar.putResource( path + "/pom.xml", new FileResource( pomFile ) ); } Properties p = new Properties(); p.put( "version", currentProject.getVersion() ); p.put( "groupId", currentProject.getGroupId() ); p.put( "artifactId", currentProject.getArtifactId() ); ByteArrayOutputStream out = new ByteArrayOutputStream(); p.store( out, "Generated by org.apache.felix.bundleplugin" ); jar.putResource( path + "/pom.properties", new EmbeddedResource( out.toByteArray(), System.currentTimeMillis() ) ); }
public static void build(Jar jar, InputStream in, long lastModified) throws IOException { ZipInputStream jin = new ZipInputStream(in); ZipEntry entry = jin.getNextEntry(); while (entry != null) { if (!entry.isDirectory()) { byte data[] = collect(jin); jar.putResource(entry.getName(), new EmbeddedResource(data, lastModified), true); } entry = jin.getNextEntry(); } IO.drain(in); jin.close(); }
public Jar(String name, InputStream in, long lastModified) throws IOException { this(name); EmbeddedResource.build(this, in, lastModified); }
@Override public InputStream openInputStream() { return IO.stream(buffer()); }
public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { String type = argumentsOnMake.get("type"); if (!type.equals("copy")) return null; String from = argumentsOnMake.get("from"); if (from == null) { String content = argumentsOnMake.get("content"); if (content == null) throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake); return new EmbeddedResource(content.getBytes("UTF-8"), 0); } File f = builder.getFile(from); if (f.isFile()) return new FileResource(f); try { URL url = new URL(from); return new URLResource(url); } catch (MalformedURLException mfue) { // We ignore this } throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination); }
public Jar(String name, String path) throws IOException { this(name); File f = new File(path); InputStream in = new FileInputStream(f); EmbeddedResource.build(this, in, f.lastModified()); in.close(); }