当前位置: 首页>>代码示例>>Java>>正文


Java JarOutputStream.finish方法代码示例

本文整理汇总了Java中java.util.jar.JarOutputStream.finish方法的典型用法代码示例。如果您正苦于以下问题:Java JarOutputStream.finish方法的具体用法?Java JarOutputStream.finish怎么用?Java JarOutputStream.finish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarOutputStream的用法示例。


在下文中一共展示了JarOutputStream.finish方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildFakePluginJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * The minimum requirement to have a "valid" archive plugin is to include
 * findbugs.xml, messages.xml and MANIFEST.MF files. The rest of the
 * resources are load using the parent ClassLoader (Not requires to be in
 * the jar).
 * <p>
 * Instead of building a file on disk, the result of the stream is kept in
 * memory and return as a byte array.
 *
 * @return
 * @throws IOException
 * @throws URISyntaxException 
 */
private byte[] buildFakePluginJar() throws IOException, URISyntaxException {
    ClassLoader cl = getClass().getClassLoader();

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    JarOutputStream jar = new JarOutputStream(buffer);

    final URL metadata = cl.getResource("metadata");
    if (metadata != null) {
        final File dir = new File(metadata.toURI());
        
        //Add files to the jar stream
        addFilesToStream(cl, jar, dir, "");
    }
    jar.finish();
    jar.close();

    return buffer.toByteArray();
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:32,代码来源:FindBugsLauncher.java

示例2: toJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public static void toJar(File directory, File jar, Manifest manifest) throws IOException {

        if (!directory.isDirectory()) { throw new IllegalArgumentException("expected directory"); }

        final JarOutputStream jar_out = new JarOutputStream(new FileOutputStream(jar), manifest);

        copyDirectory(directory, directory, jar_out);
        jar_out.finish();
        jar_out.flush();
        jar_out.close();
    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:12,代码来源:JarUtils.java

示例3: createJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * Creates a jar file from the resources (including dex file arrays).
 *
 * @param fileName {@code non-null;} name of the file
 * @return whether the creation was successful
 */
private  boolean createJar(String fileName) {
    /*
     * Make or modify the manifest (as appropriate), put the dex
     * array into the resources map, and then process the entire
     * resources map in a uniform manner.
     */

    try {
        Manifest manifest = makeManifest();
        OutputStream out = openOutput(fileName);
        JarOutputStream jarOut = new JarOutputStream(out, manifest);

        try {
            for (Map.Entry<String, byte[]> e :
                     outputResources.entrySet()) {
                String name = e.getKey();
                byte[] contents = e.getValue();
                JarEntry entry = new JarEntry(name);
                int length = contents.length;

                if (args.verbose) {
                    DxConsole.out.println("writing " + name + "; size " + length + "...");
                }

                entry.setSize(length);
                jarOut.putNextEntry(entry);
                jarOut.write(contents);
                jarOut.closeEntry();
            }
        } finally {
            jarOut.finish();
            jarOut.flush();
            closeOutput(out);
        }
    } catch (Exception ex) {
        if (args.debug) {
            DxConsole.err.println("\ntrouble writing output:");
            ex.printStackTrace(DxConsole.err);
        } else {
            DxConsole.err.println("\ntrouble writing output: " +
                               ex.getMessage());
        }
        return false;
    }

    return true;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:54,代码来源:Main.java

示例4: createJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * Creates a jar file from the resources (including dex file arrays).
 *
 * @param fileName {@code non-null;} name of the file
 * @return whether the creation was successful
 */
private static boolean createJar(String fileName) {
    /*
     * Make or modify the manifest (as appropriate), put the dex
     * array into the resources map, and then process the entire
     * resources map in a uniform manner.
     */

    try {
        Manifest manifest = makeManifest();
        OutputStream out = openOutput(fileName);
        JarOutputStream jarOut = new JarOutputStream(out, manifest);

        try {
            for (Map.Entry<String, byte[]> e :
                    outputResources.entrySet()) {
                String name = e.getKey();
                byte[] contents = e.getValue();
                JarEntry entry = new JarEntry(name);
                int length = contents.length;

                if (args.verbose) {
                    DxConsole.out.println("writing " + name + "; size " + length + "...");
                }

                entry.setSize(length);
                jarOut.putNextEntry(entry);
                jarOut.write(contents);
                jarOut.closeEntry();
            }
        } finally {
            jarOut.finish();
            jarOut.flush();
            closeOutput(out);
        }
    } catch (Exception ex) {
        if (args.debug) {
            DxConsole.err.println("\ntrouble writing output:");
            ex.printStackTrace(DxConsole.err);
        } else {
            DxConsole.err.println("\ntrouble writing output: " +
                    ex.getMessage());
        }
        return false;
    }

    return true;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:54,代码来源:Main.java


注:本文中的java.util.jar.JarOutputStream.finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。