Package de.schlichtherle.util.zip

Examples of de.schlichtherle.util.zip.ZipOutputStream


    }
 
    public static void main(String[] args) throws FileNotFoundException, ZipException, IOException {
        File tempFile = new File("c:/test.zip");
        de.schlichtherle.io.File zip = new de.schlichtherle.io.File(tempFile);
        ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(new File(zip.getAbsolutePath())));
        copyIntoAZip("file:d:\\woj\\dl\\jgoodies\\validation\\1.1/validation-1_1.zip!/validation-1.1/src/tutorial/*",
                zop,
                "binaries/");
        zop.close();
    }
View Full Code Here


        File z = new File(moduleZipFile.getAbsolutePath()+".tmp");
        if (z.exists()) {
            z.delete();
        }
        de.schlichtherle.io.File zip = new de.schlichtherle.io.File(z);
        ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(new File(zip.getAbsolutePath())));
        //tempFile.deleteOnExit();
        //test if doc is
        try {
          for (String srcPath : srcPaths) {
            ZipHelper.copyIntoAZip("file:"+srcPath+"/*", zop, Parameters.SOURCES_FOLDER+"/", new Predicate() {
                    public boolean evaluate(Object path) {
                        String p = (String)path;
                        return p.endsWith(".java") || p.endsWith("/package.html");
                    }
                });
      }
          for (String docPath : docPaths) {
            ZipHelper.copyIntoAZip("file:"+docPath+"/*", zop, Parameters.JAVADOCS_FOLDER+"/");
      }
          for (String jarPath : jarPaths) {
            ZipHelper.copyIntoAZip("file:"+jarPath, zop, Parameters.BINARIES_FOLDER+"/");
      }
            writeDescriptor(xmlDescriptor, zop);
        } finally {
            try {
                de.schlichtherle.io.File.update();
            } catch (ZipControllerException e) {
                e.printStackTrace();
            }
            zop.close();
        }
        IOHelper.move(z, moduleZipFile);
        System.out.print(" - ZIP BUILT");
  }
View Full Code Here

     * @throws ZipException
     * @throws IOException
     */
    public static void copyArchiveContent(String prefixToRemove, String prefixToAdd, String destPath, String srcPath) throws Exception {
        de.schlichtherle.io.File dest = new de.schlichtherle.io.File(destPath);
        ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(dest));
        try {
            copyArchiveContent(prefixToRemove, prefixToAdd, srcPath, zop);
        } finally {
            zop.close();
        }
    }
View Full Code Here

    private File buildZip() throws Exception {
      //zip module preparation
      File tempFile = File.createTempFile("woj-addModule", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$
        de.schlichtherle.io.File zip = new de.schlichtherle.io.File(tempFile);
        ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(new File(zip.getAbsolutePath())));
        tempFile.deleteOnExit();
        //test if doc is
        try {
          addResource(_docPath, _pathInDoc, zop, Parameters.JAVADOCS_FOLDER);
          addResource(_srcPath, _pathInSrc, zop, Parameters.SOURCES_FOLDER);
          for (int i = 0; i < _binPath.length; i++) {
        File jar = new File(_binPath[i]);
        writeContent(Parameters.BINARIES_FOLDER+"/"+jar.getName(), getFileContent(jar), zop); //$NON-NLS-1$
      }
          //write xml
            writeContent(Parameters.MODULE_DESCRIPTOR_FILE_NAME,_xmlDescriptor, zop);
          if(new File(_licence).exists()) {
            writeContent(Parameters.MODULE_LICENSE_FILE_NAME, IOHelper.readEntirely(new BufferedReader(new FileReader(_licence))), zop);
          }
        } finally {
            try {
                de.schlichtherle.io.File.update();
            } catch (ZipControllerException e) {
                e.printStackTrace();
            }
            zop.close();
        }
        return zip;
    }
View Full Code Here

        @Override
        protected void handleStart(File startDirectory, Collection results)
            throws IOException {

            //out = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(destination)));
            out = new ZipOutputStream(new FileOutputStream(destination));
            out.setMethod(ZipEntry.DEFLATED);
        }
View Full Code Here

            throw new ArchiveException(String.format("[%s] exist and delete failed",
                                                     targetArchiveFile.getAbsolutePath()));
        }

        boolean exist = false;
        ZipOutputStream zipOut = null;
        Set<String> entryNames = new HashSet<String>();
        BlockingQueue<Future<ArchiveEntry>> queue = new LinkedBlockingQueue<Future<ArchiveEntry>>(); // 下载成功的任务列表
        ExecutorCompletionService completionService = new ExecutorCompletionService(executor, queue);

        final File targetDir = new File(targetArchiveFile.getParentFile(),
                                        FilenameUtils.getBaseName(targetArchiveFile.getPath()));
        try {
            // 创建一个临时目录
            FileUtils.forceMkdir(targetDir);

            zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetArchiveFile)));
            zipOut.setLevel(Deflater.BEST_SPEED);
            // 进行并发压缩处理
            for (final FileData fileData : fileDatas) {
                if (fileData.getEventType().isDelete()) {
                    continue; // 忽略delete类型的数据打包,因为只需直接在目标进行删除
                }

                String namespace = fileData.getNameSpace();
                String path = fileData.getPath();
                boolean isLocal = StringUtils.isBlank(namespace);
                String entryName = null;
                if (true == isLocal) {
                    entryName = FilenameUtils.getPath(path) + FilenameUtils.getName(path);
                } else {
                    entryName = namespace + File.separator + path;
                }

                // 过滤一些重复的文件数据同步
                if (entryNames.contains(entryName) == false) {
                    entryNames.add(entryName);
                } else {
                    continue;
                }

                final String name = entryName;
                if (true == isLocal && !useLocalFileMutliThread) {
                    // 采用串行处理,不走临时文件
                    queue.add(new DummyFuture(new ArchiveEntry(name, callback.retrive(fileData))));
                } else {
                    completionService.submit(new Callable<ArchiveEntry>() {

                        public ArchiveEntry call() throws Exception {
                            // 处理下异常,可能失败
                            InputStream input = null;
                            OutputStream output = null;
                            try {
                                input = callback.retrive(fileData);

                                if (input instanceof LazyFileInputStream) {
                                    input = ((LazyFileInputStream) input).getInputSteam();// 获取原始的stream
                                }

                                if (input != null) {
                                    File tmp = new File(targetDir, name);
                                    NioUtils.create(tmp.getParentFile(), false, 3);// 尝试创建父路径
                                    output = new FileOutputStream(tmp);
                                    NioUtils.copy(input, output);// 拷贝到文件
                                    return new ArchiveEntry(name, new File(targetDir, name));
                                } else {
                                    return new ArchiveEntry(name);
                                }
                            } finally {
                                IOUtils.closeQuietly(input);
                                IOUtils.closeQuietly(output);
                            }
                        }
                    });
                }
            }

            for (int i = 0; i < entryNames.size(); i++) {
                // 读入流
                ArchiveEntry input = null;
                InputStream stream = null;
                try {
                    input = queue.take().get();
                    if (input == null) {
                        continue;
                    }

                    stream = input.getStream();
                    if (stream == null) {
                        continue;
                    }

                    if (stream instanceof LazyFileInputStream) {
                        stream = ((LazyFileInputStream) stream).getInputSteam();// 获取原始的stream
                    }

                    exist = true;
                    zipOut.putNextEntry(new ZipEntry(input.getName()));
                    NioUtils.copy(stream, zipOut);// 输出到压缩流中
                    zipOut.closeEntry();
                } finally {
                    IOUtils.closeQuietly(stream);
                }
            }

            if (exist) {
                zipOut.finish();
            }
        } catch (Exception e) {
            throw new ArchiveException(e);
        } finally {
            IOUtils.closeQuietly(zipOut);
View Full Code Here

TOP

Related Classes of de.schlichtherle.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.