Package java.util.zip

Examples of java.util.zip.ZipOutputStream


 
  public static void editLauncher() {
    try {
      System.out.println(hackedFile.toString());
      ZipInputStream in = new ZipInputStream(new FileInputStream(normalLauncherFilename));
      ZipOutputStream out = new ZipOutputStream(new FileOutputStream(hackedFile));
      ZipEntry entry;
      String n;
      InputStream dataSource;
      while((entry = in.getNextEntry()) != null) {
        n = entry.getName();
        if(n.contains(".svn")
            || n.equals("META-INF/MOJANG_C.SF")
            || n.equals("META-INF/MOJANG_C.DSA")
            || n.equals("net/minecraft/minecraft.key")
            || n.equals("net/minecraft/Util$OS.class")) continue;
       
        out.putNextEntry(entry);
        if(n.equals("META-INF/MANIFEST.MF")) dataSource = new ByteArrayInputStream(MANIFEST_TEXT.getBytes());
        else if(n.equals("net/minecraft/Util.class")) dataSource = Resources.load("net/minecraft/Util.class");
        else dataSource = in;
        Streams.pipeStreams(dataSource, out);
        out.flush();
      }
      in.close();
      out.close();
    } catch(Exception e) {
      System.out.println("Editing launcher failed:");
      e.printStackTrace();
    }
  }
View Full Code Here


            }
        }
    }

    private void store(File source, File target) throws IOException {
        ZipOutputStream output = null;
        try {
            File[] children = source.listFiles();
            output = new ZipOutputStream(new FileOutputStream(target));
            for (int i = 0; i < children.length; i++) {
                storeRecursive(source, new File(children[i].getName()), output);
            }
        }
        finally {
View Full Code Here

        File tmpZip = null;
        try
        {
            tmpZip = File.createTempFile("felix.test", ".zip");
            tmpZip.deleteOnExit();
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tmpZip));
            ZipEntry ze = new ZipEntry(ENTRY_NAME);
            zos.putNextEntry(ze);
            zos.write(contentBytes, 0, contentBytes.length);
            zos.close();
        }
        catch (IOException ex)
        {
            fail("Unable to create temporary zip file: " + ex);
        }
View Full Code Here

            OutputStream out = response.getOutputStream();

            if (compress)
            {
                ZipOutputStream zip = new ZipOutputStream(out);
                zip.setLevel(Deflater.BEST_SPEED);

                ZipEntry entry = new ZipEntry(dumpFile.getName());
                entry.setTime(dumpFile.lastModified());
                entry.setMethod(ZipEntry.DEFLATED);

                zip.putNextEntry(entry);

                out = zip;

                // zip output with unknown length
                response.setContentType("application/zip");
View Full Code Here

    @Override
    public OutputStream getOutputStream() throws IOException {
        File parentFile = file.getAbsoluteFile().getParentFile();
        if (parentFile.exists() || parentFile.mkdirs()) {
            ZipOutputStream os = new ZipOutputStream(new BufferedOutputStream(
                    new FileOutputStream(file)));
            os.putNextEntry(new ZipEntry("ontology.txt"));
            return os;
        } else {
            throw new IOException("Could not create directories: " + parentFile);
        }
    }
View Full Code Here

    public static void copyZipWithoutEmptyDirectories(final File inputFile, final File outputFile) throws IOException
    {
        final byte[] buf = new byte[0x2000];

        final ZipFile inputZip = new ZipFile(inputFile);
        final ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(outputFile));
        try
        {
            // read a the entries of the input zip file and sort them
            final Enumeration<? extends ZipEntry> e = inputZip.entries();
            final ArrayList<ZipEntry> sortedList = new ArrayList<ZipEntry>();
            while (e.hasMoreElements()) {
                final ZipEntry entry = e.nextElement();
                sortedList.add(entry);
            }

            Collections.sort(sortedList, new Comparator<ZipEntry>()
            {
                public int compare(ZipEntry o1, ZipEntry o2)
                {
                    String n1 = o1.getName(), n2 = o2.getName();
                    if (metaOverride(n1, n2)) {
                        return -1;
                    }
                    if (metaOverride(n2, n1)) {
                        return 1;
                    }
                    return n1.compareTo(n2);
                }

                // make sure that META-INF/MANIFEST.MF is always the first entry after META-INF/
                private boolean metaOverride(String n1, String n2) {
                    return (n1.startsWith("META-INF/") && !n2.startsWith("META-INF/"))
                        || (n1.equals("META-INF/MANIFEST.MF") && !n2.equals(n1) && !n2.equals("META-INF/"))
                        || (n1.equals("META-INF/") && !n2.equals(n1));
                }
            });

            // treat them again and write them in output, wenn they not are empty directories
            for (int i = sortedList.size()-1; i>=0; i--)
            {
                final ZipEntry inputEntry = sortedList.get(i);
                final String name = inputEntry.getName();
                final boolean isEmptyDirectory;
                if (inputEntry.isDirectory())
                {
                    if (i == sortedList.size()-1)
                    {
                        // no item afterwards; it was an empty directory
                        isEmptyDirectory = true;
                    }
                    else
                    {
                        final String nextName = sortedList.get(i+1).getName();
                        isEmptyDirectory  = !nextName.startsWith(name);
                    }
                }
                else
                {
                    isEmptyDirectory = false;
                }

                if (isEmptyDirectory)
                {
                    sortedList.remove(i);
                }
            }

            // finally write entries in normal order
            for (int i = 0; i < sortedList.size(); i++)
            {
                final ZipEntry inputEntry = sortedList.get(i);
                final ZipEntry outputEntry = new ZipEntry(inputEntry);
                outputStream.putNextEntry(outputEntry);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final InputStream is = inputZip.getInputStream(inputEntry);
                IoUtil.pipe(is, baos, buf);
                is.close();
                outputStream.write(baos.toByteArray());
            }
        } finally {
            outputStream.close();
            inputZip.close();
        }

    }
View Full Code Here

    }

    private static boolean zipObject(String sourcePath, String target)
    {
        FileOutputStream fos = null;
        ZipOutputStream cpZipOutputStream = null;
       
        try
        {
            File cpFile = new File(sourcePath);
            if (!cpFile.isDirectory())
            {
                return false;
            }
            fos = new FileOutputStream(target);
            cpZipOutputStream = new ZipOutputStream(fos);
            cpZipOutputStream.setLevel(9);
            zipFiles(cpFile, sourcePath, cpZipOutputStream);
            cpZipOutputStream.finish();
        }
        catch (Exception e)
        {
            logger.error("Unexpected exception during writing to zip output stream.", e);
            return false;
        }
        finally
        {
            if (cpZipOutputStream != null)
            {
                try
                {
                    cpZipOutputStream.close();
                }
                catch (Exception ce)
                {
                }
            }
View Full Code Here

            throw new RuntimeException( e );
        }
    }

    private void zip(OutputStream outputStream) {
        ZipOutputStream out = null;
        try {
            out = new ZipOutputStream( outputStream );

            writeJarEntries( getRootFolder(),
                             out );
            out.close();
        } catch ( IOException e ) {
            throw new RuntimeException( e );
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch ( IOException e ) {
            }
        }
    }
View Full Code Here

    Set<String> contents = new HashSet<String>();
    contents.add(base + "bar/woo/");
    contents.add(base + "bar/file");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    IOUtils.zipDir(dir, base, zos);
    ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(baos.toByteArray()));
    Set<String> zipContents = new HashSet<String>();
    ZipEntry entry = zis.getNextEntry();
    while (entry != null) {
View Full Code Here

  /**
   * Zips up a directory.
   */
  private void zipDirectory(String zipFile, String dirToZip) {
    File directory = new File(dirToZip);
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(zipFile))) {
      addDirectoryToZip(directory, directory, stream);
    } catch (Exception e) {
      throw new PlatformManagerException("Failed to zip module", e);
    }
  }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.