Java 8 ZipOutputStream - 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 ZipOutputStream 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:close, closeEntry, finish, putNextEntry, write
	} 
 
	public static byte[] zipByteArray(byte[] input, String zipEntryName) {
		try { 
			ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
			ZipOutputStream out = new ZipOutputStream(bos);
 
			out.putNextEntry(new ZipEntry(zipEntryName));
			out.write(input, 0, input.length);
			out.closeEntry();
			 
			out.finish();
			out.close();
 
			byte[] compressedData = bos.toByteArray();
			return compressedData;
		} 
		catch (IOException e) {
			log.error("Caught exception zipping byte array: " + e, e);
			return null; 
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:closeEntry, putNextEntry
 
    private static void addFileToZip(File file, String parent, ZipOutputStream zos) throws IOException {
        final FileInputStream is = new FileInputStream(file);
        try { 
            final String entryName = parent == null ? file.getName() : parent + "/" + file.getName();
            zos.putNextEntry(new ZipEntry(entryName));
 
            final BufferedInputStream bis = new BufferedInputStream(is);
            try { 
                copyStream(bis, zos);
            } finally { 
                safeClose(bis);
            } 
 
            zos.closeEntry();
        } finally { 
            safeClose(is);
        } 
    } 
 
7
CodeRank
This code example shows how to use the following methods:write, finish, putNextEntry
    private static void writeZippedKML( 
            String namePfx, String formatExtension,
            byte[] overlay, Resource data, OutputStream out) 
    throws IOException { 
 
        ZipOutputStream zipos = new ZipOutputStream(out);
        // High compression 
        //zipos.setLevel(9); 
 
        // Add the overlay, links to the next content 
        ZipEntry zeOl = new ZipEntry("netlinks_"+namePfx + ".kml");
        zipos.putNextEntry(zeOl);
        zipos.write(overlay);
 
        // Add the actual data, if applicable 
        if(data != null) {
            ZipEntry zeData = new ZipEntry("data_" + namePfx+"."+formatExtension);
            zipos.putNextEntry(zeData);
            WritableByteChannel outch = Channels.newChannel(zipos);
            data.transferTo(outch);

7
CodeRank
This code example shows how to use the following methods:close, closeEntry, finish, putNextEntry, write
        is.close();
        conn.setDefaultUseCaches(false);
        File jar = File.createTempFile("B7050028", ".jar");
        jar.deleteOnExit();
        OutputStream os = new FileOutputStream(jar);
        ZipOutputStream zos = new ZipOutputStream(os);
        ZipEntry ze = new ZipEntry("B7050028.class");
        ze.setMethod(ZipEntry.STORED);
        ze.setSize(len);
        CRC32 crc = new CRC32();
        crc.update(data);
        ze.setCrc(crc.getValue());
        zos.putNextEntry(ze);
        zos.write(data, 0, len);
        zos.closeEntry();
        zos.finish();
        zos.close();
        os.close();
        System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
    } 

7
CodeRank
This code example shows how to use the following methods:close
                JetTestUtils.compileJavaFiles(javaFiles, options);
            } 
 
            File jarFile = new File(contentDir, jarName + ".jar");
 
            ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(jarFile));
            ZipUtil.addDirToZipRecursively(zip, jarFile, classesDir, "", null, null);
            if (addSources) {
                ZipUtil.addDirToZipRecursively(zip, jarFile, new File(sourcesPath), "src", null, null);
            } 
            zip.close();
 
            return jarFile;
        } 
        catch (IOException e) {
            throw UtilsPackage.rethrow(e);
        } 
    } 
 
    // Runs compiler in custom class loader to avoid effects caused by replacing Application with another one created in compiler. 
7
CodeRank
This code example shows how to use the following methods:closeEntry, putNextEntry
    m_destination = destination;
 
    // if a directory is specified then use gzip format, otherwise 
    // use zip 
    if (!m_destination.isDirectory()) {
      m_zs = new ZipOutputStream(new FileOutputStream(m_destination));
      m_zipOut = new DataOutputStream(m_zs);
    }     
  } 
 
  /** 
   * Saves a string to either an individual gzipped file or as 
   * an entry in a zip file. 
   *  
   * @param outString the output string to save 
   * @param name the name of the file/entry to save it to 
   * @throws Exception if something goes wrong 
   */ 
  public void zipit(String outString, String name) throws Exception {
    File saveFile;

7
CodeRank
This code example shows how to use the following methods:close, closeEntry, finish, putNextEntry, write
	} 
 
	public static byte[] zipByteArray(byte[] input, String zipEntryName) {
		try { 
			ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
			ZipOutputStream out = new ZipOutputStream(bos);
 
			out.putNextEntry(new ZipEntry(zipEntryName));
			out.write(input, 0, input.length);
			out.closeEntry();
			 
			out.finish();
			out.close();
 
			byte[] compressedData = bos.toByteArray();
			return compressedData;
		} 
		catch (IOException e) {
			log.error("Caught exception zipping byte array: " + e, e);
			return null; 
7
CodeRank

Related Java 8 ZipOutputStream Questions & Answers:

See Code Examples for Java 8 ZipOutputStream Methods: