Java 8 JarOutputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JarOutputStream class.

This code example shows how to use the following methods:write, putNextEntry, close, closeEntry
    assertEquals("hello", IOUtils.toString(in));
  } 
   
  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;
  } 
   
} 
9
CodeRank
This code example shows how to use the following methods:putNextEntry, close, closeEntry
   * test dir. 
   */ 
  private void makeTestJar() throws IOException { 
    File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_NAME);
    JarOutputStream jstream =
        new JarOutputStream(new FileOutputStream(jarFile));
    jstream.putNextEntry(new ZipEntry("foobar.txt"));
    jstream.closeEntry();
    jstream.putNextEntry(new ZipEntry("foobaz.txt"));
    jstream.closeEntry();
    jstream.close();
  } 
 
  /** 
   * Test default unjarring behavior - unpack everything 
   */ 
  @Test 
  public void testUnJar() throws Exception { 
    File unjarDir = new File(TEST_ROOT_DIR, "unjar-all");
    assertFalse("unjar dir shouldn't exist at test start",
8
CodeRank
This code example shows how to use the following methods:write, putNextEntry, write, close
            manifest.write(manOut);
            byte[] manBytes = manOut.toByteArray();
            File file = File.createTempFile(
                    Support_PlatformFile.getNewPlatformFile("hyts_manifest1", 
                            ""), ".jar"); 
            JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(
                    file.getAbsolutePath()));
            ZipEntry entry = new ZipEntry("META-INF/");
            entry.setSize(0);
            jarOut.putNextEntry(entry);
            entry = new ZipEntry(JarFile.MANIFEST_NAME);
            entry.setSize(manBytes.length);
            jarOut.putNextEntry(entry);
            jarOut.write(manBytes);
            entry = new ZipEntry("myfile");
            entry.setSize(1);
            jarOut.putNextEntry(entry);
            jarOut.write(65);
            jarOut.close();
            JarFile jar = new JarFile(file.getAbsolutePath(), false);

7
CodeRank
This code example shows how to use the following methods:write, putNextEntry, close, closeEntry
  } 
 
  private Path makeJar(Path p, int index) throws FileNotFoundException,
      IOException { 
    FileOutputStream fos = new FileOutputStream(new File(p.toString()));
    JarOutputStream jos = new JarOutputStream(fos);
    ZipEntry ze = new ZipEntry("distributed.jar.inside" + index);
    jos.putNextEntry(ze);
    jos.write(("inside the jar!" + index).getBytes());
    jos.closeEntry();
    jos.close();
    return p;
  } 
} 
7
CodeRank
This code example shows how to use the following methods:
        String name = outFile.getName();
        String tzname = name.substring(name.lastIndexOf(".") + 1);
        JarOutputStream jos = null;
        try { 
            TimeZone.setDefault(TimeZone.getTimeZone(tzname));
            jos = new JarOutputStream(new FileOutputStream(outFile));
            System.out.println("Using timezone: " + TimeZone.getDefault());
            Utils.unpackj(packFile, jos);
        } finally { 
            Utils.close(jos);
            TimeZone.setDefault(tz); // always reset
        } 
    } 
 
    static void verifyJar(File f1, File f2) throws IOException {
        int errors = 0;
        JarFile jf1 = null;
        JarFile jf2 = null;
        try { 
            jf1 = new JarFile(f1);
7
CodeRank
This code example shows how to use the following methods:write, putNextEntry, close
        // play with relative file names - put relative path as ../<parent dir 
        // name>/xx.jar 
        att.put(Attributes.Name.CLASS_PATH, ".." + File.separator
                + barJar.getParentFile().getName() + File.separator
                + barJar.getName());
        joutFoo = new JarOutputStream(new FileOutputStream(fooJar), man);
        joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
        joutFoo.write(getResource(resources, "hyts_Foo.ser"));
        joutFoo.close();
        // execute the JAR and read the result 
        assertTrue("Error executing JAR",
                execAndGetOutput(builder).startsWith( "FOOBAR"));
    } 
 
    /** 
     * tests case when Main-Class is not in the jar launched but in another jar 
     * referenced by Class-Path 
     * 
     * @throws Exception in case of troubles 
     */ 
6
CodeRank
This code example shows how to use the following methods:write, putNextEntry, close
{ 
    public static void realMain(String args[]) throws Exception
    { 
        final File zf = File.createTempFile("deletetemp", ".jar");
        zf.deleteOnExit();
        JarOutputStream jos = new JarOutputStream(
                new FileOutputStream(zf));
        JarEntry je = new JarEntry("entry");
        jos.putNextEntry(je);
        jos.write("hello, world".getBytes("ASCII"));
        jos.close();
 
        HttpServer server = HttpServer.create(
                new InetSocketAddress((InetAddress) null, 0), 0);
        HttpContext context = server.createContext("/",
            new HttpHandler() { 
                public void handle(HttpExchange e) {
                try { 
                    FileInputStream fis = new FileInputStream(zf);
                    e.sendResponseHeaders(200, zf.length());
6
CodeRank
This code example shows how to use the following methods:close
				zos = new JarOutputStream(fos, manifest);
			} 
			else 
			{ 
				fos = new FileOutputStream(tofp);
				zos = new JarOutputStream(fos);
			} 
 
			File[] files = fromfp.listFiles();
			generic.FileUtils.writeInJar(zos, files, "", true);
			zos.close();
			System.out.println("Build a JAR: " + jarfilepath);
		} 
		catch (Exception e)
		{ 
			Utils.log("Something wrong: ", e);
		} 
	} 
 
	public void run() 
6
CodeRank
This code example shows how to use the following methods:putNextEntry, close, closeEntry
   * test dir. 
   */ 
  private void makeTestJar() throws IOException {
    File jarFile = new File(TEST_ROOT_DIR, TEST_JAR_NAME);
    JarOutputStream jstream =
        new JarOutputStream(new FileOutputStream(jarFile));
    jstream.putNextEntry(new ZipEntry("foobar.txt"));
    jstream.closeEntry();
    jstream.putNextEntry(new ZipEntry("foobaz.txt"));
    jstream.closeEntry();
    jstream.close();
  } 
 
  /** 
   * Test default unjarring behavior - unpack everything 
   */ 
  @Test
  public void testUnJar() throws Exception {
    File unjarDir = new File(TEST_ROOT_DIR, "unjar-all");
    assertFalse("unjar dir shouldn't exist at test start",
7
CodeRank
This code example shows how to use the following methods:putNextEntry, close, closeEntry
    } 
 
    @Test
    public void testJar() throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JarOutputStream jos = new JarOutputStream(baos);
        jos.putNextEntry(new JarEntry("dummy"));
        jos.closeEntry();
        jos.close();
        InputStream in = new ByteArrayInputStream(baos.toByteArray());
        FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy");
        assertSame(JarAnalyzer.class, fa.getClass());
    } 
 
    @Test
    public void testPlainText() throws IOException {
        ByteArrayInputStream in = new ByteArrayInputStream(
                "This is a plain text file.".getBytes("US-ASCII"));
        assertSame(PlainAnalyzer.class, 
                   AnalyzerGuru.getAnalyzer(in, "dummy").getClass());
7
CodeRank

Related Java 8 JarOutputStream Questions & Answers:

See Code Examples for Java 8 JarOutputStream Methods: