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


Java JarOutputStream.close方法代码示例

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


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

示例1: 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,代码来源:FreeformProjectGeneratorTest.java

示例2: makeClassLoaderTestJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File makeClassLoaderTestJar(String... clsNames) throws IOException {
  File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_2_NAME);
  JarOutputStream jstream =
      new JarOutputStream(new FileOutputStream(jarFile));
  for (String clsName: clsNames) {
    String name = clsName.replace('.', '/') + ".class";
    InputStream entryInputStream = this.getClass().getResourceAsStream(
        "/" + name);
    ZipEntry entry = new ZipEntry(name);
    jstream.putNextEntry(entry);
    BufferedInputStream bufInputStream = new BufferedInputStream(
        entryInputStream, 2048);
    int count;
    byte[] data = new byte[2048];
    while ((count = bufInputStream.read(data, 0, 2048)) != -1) {
      jstream.write(data, 0, count);
    }
    jstream.closeEntry();
  }
  jstream.close();

  return jarFile;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestRunJar.java

示例3: copyJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File copyJar(File file, String manifest) throws IOException {
    File ret = File.createTempFile(file.getName(), "2ndcopy", file.getParentFile());
    JarFile jar = new JarFile(file);
    JarOutputStream os = new JarOutputStream(new FileOutputStream(ret), new Manifest(
        new ByteArrayInputStream(manifest.getBytes())
    ));
    Enumeration<JarEntry> en = jar.entries();
    while (en.hasMoreElements()) {
        JarEntry elem = en.nextElement();
        if (elem.getName().equals("META-INF/MANIFEST.MF")) {
            continue;
        }
        os.putNextEntry(elem);
        InputStream is = jar.getInputStream(elem);
        copyStreams(is, os);
        is.close();
    }
    os.close();
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ModuleManagerTest.java

示例4: testHandleSpaceInPathAsProducedByEclipse

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void testHandleSpaceInPathAsProducedByEclipse() throws Exception {
    File d = new File(getWorkDir(), "space in path");
    d.mkdirs();
    File f = new File(d, "x.jar");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f));
    os.putNextEntry(new JarEntry("test.txt"));
    os.write(10);
    os.close();
    
    URL u = new URL("jar:" + f.toURL() + "!/test.txt");
    DataInputStream is = new DataInputStream(u.openStream());
    byte[] arr = new byte[100];
    is.readFully(arr, 0, 1);
    assertEquals("One byte", 10, arr[0]);
    is.close();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ProxyURLStreamHandlerFactoryTest.java

示例5: createJarArchive

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public static void createJarArchive(JavaProjectFolder projectFolder) throws IOException {
    //input file
    File dirBuildClasses = projectFolder.getDirBuildClasses();
    File archiveFile = projectFolder.getOutJarArchive();


    // Open archive file
    FileOutputStream stream = new FileOutputStream(archiveFile);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");

    //Create the jar file
    JarOutputStream out = new JarOutputStream(stream, manifest);

    //Add the files..
    if (dirBuildClasses.listFiles() != null) {
        for (File file : dirBuildClasses.listFiles()) {
            addzz(dirBuildClasses.getPath(), file, out);
        }
    }

    out.close();
    stream.close();
    System.out.println("Adding completed OK");
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:26,代码来源:Jar.java

示例6: writeIndexJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void writeIndexJar() throws IOException, XmlPullParserException, LocalRepoKeyStore.InitException {
    BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned));
    JarOutputStream jo = new JarOutputStream(bo);
    JarEntry je = new JarEntry("index.xml");
    jo.putNextEntry(je);
    new IndexXmlBuilder().build(context, apps, jo);
    jo.close();
    bo.close();

    try {
        LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar);
    } catch (LocalRepoKeyStore.InitException e) {
        throw new IOException("Could not sign index - keystore failed to initialize");
    } finally {
        attemptToDelete(xmlIndexJarUnsigned);
    }

}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:19,代码来源:LocalRepoManager.java

示例7: write

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
@Override
public void write(File file) throws IOException {
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
    try {
        for (Iterator<ClassNode> itr = iterator(); itr.hasNext(); ) {
            ClassNode   node   = itr.next();
            ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
            node.accept(new CheckClassAdapter(writer, true));
            byte[] bytes = writer.toByteArray();
            jos.putNextEntry(new JarEntry(node.name.concat(".class")));
            jos.write(bytes);
        }
    } finally {
        jos.close();
    }
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:17,代码来源:JarArchive.java

示例8: assertEnableModule

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private void assertEnableModule(String req, boolean enable) throws Exception {
    Manifest man = new Manifest ();
    man.getMainAttributes ().putValue ("Manifest-Version", "1.0");
    man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.PlatformDependency/1");
    man.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-");
    
    man.getMainAttributes ().putValue ("OpenIDE-Module-Requires", req);
    
    JarOutputStream os = new JarOutputStream (new FileOutputStream (moduleJarFile), man);
    os.putNextEntry (new JarEntry ("empty/test.txt"));
    os.close ();
    
    final MockEvents ev = new MockEvents();
    NbInstaller installer = new NbInstaller(ev);
    ModuleManager mgr = new ModuleManager(installer, ev);
    ModuleFormatSatisfiedTest.addOpenideModules(mgr);
    installer.registerManager(mgr);
    mgr.mutexPrivileged().enterWriteAccess();
    try {
        Module m1 = mgr.create(moduleJarFile, null, false, false, false);
        if (enable) {
            assertEquals(Collections.EMPTY_SET, m1.getProblems());
            mgr.enable(m1);
            mgr.disable(m1);
        } else {
            assertFalse("We should not be able to enable the module", m1.getProblems().isEmpty());
        }
        mgr.delete(m1);
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:PlatformDependencySatisfiedTest.java

示例9: createJAR

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
static void createJAR(File cluster, String moduleName, Class metaInfHandler) 
    throws IOException {
        File xml = new File(new File(new File(cluster, "config"), "Modules"), moduleName + ".xml");
        File jar = new File(new File(cluster, "modules"), moduleName + ".jar");
        
        xml.getParentFile().mkdirs();
        jar.getParentFile().mkdirs();
        
        
        Manifest mf = new Manifest();
        mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
        mf.getMainAttributes().putValue("OpenIDE-Module", moduleName.replace('-', '.'));
        mf.getMainAttributes().putValue("OpenIDE-Module-Public-Packages", "-");
        
        JarOutputStream os = new JarOutputStream(new FileOutputStream(jar), mf);
        os.putNextEntry(new JarEntry("META-INF/services/org.netbeans.CLIHandler"));
        os.write(metaInfHandler.getName().getBytes());
        os.close();
        
        FileWriter w = new FileWriter(xml);
        w.write(            
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!DOCTYPE module PUBLIC \"-//NetBeans//DTD Module Status 1.0//EN\"\n" +
"                        \"http://www.netbeans.org/dtds/module-status-1_0.dtd\">\n" +
"<module name=\"" + moduleName.replace('-', '.') + "\">\n" +
"    <param name=\"autoload\">false</param>\n" +
"    <param name=\"eager\">false</param>\n" +
"    <param name=\"enabled\">true</param>\n" +
"    <param name=\"jar\">modules/" + moduleName + ".jar</param>\n" +
"    <param name=\"release\">2</param>\n" +
"    <param name=\"reloadable\">false</param>\n" +
"    <param name=\"specversion\">3.4.0.1</param>\n" +
"</module>\n");
        w.close();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:CLILookupHelpNoDirTest.java

示例10: makeTestJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
private File makeTestJar() throws IOException {
  File jarFile = new File(testDir, "test.jar");
  JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
  ZipEntry entry = new ZipEntry("resource.txt");
  out.putNextEntry(entry);
  out.write("hello".getBytes());
  out.closeEntry();
  out.close();
  return jarFile;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:11,代码来源:TestApplicationClassLoader.java

示例11: outputToJar

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/**
 * Generate output JAR-file and packages
 */
public void outputToJar() throws IOException {
    // create the manifest
    final Manifest manifest = new Manifest();
    final java.util.jar.Attributes atrs = manifest.getMainAttributes();
    atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.2");

    final Map<String, Attributes> map = manifest.getEntries();
    // create manifest
    final String now = (new Date()).toString();
    final java.util.jar.Attributes.Name dateAttr =
        new java.util.jar.Attributes.Name("Date");

    final File jarFile = new File(_destDir, _jarFileName);
    final JarOutputStream jos =
        new JarOutputStream(new FileOutputStream(jarFile), manifest);

    for (JavaClass clazz : _bcelClasses) {
        final String className = clazz.getClassName().replace('.', '/');
        final java.util.jar.Attributes attr = new java.util.jar.Attributes();
        attr.put(dateAttr, now);
        map.put(className + ".class", attr);
        jos.putNextEntry(new JarEntry(className + ".class"));
        final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
        clazz.dump(out); // dump() closes it's output stream
        out.writeTo(jos);
    }
    jos.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:XSLTC.java

示例12: unpackInternally

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
@SuppressWarnings("CallToThreadDumpStack")
public static boolean unpackInternally(final File source,
        final File target) throws IOException {
    try {
        JarOutputStream os = new JarOutputStream(new FileOutputStream(target));
        unpacker.unpack(source, os);
        os.close();
        target.setLastModified(source.lastModified());
    } catch (IOException exc) {
        exc.printStackTrace();
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:Utils.java

示例13: fakeBundle

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
/** Creates a fake bundle definition that represents one NetBeans module
 *
 * @param m the module
 * @return the stream to read the definition from or null, if it does not
 *   make sense to represent this module as bundle
 */
private static InputStream fakeBundle(Module m) throws IOException {
    String netigsoExp = (String) m.getAttribute("Netigso-Export-Package"); // NOI18N
    String exp = (String) m.getAttribute("OpenIDE-Module-Public-Packages"); // NOI18N
    if (netigsoExp == null) {
        if ("-".equals(exp) || m.getAttribute("OpenIDE-Module-Friends") != null) { // NOI18N
            return null;
        }
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Manifest man = new Manifest();
    man.getMainAttributes().putValue("Manifest-Version", "1.0"); // workaround for JDK bug
    man.getMainAttributes().putValue("Bundle-ManifestVersion", "2"); // NOI18N
    man.getMainAttributes().putValue("Bundle-SymbolicName", m.getCodeNameBase()); // NOI18N

    if (m.getSpecificationVersion() != null) {
        String spec = threeDotsWithMajor(m.getSpecificationVersion().toString(), m.getCodeName());
        man.getMainAttributes().putValue("Bundle-Version", spec.toString()); // NOI18N
    }
    if (netigsoExp != null) {
        man.getMainAttributes().putValue("Export-Package", netigsoExp); // NOI18N
    } else if (exp != null) {
        man.getMainAttributes().putValue("Export-Package", substitutePkg(m)); // NOI18N
    } else {
        man.getMainAttributes().putValue("Export-Package", m.getCodeNameBase()); // NOI18N
    }        
    JarOutputStream jos = new JarOutputStream(os, man);
    jos.close();
    return new ByteArrayInputStream(os.toByteArray());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:Netigso.java

示例14: testLazyOpen

import java.util.jar.JarOutputStream; //导入方法依赖的package包/类
public void testLazyOpen() throws Exception {
    File f = new File(getWorkDir(), "ok.jar");
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(f));
    jos.putNextEntry(new JarEntry("one"));
    jos.putNextEntry(new JarEntry("two.txt"));
    jos.putNextEntry(new JarEntry("3.txt"));
    jos.close();

    CharSequence log = Log.enable(JarFileSystem.class.getName(), Level.FINE);
    JarFileSystem fs = new JarFileSystem(f);
    final String match = "opened: " + f.getAbsolutePath();
    if (log.toString().contains(match)) {
        fail("The file " + f + " shall not be opened when fs created:\n" + log);
    }

    URL u = fs.getRoot().toURL();
    assertNotNull("URL is OK", u);
    if (!u.toExternalForm().startsWith("jar:file") || !u.toExternalForm().endsWith("ok.jar!/")) {
        fail("Unexpected URL: " + u);
    }
    if (log.toString().contains(match)) {
        fail("The file " + f + " shall not be opened yet:\n" + log);
    }
    assertEquals("Three files", 3, fs.getRoot().getChildren().length);
    if (!log.toString().contains(match)) {
        fail("The file " + f + " shall be opened now:\n" + log);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:JarFileSystemHidden.java

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


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