org.apache.commons.compress.archivers.jar.JarArchiveEntry Java Examples

The following examples show how to use org.apache.commons.compress.archivers.jar.JarArchiveEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XDecryption.java    From xjar with Apache License 2.0 6 votes vote down vote up
/**
 * 指定原文包文件, 并执行解密.
 *
 * @param jar 原文包文件
 * @throws Exception 解密异常
 */
public void to(File jar) throws Exception {
    if (xJar == null) {
        throw new IllegalArgumentException("xJar to decrypt is null. [please call from(String xJar) or from(File xJar) before]");
    }
    if (key == null) {
        throw new IllegalArgumentException("key to decrypt is null. [please call use(String password) or use(String algorithm, int keysize, int ivsize, String password) before]");
    }
    XMixEntryFilter<JarArchiveEntry> filter;
    if (includes.size() == 0 && excludes.size() == 0) {
        filter = null;
    } else {
        filter = XKit.all();
        if (includes.size() > 0) {
            filter.mix(includes);
        }
        if (excludes.size() > 0) {
            filter.mix(excludes);
        }
    }
    XCryptos.decrypt(xJar, jar, key, filter);
}
 
Example #2
Source File: XInjector.java    From xjar with Apache License 2.0 6 votes vote down vote up
/**
 * 往JAR包中注入XJar框架的classes
 *
 * @param zos jar包输出流
 * @throws IOException I/O 异常
 */
public static void inject(JarArchiveOutputStream zos) throws IOException {
    Set<String> directories = new HashSet<>();
    Enumeration<Resource> resources = Loaders.ant().load("io/xjar/**");
    while (resources.hasMoreElements()) {
        Resource resource = resources.nextElement();
        String name = resource.getName();
        String directory = name.substring(0, name.lastIndexOf('/') + 1);
        if (directories.add(directory)) {
            JarArchiveEntry xDirEntry = new JarArchiveEntry(directory);
            xDirEntry.setTime(System.currentTimeMillis());
            zos.putArchiveEntry(xDirEntry);
            zos.closeArchiveEntry();
        }
        JarArchiveEntry xJarEntry = new JarArchiveEntry(name);
        xJarEntry.setTime(System.currentTimeMillis());
        zos.putArchiveEntry(xJarEntry);
        try (InputStream ris = resource.getInputStream()) {
            XKit.transfer(ris, zos);
        }
        zos.closeArchiveEntry();
    }
}
 
Example #3
Source File: XEncryption.java    From xjar with Apache License 2.0 6 votes vote down vote up
/**
 * 指定密文包文件, 并执行加密.
 *
 * @param xJar 密文包文件
 * @throws Exception 加密异常
 */
public void to(File xJar) throws Exception {
    if (jar == null) {
        throw new IllegalArgumentException("jar to encrypt is null. [please call from(String jar) or from(File jar) before]");
    }
    if (key == null) {
        throw new IllegalArgumentException("key to encrypt is null. [please call use(String password) or use(String algorithm, int keysize, int ivsize, String password) before]");
    }
    XMixEntryFilter<JarArchiveEntry> filter;
    if (includes.size() == 0 && excludes.size() == 0) {
        filter = null;
    } else {
        filter = XKit.all();
        if (includes.size() > 0) {
            filter.mix(includes);
        }
        if (excludes.size() > 0) {
            filter.mix(excludes);
        }
    }
    XCryptos.encrypt(jar, xJar, key, filter);
}
 
Example #4
Source File: TestUtils.java    From coroutines with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void writeJarEntry(JarArchiveOutputStream jaos, String name, byte[] data) throws IOException {
    ZipArchiveEntry entry = new JarArchiveEntry(name);
    entry.setSize(data.length);
    jaos.putArchiveEntry(entry);
    jaos.write(data);
    jaos.closeArchiveEntry();
}
 
Example #5
Source File: FileSystemClassInformationRepository.java    From coroutines with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addJar(File file) throws IOException {
    Validate.notNull(file);
    Validate.isTrue(file.isFile());
    try (FileInputStream fis = new FileInputStream(file);
            JarArchiveInputStream jais = new JarArchiveInputStream(fis)) {
        JarArchiveEntry entry;
        while ((entry = jais.getNextJarEntry()) != null) {
            if (!entry.getName().endsWith(".class") || entry.isDirectory()) {
                continue;
            }

            populateSuperClassMapping(jais);
        }
    }
}
 
Example #6
Source File: ArchiveUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recursively create JAR archive from directory
 */
public static void createJar(File path, String root, OutputStream os) throws IOException {
	log.debug("createJar({}, {}, {})", new Object[]{path, root, os});

	if (path.exists() && path.canRead()) {
		JarArchiveOutputStream jaos = new JarArchiveOutputStream(os);
		jaos.setComment("Generated by OpenKM");
		jaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
		jaos.setUseLanguageEncodingFlag(true);
		jaos.setFallbackToUTF8(true);
		jaos.setEncoding("UTF-8");

		// Prevents java.util.jar.JarException: JAR file must have at least one entry
		JarArchiveEntry jae = new JarArchiveEntry(root + "/");
		jaos.putArchiveEntry(jae);
		jaos.closeArchiveEntry();

		createJarHelper(path, jaos, root);

		jaos.flush();
		jaos.finish();
		jaos.close();
	} else {
		throw new IOException("Can't access " + path);
	}

	log.debug("createJar: void");
}
 
Example #7
Source File: ZipSigner.java    From BusyBox with Apache License 2.0 5 votes vote down vote up
/** Copy all the files in a manifest from input to output. */
private static void copyFiles(Manifest manifest, JarFile in, JarArchiveOutputStream out, long timestamp)
    throws IOException {
  final byte[] buffer = new byte[4096];
  int num;

  final Map<String, Attributes> entries = manifest.getEntries();
  final List<String> names = new ArrayList<>(entries.keySet());
  Collections.sort(names);
  for (final String name : names) {
    final JarEntry inEntry = in.getJarEntry(name);
    if (inEntry.getMethod() == JarArchiveEntry.STORED) {
      // Preserve the STORED method of the input entry.
      out.putArchiveEntry(new JarArchiveEntry(inEntry));
    } else {
      // Create a new entry so that the compressed len is recomputed.
      final JarArchiveEntry je = new JarArchiveEntry(name);
      je.setTime(timestamp);
      out.putArchiveEntry(je);
    }

    final InputStream data = in.getInputStream(inEntry);
    while ((num = data.read(buffer)) > 0) {
      out.write(buffer, 0, num);
    }
    out.flush();
    out.closeArchiveEntry();
  }
}
 
Example #8
Source File: XIncludeAntEntryFilter.java    From xjar-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean filtrate(JarArchiveEntry entry) {
    return matches(entry.getName());
}
 
Example #9
Source File: XJarDecryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XJarDecryptor(XDecryptor xDecryptor, int level, XEntryFilter<JarArchiveEntry> filter) {
    super(xDecryptor, filter);
    this.level = level;
}
 
Example #10
Source File: XJarDecryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XJarDecryptor(XDecryptor xDecryptor, XEntryFilter<JarArchiveEntry> filter) {
    this(xDecryptor, Deflater.DEFAULT_COMPRESSION, filter);
}
 
Example #11
Source File: XJarEncryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XJarEncryptor(XEncryptor xEncryptor, int level, XEntryFilter<JarArchiveEntry> filter) {
    super(xEncryptor, filter);
    this.level = level;
}
 
Example #12
Source File: XJarEncryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XJarEncryptor(XEncryptor xEncryptor, XEntryFilter<JarArchiveEntry> filter) {
    this(xEncryptor, Deflater.DEFAULT_COMPRESSION, filter);
}
 
Example #13
Source File: XJarRegexEntryFilter.java    From xjar with Apache License 2.0 4 votes vote down vote up
@Override
protected String toText(JarArchiveEntry entry) {
    return entry.getName();
}
 
Example #14
Source File: XJarAntEntryFilter.java    From xjar with Apache License 2.0 4 votes vote down vote up
@Override
protected String toText(JarArchiveEntry entry) {
    return entry.getName();
}
 
Example #15
Source File: XSmartEncryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XSmartEncryptor(XEncryptor xEncryptor, XEntryFilter<JarArchiveEntry> filter) {
    super(xEncryptor, filter);
}
 
Example #16
Source File: XExcludeAntEntryFilter.java    From xjar-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean filtrate(JarArchiveEntry entry) {
    return !matches(entry.getName());
}
 
Example #17
Source File: XJarAllEntryFilter.java    From xjar with Apache License 2.0 4 votes vote down vote up
@Override
public boolean filtrate(JarArchiveEntry entry) {
    return true;
}
 
Example #18
Source File: XSmartDecryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XSmartDecryptor(XDecryptor xDecryptor, XEntryFilter<JarArchiveEntry> filter) {
    super(xDecryptor, filter);
}
 
Example #19
Source File: XBootDecryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XBootDecryptor(XDecryptor xDecryptor, XEntryFilter<JarArchiveEntry> filter) {
    this(xDecryptor, Deflater.DEFAULT_COMPRESSION, filter);
}
 
Example #20
Source File: XBootDecryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XBootDecryptor(XDecryptor xDecryptor, int level, XEntryFilter<JarArchiveEntry> filter) {
    super(xDecryptor, filter);
    this.level = level;
}
 
Example #21
Source File: XBootEncryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XBootEncryptor(XEncryptor xEncryptor, XEntryFilter<JarArchiveEntry> filter) {
    this(xEncryptor, Deflater.DEFAULT_COMPRESSION, filter);
}
 
Example #22
Source File: XBootEncryptor.java    From xjar with Apache License 2.0 4 votes vote down vote up
public XBootEncryptor(XEncryptor xEncryptor, int level, XEntryFilter<JarArchiveEntry> filter) {
    super(xEncryptor, filter);
    this.level = level;
}
 
Example #23
Source File: ExecMojo.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void createExecutableJar() throws Exception {
    mkdirs(execFile.getParentFile());

    final Properties config = new Properties();
    config.put("distribution", distributionName);
    config.put("workingDir", runtimeWorkingDir);
    config.put("command", DEFAULT_SCRIPT.equals(script) ? (skipArchiveRootFolder ? "" : catalinaBase.getName() + "/") + DEFAULT_SCRIPT : script);
    final List<String> jvmArgs = generateJVMArgs();

    final String catalinaOpts = toString(jvmArgs, " ");
    config.put("catalinaOpts", catalinaOpts);
    config.put("timestamp", Long.toString(System.currentTimeMillis()));
    // java only
    final String cp = getAdditionalClasspath();
    if (cp != null) {
        config.put("additionalClasspath", cp);
    }
    config.put("shutdownCommand", tomeeShutdownCommand);
    int i = 0;
    boolean encodingSet = catalinaOpts.contains("-Dfile.encoding");
    for (final String jvmArg : jvmArgs) {
        config.put("jvmArg." + i++, jvmArg);
        encodingSet = encodingSet || jvmArg.contains("-Dfile.encoding");
    }
    if (!encodingSet) { // forcing encoding for launched process to be able to read conf files
        config.put("jvmArg." + i, "-Dfile.encoding=UTF-8");
    }

    if (preTasks != null) {
        config.put("preTasks", toString(preTasks, ","));
    }
    if (postTasks != null) {
        config.put("postTasks", toString(postTasks, ","));
    }
    config.put("waitFor", Boolean.toString(waitFor));

    // create an executable jar with main runner and zipFile
    final FileOutputStream fileOutputStream = new FileOutputStream(execFile);
    final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.JAR, fileOutputStream);

    { // distrib
        os.putArchiveEntry(new JarArchiveEntry(distributionName));
        final FileInputStream in = new FileInputStream(zipFile);
        try {
            IOUtils.copy(in, os);
            os.closeArchiveEntry();
        } finally {
            IOUtil.close(in);
        }
    }

    { // config
        os.putArchiveEntry(new JarArchiveEntry("configuration.properties"));
        final StringWriter writer = new StringWriter();
        config.store(writer, "");
        IOUtils.copy(new ByteArrayInputStream(writer.toString().getBytes("UTF-8")), os);
        os.closeArchiveEntry();
    }

    { // Manifest
        final Manifest manifest = new Manifest();

        final Manifest.Attribute mainClassAtt = new Manifest.Attribute();
        mainClassAtt.setName("Main-Class");
        mainClassAtt.setValue(runnerClass);
        manifest.addConfiguredAttribute(mainClassAtt);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
        manifest.write(baos);

        os.putArchiveEntry(new JarArchiveEntry("META-INF/MANIFEST.MF"));
        IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), os);
        os.closeArchiveEntry();
    }

    { // Main + utility
        for (final Class<?> clazz : asList(
                ExecRunner.class,
                Files.class, Files.PatternFileFilter.class, Files.DeleteThread.class,
                Files.FileRuntimeException.class, Files.FileDoesNotExistException.class, Files.NoopOutputStream.class,
                LoaderRuntimeException.class,
                Pipe.class, IO.class, Zips.class, JarLocation.class,
                RemoteServer.class, RemoteServer.CleanUpThread.class,
                OpenEJBRuntimeException.class, Join.class, QuickServerXmlParser.class,
                Options.class, Options.NullLog.class, Options.TomEEPropertyAdapter.class, Options.NullOptions.class,
                Options.Log.class, JavaSecurityManagers.class)) {
            addToJar(os, clazz);
        }
    }
    addClasses(additionalClasses, os);
    addClasses(preTasks, os);
    addClasses(postTasks, os);

    IOUtil.close(os);
    IOUtil.close(fileOutputStream);
}
 
Example #24
Source File: ExecMojo.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void addToJar(final ArchiveOutputStream os, final Class<?> clazz) throws IOException {
    final String name = clazz.getName().replace('.', '/') + ".class";
    os.putArchiveEntry(new JarArchiveEntry(name));
    IOUtils.copy(getClass().getResourceAsStream('/' + name), os);
    os.closeArchiveEntry();
}
 
Example #25
Source File: XBoot.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 加密 Spring-Boot JAR 包
 *
 * @param in     原文包输入流
 * @param out    加密包输出流
 * @param xKey   密钥
 * @param filter 过滤器
 * @throws Exception 加密异常
 */
public static void encrypt(InputStream in, OutputStream out, XKey xKey, XEntryFilter<JarArchiveEntry> filter) throws Exception {
    XBootEncryptor xBootEncryptor = new XBootEncryptor(new XJdkEncryptor(), filter);
    xBootEncryptor.encrypt(xKey, in, out);
}
 
Example #26
Source File: XFilters.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 创建非门逻辑运算过滤器,实际上就是将委派过滤器的过滤结果取反
 *
 * @param filter 委派过滤器
 * @return 非门逻辑过滤器
 */
public static XNotEntryFilter<JarArchiveEntry> not(XEntryFilter<JarArchiveEntry> filter) {
    return new XNotEntryFilter<>(filter);
}
 
Example #27
Source File: XBoot.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 加密 Spring-Boot JAR 包
 *
 * @param src    原文包
 * @param dest   加密包
 * @param xKey   密钥
 * @param filter 过滤器
 * @throws Exception 加密异常
 */
public static void encrypt(File src, File dest, XKey xKey, XEntryFilter<JarArchiveEntry> filter) throws Exception {
    XBootEncryptor xBootEncryptor = new XBootEncryptor(new XJdkEncryptor(), filter);
    xBootEncryptor.encrypt(xKey, src, dest);
}
 
Example #28
Source File: XBoot.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 加密 Spring-Boot JAR 包
 *
 * @param src    原文包
 * @param dest   加密包
 * @param xKey   密钥
 * @param filter 过滤器
 * @throws Exception 加密异常
 */
public static void encrypt(String src, String dest, XKey xKey, XEntryFilter<JarArchiveEntry> filter) throws Exception {
    encrypt(new File(src), new File(dest), xKey, filter);
}
 
Example #29
Source File: XJar.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 加密 普通 JAR 包
 *
 * @param in     原文包输入流
 * @param out    加密包输出流
 * @param xKey   密钥
 * @param filter 过滤器
 * @throws Exception 加密异常
 */
public static void encrypt(InputStream in, OutputStream out, XKey xKey, XEntryFilter<JarArchiveEntry> filter) throws Exception {
    XJarEncryptor xJarEncryptor = new XJarEncryptor(new XJdkEncryptor(), filter);
    xJarEncryptor.encrypt(xKey, in, out);
}
 
Example #30
Source File: XFilters.java    From xjar with Apache License 2.0 2 votes vote down vote up
/**
 * 创建多个子过滤器OR连接的混合过滤器
 *
 * @param filters 子过滤器
 * @return 多个子过滤器OR连接的混合过滤器
 */
public static XMixEntryFilter<JarArchiveEntry> or(Collection<? extends XEntryFilter<? extends JarArchiveEntry>> filters) {
    return any(filters);
}