Package java.util.zip

Examples of java.util.zip.ZipEntry


           
            byte b[] = new byte[512];
            ZipOutputStream zout = getZipOutputStream(directory.toString());
           
            if (zout != null) {
                ZipEntry versionEntry = new ZipEntry("version.txt");
                zout.putNextEntry(versionEntry);
                String version = String.valueOf(DataCrow.getVersion().toString());
                zout.write(version.getBytes(), 0, version.getBytes().length);
               
                if (comment.length() > 0)
                    zout.write(("\n" + comment).getBytes(), 0, ("\n" + comment).getBytes().length);
               
                zout.closeEntry();
               
                for (String file : files) {
                    if (!file.endsWith(".log")) {
                        InputStream in = new FileInputStream(file);
                        ZipEntry e = new ZipEntry(file.replace(File.separatorChar, '/'));
                        zout.putNextEntry(e);
                        int len = 0;
                        while ((len = in.read(b)) != -1) {
                            zout.write(b, 0, len);
                        }

                        listener.sendMessage(DcResources.getText("msgCreatingBackupOfFile", file));

                        in.close();
                        zout.closeEntry();
                    }

                    listener.notifyProcessed();
                }
               
                zout.close();
                listener.sendMessage(DcResources.getText("msgWritingBackupFile"));
            }
        } catch (Exception e) {
            listener.sendMessage(DcResources.getText("msgBackupError", e.getMessage()));
            listener.sendError(e);
        }

        DcSettings.set(DcRepository.Settings.stBackupLocation, directory.toString());
       
View Full Code Here


            listener.sendError(e);
        }
    }   
   
    private boolean isSupportedVersion(ZipFile zf) throws IOException {
        ZipEntry ze = zf.getEntry("version.txt");
       
        if (ze != null) {
            InputStream is = zf.getInputStream(ze);
            BufferedInputStream bis = new BufferedInputStream(is);
           
View Full Code Here

            listener.sendMessage(DcResources.getText("msgClosingDb"));
            DatabaseManager.closeDatabases(false);

            boolean success = true;
            while (list.hasMoreElements()) {
                ZipEntry ze = list.nextElement();
                String filename = ze.getName();
                try {

                    if (isVersion(filename))
                        continue;
                   
                    boolean isImage = isImage(filename);
                    boolean isReport = isReport(filename);
                    boolean isModule = isModule(filename);
                    boolean isResource = isResource(filename);
                    boolean isData = !isImage && !isReport && !isModule && !isResource;
                   
                    boolean restore = true;
                   
                    if (isImage && restoreDatabase) {
                        filename = DataCrow.imageDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
                    } else if (isResource && restoreDatabase) {
                        filename = DataCrow.resourcesDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
                    } else if (isReport && restoreReports) {
                        filename = filename.substring(filename.lastIndexOf("/reports") + 1, filename.length());
                        filename = DataCrow.installationDir + filename;
                    } else if (isModule && restoreModules) {
                        filename = filename.substring(filename.lastIndexOf("/modules") + 1, filename.length());
                        filename = DataCrow.installationDir + filename;
                    } else if (isData && restoreDatabase) {
                        filename = DataCrow.dataDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
                    } else {
                        if (logger.isDebugEnabled())
                            logger.debug("Skipping " + filename);

                        restore = false;
                    }
                   
                    if (restore) {
                        try {
                            new File(filename.substring(0, filename.lastIndexOf("/"))).mkdirs();
                        } catch (Exception e) {
                            logger.warn("Unable to create directories for " + filename, e);
                        }
                       
                        InputStream istr = zf.getInputStream(ze);
                        BufferedInputStream bis = new BufferedInputStream(istr);
                        FileOutputStream fos = new FileOutputStream(filename);

                        int sz = (int)ze.getSize();
                        final int N = 1024;
                        byte buf[] = new byte[N];
                        int ln = 0;
                        while (sz > 0 &&  // workaround for bug
                            (ln = bis.read(buf, 0, Math.min(N, sz))) != -1) {
View Full Code Here

            try {
               
                if (!selection.isFile()) return;
               
                ZipFile zf = new ZipFile(selection);
                ZipEntry ze = zf.getEntry("version.txt");
               
                if (ze != null) {
                    InputStream is = zf.getInputStream(ze);
                    BufferedInputStream bis = new BufferedInputStream(is);
                   
View Full Code Here

            ZipFile zf = new ZipFile(DataCrow.moduleDir + filename);

            Map<String, byte[]> content = new HashMap<String, byte[]>();
            Enumeration<? extends ZipEntry> list = zf.entries();
            while (list.hasMoreElements()) {
                ZipEntry ze = list.nextElement();

                BufferedInputStream bis = new BufferedInputStream(zf.getInputStream(ze));
                int size = (int) ze.getSize();
                byte[] bytes = new byte[size];
                bis.read(bytes);
               
                String filename = ze.getName();
                content.put(filename, bytes);
               
                bis.close();
            }       
           
View Full Code Here

        ZipFile zf = null;
        try {
            zf = new ZipFile(jar);
            Enumeration<? extends ZipEntry> entries = zf.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().equals(name)) {
                    bis = new BufferedInputStream(zf.getInputStream(entry));
                    int size = (int) entry.getSize();
                    byte[] data = new byte[size];
                    int b = 0, eofFlag = 0;
                    while ((size - b) > 0) {
                        eofFlag = bis.read(data, b, size - b);
                        if (eofFlag == -1)
View Full Code Here

  }
 
    public void addEntry(String name, byte[] bytes) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
       
        ZipEntry ze = new ZipEntry(name);
        zout.putNextEntry(ze);
       
        byte b[] = new byte[512];
        int len = 0;
        while ((len = bais.read(b)) != -1) {
View Full Code Here

        if (!outDir.exists()) {
            outDir.mkdirs();
        }

        ZipInputStream in = new ZipInputStream(input);
        ZipEntry z;
        while ((z = in.getNextEntry()) != null) {
            if (z.isDirectory()) {
                String name = z.getName();
                name = name.substring(0, name.length() - 1);
                File f = new File(outputDirectory + File.separator + name);
                f.mkdirs();
                f.setLastModified(z.getTime());
            } else {
                File f = new File(outputDirectory + File.separator + z.getName());
                f.createNewFile();
                DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
                int b;
                while ((b = in.read()) != -1) out.write(b);
                out.close();
                f.setLastModified(z.getTime());
            }
        }
        in.close();
    }
View Full Code Here

     */
    public static void zip(ZipOutputStream out, File f, String base) throws IOException {
        if (f.isDirectory()) {
            File[] fl = f.listFiles();
            if (!base.equals("")) {
                ZipEntry entry = new ZipEntry(base + "/");
                entry.setTime(f.lastModified());
                out.putNextEntry(entry);
            }
            base = base.length() == 0 ? "" : base + "/";
            for (int i = 0; i < fl.length; i++) {
                zip(out, fl[i], base + fl[i].getName());
            }
        } else {
            ZipEntry entry = new ZipEntry(base);
            entry.setTime(f.lastModified());
            out.putNextEntry(entry);
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(f)));
            int b;
            while ((b = in.read()) != -1) out.write(b);
            in.close();
View Full Code Here

        }
    }

    public static void addEntry(ZipOutputStream out, long time, String entryName) throws IOException {
        if (!entryName.equals("")) {
            ZipEntry entry = new ZipEntry(entryName);
            entry.setTime(time);
            out.putNextEntry(entry);
        }
    }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipEntry

Copyright © 2015 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.