org.jboss.shrinkwrap.api.asset.ByteArrayAsset类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.jboss.shrinkwrap.api.asset.ByteArrayAsset类的一些代码示例,展示了ByteArrayAsset类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayAsset类的具体详情如下:
包路径:org.jboss.shrinkwrap.api.asset.ByteArrayAsset
类名称:ByteArrayAsset

ByteArrayAsset介绍

[英]Implementation of an Asset backed by a byte array
[中]由字节数组支持的资产的实现

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

public static Asset getStringAsAssetWithReplacements(String string, String[][] replacements) {
 for (String[] replacement : replacements) {
  string = string.replaceAll(replacement[0], replacement[1]);
 }
 return new ByteArrayAsset(string.getBytes());
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
  public void shouldBeAbleToReturnByteArray() throws Exception {
    // Make contents
    final int length = 10;
    final byte[] contents = new byte[length];
    for (int i = 0; i < length; i++) {
      contents[i] = (byte) i;
    }

    // Make Asset
    final ByteArrayAsset asset = new ByteArrayAsset(contents);
    final byte[] contentFromGetSource = asset.getSource();
    
    Assert.assertTrue(asset.getSource().length == contents.length);
       // Ensure the roundtrip matches the input (index number)
    for (int i = 0; i < length; i++) {
      Assert.assertEquals("getSource() did not equal passed in contents", i, contentFromGetSource[i]);
    }
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

final ByteArrayAsset asset = new ByteArrayAsset(contents);
final InputStream stream = asset.openStream();
final ByteArrayOutputStream out = new ByteArrayOutputStream(length);
int read;

代码示例来源:origin: camunda/camunda-bpm-platform

protected static Asset modelAsAsset(BpmnModelInstance modelInstance) {
 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
 Bpmn.writeModelToStream(byteStream, modelInstance);
 byte[] bytes = byteStream.toByteArray();
 return new ByteArrayAsset(bytes);
}

代码示例来源:origin: camunda/camunda-bpm-platform

protected static Asset modelAsAsset(BpmnModelInstance modelInstance) {
 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
 Bpmn.writeModelToStream(byteStream, modelInstance);
 byte[] bytes = byteStream.toByteArray();
 return new ByteArrayAsset(bytes);
}

代码示例来源:origin: crashub/crash

private void doTestImport(ClassLoaderFactory factory) throws Exception {
 Compiler compiler = new Compiler();
 List<JavaClassFileObject> files = compiler.compile("foo.A", "package foo;\n public class A {}");
 assertEquals(1, files.size());
 JavaClassFileObject aFile = files.get(0);
 JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "crash.jar");
 jar.add(new ByteArrayAsset(aFile.getBytes()), "foo/A.class");
 jar.setManifest(Thread.currentThread().getContextClassLoader().getResource("META-INF/MANIFEST.MF"));
 ClassLoader cl = factory.getClassLoader(jar);
 //
 compiler = new Compiler(cl);
 files = compiler.compile("B",
   "import foo.A;\n" +
     "public class B implements java.util.concurrent.Callable<A> {\n" +
     "public A call() {\n" +
     "return new A();\n" +
     "}\n" +
     "}");
 assertEquals(1, files.size());
 LoadingClassLoader loader = new LoadingClassLoader(cl, files);
 Class<?> B = loader.findClass("B");
 Callable<?> asCallable = (Callable<?>)B.newInstance();
 Object ret = asCallable.call();
 assertNotNull(ret);
 Class<?> A = ret.getClass();
 assertEquals("foo.A", A.getName());
 assertEquals(cl, A.getClassLoader());
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment(name = "dummy-client", order = 2)
public static WebArchive createDummyClientDeployment() {
 return initWebArchiveDeployment("pa2.war")
   .addAsResource(new ByteArrayAsset(serializeJavaObjectValue(new PriorityBean())), PRIORITY_BEAN_INSTANCE_FILE);
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Deployment(name = "dummy-client", order = 2)
public static WebArchive createDummyClientDeployment() {
 final WebArchive webArchive = initWebArchiveDeployment("paJavaSerialization2.war", "org/camunda/bpm/integrationtest/processes-javaSerializationEnabled-pa2.xml")
  .addAsResource(new ByteArrayAsset(serializeJavaObjectValue(new PriorityBean())), PRIORITY_BEAN_INSTANCE_FILE);
 return webArchive;
}

代码示例来源:origin: camunda/camunda-bpm-platform

.setManifest(new ByteArrayAsset(("Class-Path: " + foxPlatformClientJar.getName()+"\n").getBytes()))
.addClass(AbstractFoxPlatformIntegrationTest.class)
.addClass(TestFoxPlatformClientAsEjbModule_onePaAsLib.class);

代码示例来源:origin: org.wildfly.swarm/keycloak

private Asset createAsset(InputStream in) throws IOException {
  StringBuilder str = new StringBuilder();
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
    String line = null;
    while ((line = reader.readLine()) != null) {
      str.append(line).append("\n");
    }
  }
  return new ByteArrayAsset(str.toString().getBytes());
}

代码示例来源:origin: io.thorntail/keycloak

private Asset createKeycloakJsonAsset(InputStream in) throws IOException {
  StringBuilder str = new StringBuilder();
  try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
    String line = null;
    while ((line = reader.readLine()) != null) {
      str.append(line).append("\n");
    }
  }
  return new ByteArrayAsset(str.toString().getBytes());
}

代码示例来源:origin: wildfly-swarm-archive/ARCHIVE-wildfly-swarm

private Asset createAsset(InputStream in) {

    StringBuilder str = new StringBuilder();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {

      String line = null;

      while ((line = reader.readLine()) != null) {
        str.append(line).append("\n");
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
    return new ByteArrayAsset(str.toString().getBytes());
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

.setManifest(new ByteArrayAsset(("Class-Path: " + foxPlatformClientJar.getName()+"\n").getBytes()))
.addClass(AbstractFoxPlatformIntegrationTest.class)
.addClass(TestFoxPlatformClientAsEjbModule_twoPasAsLib.class);

代码示例来源:origin: com.adaptavist.shrinkwrap/shrinkwrap-atlassian-plugin-impl

@Override
  public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
    final Path relativePath = scannerOutput.relativize(path);
    addAsResource(new ByteArrayAsset(Files.readAllBytes(path)), toArchivePath(relativePath));
    if (!debug) {
      path.toFile().delete();
    }
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: org.wildfly.swarm/tools

private void addJarManifest() {
  Manifest manifest = new Manifest();
  Attributes attrs = manifest.getMainAttributes();
  attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
  attrs.put(Attributes.Name.MAIN_CLASS, Main.class.getName());
  try {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    out.close();
    byte[] bytes = out.toByteArray();
    this.archive.addAsManifestResource(new ByteArrayAsset(bytes), "MANIFEST.MF");
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: io.thorntail/tools

private void addJarManifest() {
  Manifest manifest = new Manifest();
  Attributes attrs = manifest.getMainAttributes();
  attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
  attrs.put(Attributes.Name.MAIN_CLASS, Main.class.getName());
  try {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    manifest.write(out);
    out.close();
    byte[] bytes = out.toByteArray();
    this.archive.addAsManifestResource(new ByteArrayAsset(bytes), "MANIFEST.MF");
  } catch (IOException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: org.arquillian.liferay/arquillian-processor-osgi-allin

@Override
public void replaceManifest(Archive archive, Manifest manifest )
  throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  manifest.write(baos);
  ByteArrayAsset byteArrayAsset = new ByteArrayAsset(baos.toByteArray());
  archive.delete(JarFile.MANIFEST_NAME);
  archive.add(byteArrayAsset, JarFile.MANIFEST_NAME);
}

代码示例来源:origin: wildfly-swarm-archive/ARCHIVE-wildfly-swarm

private void addWildFlySwarmProperties() throws IOException {
  Properties props = new Properties();
  Enumeration<?> propNames = this.properties.propertyNames();
  while (propNames.hasMoreElements()) {
    String eachName = (String) propNames.nextElement();
    String eachValue = this.properties.get(eachName).toString();
    props.put(eachName, eachValue);
  }
  props.setProperty(BootstrapProperties.APP_ARTIFACT, this.projectAsset.getSimpleName());
  if (this.bundleDependencies) {
    props.setProperty(BootstrapProperties.BUNDLED_DEPENDENCIES, "true");
  }
  ByteArrayOutputStream propsBytes = new ByteArrayOutputStream();
  props.store(propsBytes, "Generated by WildFly Swarm");
  this.archive.addAsManifestResource(new ByteArrayAsset(propsBytes.toByteArray()), "wildfly-swarm.properties");
}

代码示例来源:origin: org.gatein.pc/pc-test-core

private static void addResources(URL root, WebArchive target) throws Exception
{
 if (root.getProtocol().equals("file"))
 {
   addResources(new File(root.toURI()), target, new LinkedList<String>());
 }
 else if (root.getProtocol().equals("jar"))
 {
   String path = root.getFile();
   String prefix = path.substring(path.indexOf("!/") + 2);
   JarURLConnection conn = (JarURLConnection)root.openConnection();
   JarFile jarFile = conn.getJarFile();
   for (JarEntry entry : Collections.list(conn.getJarFile().entries()))
   {
    if (!entry.isDirectory() && entry.getName().startsWith(prefix))
    {
      String key = entry.getName().substring(prefix.length());
      target.addAsWebResource(new ByteArrayAsset(jarFile.getInputStream(entry)), key);
    }
   }
 }
}

代码示例来源:origin: reactiverse/vertx-maven-plugin

/**
   * Generate the manifest for the über jar.
   */
  private static void generateManifest(JavaArchive jar, Map<String, String> entries) throws IOException {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    if (entries != null) {
      for (Map.Entry<String, String> entry : entries.entrySet()) {
        attributes.put(new Attributes.Name(entry.getKey()), entry.getValue());
      }
    }

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    manifest.write(bout);
    bout.close();
    byte[] bytes = bout.toByteArray();
    //TODO: merge existing manifest with current one
    jar.setManifest(new ByteArrayAsset(bytes));

  }
}

相关文章

微信公众号

最新文章

更多

ByteArrayAsset类方法