Package org.apache.tools.zip

Examples of org.apache.tools.zip.ZipEntry


        log("adding directory " + vPath, Project.MSG_VERBOSE);
        addedDirs.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry (vPath);
            if (dir != null && dir.exists()) {
                // ZIPs store time with a granularity of 2 seconds, round up
                ze.setTime(dir.lastModified() + 1999);
            } else {
                // ZIPs store time with a granularity of 2 seconds, round up
                ze.setTime(System.currentTimeMillis() + 1999);
            }
            ze.setSize (0);
            ze.setMethod (ZipEntry.STORED);
            // This is faintly ridiculous:
            ze.setCrc (EMPTY_CRC);
            ze.setUnixMode(mode);

            zOut.putNextEntry (ze);
        }
    }
View Full Code Here


        }

        entries.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry(vPath);
            ze.setTime(lastModified);
            ze.setMethod(doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED);

            /*
            * ZipOutputStream.putNextEntry expects the ZipEntry to
            * know its size and the CRC sum before you start writing
            * the data when using STORED mode - unless it is seekable.
            *
            * This forces us to process the data twice.
            */
            if (!zOut.isSeekable() && !doCompress) {
                long size = 0;
                CRC32 cal = new CRC32();
                if (!in.markSupported()) {
                    // Store data into a byte[]
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                    byte[] buffer = new byte[8 * 1024];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        bos.write(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in = new ByteArrayInputStream(bos.toByteArray());

                } else {
                    in.mark(Integer.MAX_VALUE);
                    byte[] buffer = new byte[8 * 1024];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in.reset();
                }
                ze.setSize(size);
                ze.setCrc(cal.getValue());
            }

            ze.setUnixMode(mode);
            zOut.putNextEntry(ze);

            byte[] buffer = new byte[8 * 1024];
            int count = 0;
            do {
View Full Code Here

            && lastScannedResource.getLastModified()
            == thisresource.getLastModified()) {
            return;
        }

        ZipEntry entry = null;
        ZipFile zf = null;
        myentries = new Hashtable();
        try {
            try {
                zf = new ZipFile(srcFile, encoding);
            } catch (ZipException ex) {
                throw new BuildException("problem reading " + srcFile, ex);
            } catch (IOException ex) {
                throw new BuildException("problem opening " + srcFile, ex);
            }

            Enumeration e = zf.getEntries();
            while (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
                myentries.put(new String(entry.getName()),
                              new Resource(entry.getName(), true,
                                           entry.getTime(),
                                           entry.isDirectory()));
            }
        } finally {
            if (zf != null) {
                try {
                    zf.close();
View Full Code Here

        ZipFile zf = null;
        try {
            zf = new ZipFile(srcF, encoding);
            Enumeration e = zf.getEntries();
            while (e.hasMoreElements()) {
                ZipEntry ze = (ZipEntry) e.nextElement();
                extractFile(fileUtils, srcF, dir, zf.getInputStream(ze),
                            ze.getName(), new Date(ze.getTime()),
                            ze.isDirectory());
            }

            log("expand complete", Project.MSG_VERBOSE);
        } catch (IOException ioe) {
            throw new BuildException("Error while expanding " + srcF.getPath(),
View Full Code Here

        }
    }
   
    private void insert() throws IOException {
        ZipOutputStream zout = null;
        ZipEntry entry;
        InputStream in;
       
        try {
            zout = new ZipOutputStream(archive);
            for (File file : files) {
                in = null;
                entry = createEntry(file);
                out(String.format(fmt_extract, str_adding, entry.getName()));
                try {
                    if (!file.isDirectory()) {
                        if ((in = openFileRead(file)) == null) {
                            continue;
                        }
View Full Code Here

     * If the -j option is given, then only the file name is stored,
     * not its full pathname. Conflicts are dealt with in parseFiles()
     */
    private ZipEntry createEntry(File file) {
        String name = file.getPath();
        ZipEntry entry;
        if (file.isDirectory()) {
            if (!name.endsWith(File.separator)) {
                name = name + File.separator;
            }
            entry = new ZipEntry(name);
            entry.setMethod(ZipEntry.STORED);
        } else {
            if (noPath) {
                name = file.getName();
            }
            entry = new ZipEntry(name);
            entry.setMethod(ZipEntry.DEFLATED);
            if (noCompress != null && noCompress.length > 0) {
                for (String suf : noCompress) {
                    if (name.endsWith(suf)) {
                        entry.setMethod(ZipEntry.STORED);
                        break;
                    }
                }
            }
        }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    private void parseEntries() {
        int count = 0;
       
        ZipEntry entry;
        Enumeration<ZipEntry> entries = zarchive.getEntries();
        fileEntries = new ArrayList<ZipEntry>();
        dirEntries = new ArrayList<ZipEntry>();
       
        while (entries.hasMoreElements()) {
            count++;
            entry = entries.nextElement();
            if (entry.isDirectory()) {
                dirEntries.add(entry);
            } else {
                fileEntries.add(entry);
            }
        }
View Full Code Here

        InputStream is = null;
        if (fromName.toLowerCase().endsWith(".fb2")) {
            is = new FileInputStream(new File(fromName));
        } else if (fromName.toLowerCase().endsWith(".zip")) {
            ZipFile fromZip = new ZipFile(fromName);
            ZipEntry entry = (ZipEntry) fromZip.getEntries().nextElement();
            if (entry.getName().toLowerCase().endsWith(".fb2")) {
                is = fromZip.getInputStream(entry);
            } else {
                System.err.println("First archive entry " + entry.getName() + " is not an FB2 file.");
                System.exit(-1);
            }
        } else {
            System.err.println("Unrecognized file extension: " + fromName + ", only FB2 or ZIP supported.");
            System.exit(-1);
View Full Code Here

    private int getUnixMode(Resource r, ZipFile zf, int defaultMode)
        throws IOException {

        int unixMode = defaultMode;
        if (zf != null) {
            ZipEntry ze = zf.getEntry(r.getName());
            unixMode = ze.getUnixMode();
            if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG)
                && !preserve0Permissions) {
                unixMode = defaultMode;
            }
        } else if (r instanceof ArchiveResource) {
View Full Code Here

                             ZipOutputStream zOut, int mode,
                             ZipFile zf, File fromArchive)
        throws IOException {

        if (zf != null) {
            ZipEntry ze = zf.getEntry(r.getName());

            if (ze != null) {
                boolean oldCompress = doCompress;
                if (keepCompression) {
                    doCompress = (ze.getMethod() == ZipEntry.DEFLATED);
                }
                InputStream is = null;
                try {
                    is = zf.getInputStream(ze);
                    zipFile(is, zOut, prefix + name, ze.getTime(),
                            fromArchive, mode, ze.getExtraFields(true));
                } finally {
                    doCompress = oldCompress;
                    FileUtils.close(is);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.tools.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.