Package de.schlichtherle.util.zip

Examples of de.schlichtherle.util.zip.ZipEntry


        } else {
            Pattern pattern = Pattern.compile(".*\\.mc[ra]$");
            // World pattern
            Pattern worldPattern = Pattern.compile(worldName + "\\$");
            for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
                ZipEntry testEntry = e.nextElement();
                // Check for world
                if (worldPattern.matcher(worldName).matches()) {
                    // Check for file
                    if (pattern.matcher(testEntry.getName()).matches()) {
                        folder = testEntry.getName().substring(0, testEntry.getName().lastIndexOf("/"));
                        name = folder + "/" + name;
                        break;
                    }
                }
            }

            // Check if world is found
            if (folder == null) {
                throw new MissingWorldException("Target world is not present in ZIP.", worldName);
            }
        }

        ZipEntry entry = getEntry(name);
        if (entry == null) {
            throw new MissingChunkException();
        }
        try {
            return zip.getInputStream(entry);
View Full Code Here


     *
     * @param file the file
     * @return an entry
     */
    private ZipEntry getEntry(String file) {
        ZipEntry entry = zip.getEntry(file);
        if (entry != null) {
            return entry;
        }
        return zip.getEntry(file.replace("/", "\\"));
    }
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public boolean isValid() {
        for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {

            ZipEntry testEntry = e.nextElement();

            if (testEntry.getName().matches(".*\\.mcr$") || testEntry.getName().matches(".*\\.mca$")) { // TODO: does this need a separate class?
                return true;
            }
        }

        return false;
View Full Code Here

        if (folder != null) {
            if (!folder.equals("")) {
                file = folder + "/" + file;
            }
        } else {
            ZipEntry testEntry = zip.getEntry("level.dat");

            // So, the data is not in the root directory
            if (testEntry == null) {
                // Let's try a world/ sub-directory
                testEntry = getEntry("world/level.dat");

                Pattern pattern = Pattern.compile(".*[\\\\/]level\\.dat$");

                // So not there either...
                if (testEntry == null) {
                    for (Enumeration<? extends ZipEntry> e = zip.entries(); e.hasMoreElements(); ) {
                        testEntry = e.nextElement();

                        // Whoo, found level.dat!
                        if (pattern.matcher(testEntry.getName()).matches()) {
                            folder = testEntry.getName().replaceAll("level\\.dat$", "");
                            folder = folder.substring(0, folder.length() - 1);
                            file = folder + file;
                            break;
                        }
                    }
                } else {
                    file = "world/" + file;
                }
            }
        }

        ZipEntry entry = getEntry(file);
        if (entry == null) {
            throw new MissingChunkException();
        }
        try {
            return zip.getInputStream(entry);
View Full Code Here

     *
     * @param file the file
     * @return an entry
     */
    private ZipEntry getEntry(String file) {
        ZipEntry entry = zip.getEntry(file);
        if (entry != null) {
            return entry;
        }
        return zip.getEntry(file.replace("/", "\\"));
    }
View Full Code Here

          }
      } else if (filter == null || filter.evaluate(fo.toString())) {
        //Adding a file
        int readed = -1;
        byte bytes [] = new byte[1024];
        ZipEntry entry = new ZipEntry(intoZipFolder + FSHelper.getCanonicalName(fo));
        zop.putNextEntry(entry);
       
        InputStream is = null;
        try {
          ZipEntry zipEntryOut = new ZipEntry(entry.getName());
          zop.putNextEntry(zipEntryOut);
          is = fo.getContent().getInputStream();
          while((readed = is.read(bytes)) > 0) {
            zop.write(bytes, 0, readed);
          }
View Full Code Here

      int prefixLength = prefix.length();
        FileOutputStream fos = null;
        Enumeration entries = zip.entries();
        try {
          while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            if(entry.getName().startsWith(prefix)) {
              InputStream is = null;
              try {
                is = zip.getInputStream(entry, true);
                //if prefixLength == 0 the prefix doesn't design any folder so we do not need to substring the entry name.
                File file = new File(dest + "/" + entry.getName().substring((prefixLength==0)?0:prefixLength+1));
                if (! entry.isDirectory()) {
                  IOHelper.copy(is, file);
                } else {
                  file.mkdirs();
                }
              } catch (Exception e) {
View Full Code Here

        long total = 0;
        ZipFile zip = new ZipFile(zipFile);
        Enumeration entries = zip.entries();
        try {
            while (entries.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                total += entry.getSize();
            }
        } finally {
            zip.close();
        }
        return total;
View Full Code Here

     * @param zop
     * @throws FileNotFoundException
     * @throws IOException
     */
    private void writeDescriptor(String xmlDescriptor, ZipOutputStream zop) throws FileNotFoundException, IOException {
        ZipEntry zipEntry = new ZipEntry(Parameters.MODULE_DESCRIPTOR_FILE_NAME);
        zop.putNextEntry(zipEntry);
        zop.write(xmlDescriptor.getBytes());
        zop.closeEntry();
    }
View Full Code Here

        byte bytes [] = new byte[1024];
        ZipFile zip = new ZipFile(src);
        Enumeration entries = zip.entries();
        try {
          while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            if(entry.getName().startsWith(prefixToRemove)) {
              InputStream is = null;
              try {
                String newName = entry.getName().substring(prefixToRemove.length());
                if(newName.startsWith("/")) { //$NON-NLS-1$
                  newName = newName.substring(1);
                }
                ZipEntry zipEntryOut = new ZipEntry(prefixToAdd + newName);
                zop.putNextEntry(zipEntryOut);
                is = zip.getInputStream(entry, true);
                while((readed = is.read(bytes)) > 0) {
                  zop.write(bytes, 0, readed);
                }
View Full Code Here

TOP

Related Classes of de.schlichtherle.util.zip.ZipEntry

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.