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


Java JarOutputStream.flush方法代码示例

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


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

示例1: testPrescan

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void testPrescan() throws Exception {
    File j = new File(getWorkDir(), "x.jar");
    try (OutputStream os = new FileOutputStream(j)) {
        JarOutputStream jos = new JarOutputStream(os, new Manifest(new ByteArrayInputStream("Manifest-Version: 1.0\nBundle-SymbolicName: org.eclipse.mylyn.bugzilla.core;singleton:=true\nExport-Package: org.eclipse.mylyn.internal.bugzilla.core;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.history;x-friends:=\"org.eclipse.mylyn.bugzilla.ide,org.eclipse.mylyn.bugzilla.ui\",org.eclipse.mylyn.internal.bugzilla.core.service;x-internal:=true\n".getBytes())));
        jos.flush();
        jos.close();
    }
    Info info = new MakeOSGi.Info();
    JarFile jf = new JarFile(j);
    try {
        assertEquals("org.eclipse.mylyn.bugzilla.core", MakeOSGi.prescan(jf, info, new Task() {}));
    } finally {
        jf.close();
    }
    assertEquals("[org.eclipse.mylyn.internal.bugzilla.core, org.eclipse.mylyn.internal.bugzilla.core.history, org.eclipse.mylyn.internal.bugzilla.core.service]", info.exportedPackages.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:MakeOSGiTest.java

示例2: createRealJarFile

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void createRealJarFile(File f) throws Exception {
        OutputStream os = new FileOutputStream(f);
        try {
            JarOutputStream jos = new JarOutputStream(os);
//            jos.setMethod(ZipEntry.STORED);
            JarEntry entry = new JarEntry("foo.txt");
//            entry.setSize(0L);
//            entry.setTime(System.currentTimeMillis());
//            entry.setCrc(new CRC32().getValue());
            jos.putNextEntry(entry);
            jos.flush();
            jos.close();
        } finally {
            os.close();
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaProjectGeneratorTest.java

示例3: createTempJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * 创建临时文件*.jar
 * 
 * @param root
 * @return
 * @throws IOException
 */
public static File createTempJar(String root) throws IOException {
    if (!new File(root).exists()) {
        return null;
    }

    final File jarFile = File.createTempFile("EJob-", ".jar", new File(System
            .getProperty("java.io.tmpdir")));

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            jarFile.delete();
        }
    });

    JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
    createTempJarInner(out, new File(root), "");
    out.flush();
    out.close();
    return jarFile;
}
 
开发者ID:liuhaozzu,项目名称:big_data,代码行数:29,代码来源:EJob.java

示例4: testJarMapping

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * Check that jar: URLs are correctly mapped back into JarFileSystem resources.
 * @see "#39190"
 */
public void testJarMapping() throws Exception {
    clearWorkDir();
    File workdir = getWorkDir();
    File jar = new File(workdir, "test.jar");
    String textPath = "x.txt";
    OutputStream os = new FileOutputStream(jar);
    try {
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(ZipEntry.STORED);
        JarEntry entry = new JarEntry(textPath);
        entry.setSize(0L);
        entry.setTime(System.currentTimeMillis());
        entry.setCrc(new CRC32().getValue());
        jos.putNextEntry(entry);
        jos.flush();
        jos.close();
    } finally {
        os.close();
    }
    assertTrue("JAR was created", jar.isFile());
    assertTrue("JAR is not empty", jar.length() > 0L);
    JarFileSystem jfs = new JarFileSystem();
    jfs.setJarFile(jar);
    Repository.getDefault().addFileSystem(jfs);
    FileObject rootFO = jfs.getRoot();
    FileObject textFO = jfs.findResource(textPath);
    assertNotNull("JAR contains a/b.txt", textFO);
    String rootS = "jar:" + BaseUtilities.toURI(jar) + "!/";
    URL rootU = new URL(rootS);
    URL textU = new URL(rootS + textPath);
    assertEquals("correct FO -> URL for root", rootU, URLMapper.findURL(rootFO, URLMapper.EXTERNAL));
    assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL));
    assertTrue("correct URL -> FO for root", Arrays.asList(URLMapper.findFileObjects(rootU)).contains(rootFO));
    assertTrue("correct URL -> FO for " + textPath, Arrays.asList(URLMapper.findFileObjects(textU)).contains(textFO));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:URLMapperTest.java

示例5: reconstructBootstrapJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private static void reconstructBootstrapJar() throws IOException {

        final Manifest manifest = new Manifest();
        final Attributes main_attributes = manifest.getMainAttributes();
        main_attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
        main_attributes.put(Attributes.Name.MAIN_CLASS, Bootstrap.class.getName());
        main_attributes.put(Attributes.Name.CLASS_PATH, ".:*");
        main_attributes.put(PREMAIN_CLASS, Bootstrap.class.getName());
        FileUtils.forceMkdir(LOCAL_BOOTSTRAP_HOME);
        final JarOutputStream jar_stream = new JarOutputStream(new FileOutputStream(BOOTSTRAP_JAR), manifest);

        try {
            addClassToJar(MavenDependencyResolver.class, jar_stream);
            addClassToJar(MavenDependencyResolver.FileCollector.class, jar_stream);
            addClassToJar(MavenDependencyResolver.DependencyNodeCollector.class, jar_stream);
            addClassToJar(MavenDependencyResolver.ServiceLocatorErrorHandler.class, jar_stream);
            addClassToJar(Bootstrap.class, jar_stream);
            addClassToJar(BootstrapConfiguration.class, jar_stream);
            addClassToJar(Duration.class, jar_stream);
            addClassToJar(URLUtils.class, jar_stream);
            addClassToJar(FileDeletionHook.class, jar_stream);
        }
        finally {
            jar_stream.flush();
            jar_stream.close();
        }
    }
 
开发者ID:stacs-srg,项目名称:shabdiz,代码行数:28,代码来源:Bootstrap.java

示例6: 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

示例7: 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

示例8: createJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void createJar(Manifest mf) throws Exception {
	mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
	JarOutputStream out = new JarOutputStream(storage.getOutputStream(), mf);
	out.flush();
	out.close();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:7,代码来源:ManifestUtilsTest.java

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