java.util.zip.ZipOutputStream#closeEntry ( )源码实例Demo

下面列出了java.util.zip.ZipOutputStream#closeEntry ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: apicurio-studio   文件: OpenApi2Thorntail.java
/**
 * @see io.apicurio.hub.api.codegen.OpenApi2JaxRs#generateAll(io.apicurio.hub.api.codegen.beans.CodegenInfo, java.lang.StringBuilder, java.util.zip.ZipOutputStream)
 */
@Override
protected void generateAll(CodegenInfo info, StringBuilder log, ZipOutputStream zipOutput)
        throws IOException {
    super.generateAll(info, log, zipOutput);
    if (!this.isUpdateOnly()) {
        log.append("Generating Dockerfile\r\n");
        zipOutput.putNextEntry(new ZipEntry("Dockerfile"));
        zipOutput.write(generateDockerfile().getBytes());
        zipOutput.closeEntry();

        log.append("Generating openshift-template.yml\r\n");
        zipOutput.putNextEntry(new ZipEntry("openshift-template.yml"));
        zipOutput.write(generateOpenshiftTemplate().getBytes());
        zipOutput.closeEntry();

        log.append("Generating src/main/resources/META-INF/microprofile-config.properties\r\n");
        zipOutput.putNextEntry(new ZipEntry("src/main/resources/META-INF/microprofile-config.properties"));
        zipOutput.write(generateMicroprofileConfigProperties().getBytes());
        zipOutput.closeEntry();
    }
}
 
源代码2 项目: FoxBPM   文件: DataObjectCacheGenerator.java
public void generate(ZipOutputStream out) {
	log.debug("开始处理bizData.data...");
	try{
		List<Map<String,Object>> list = FoxBpmUtil.getProcessEngine().getModelService().getAllBizObjects();
		ObjectMapper objectMapper = new ObjectMapper();
		JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(out, JsonEncoding.UTF8);
		String tmpEntryName = "cache/bizData.data";
		ZipEntry zipEntry = new ZipEntry(tmpEntryName);
		zipEntry.setMethod(ZipEntry.DEFLATED);// 设置条目的压缩方式
		out.putNextEntry(zipEntry);
		jsonGenerator.writeObject(list);
		out.closeEntry();
		log.debug("处理bizData.data文件完毕");
	}catch(Exception ex){
		log.error("解析bizData.data文件失败!生成zip文件失败!");
		throw new FoxBPMException("解析bizData.data文件失败",ex);
	}
}
 
源代码3 项目: scheduling   文件: VFSZipper.java
public static void zip(FileObject root, List<FileObject> files, OutputStream out) throws IOException {
    String basePath = root.getName().getPath();
    Closer closer = Closer.create();
    try {
        ZipOutputStream zos = new ZipOutputStream(out);
        closer.register(zos);
        for (FileObject fileToCopy : files) {
            ZipEntry zipEntry = zipEntry(basePath, fileToCopy);
            zos.putNextEntry(zipEntry);
            copyFileContents(fileToCopy, zos);
            zos.flush();
            zos.closeEntry();
        }
    } catch (IOException e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
 
源代码4 项目: big-c   文件: JarFinder.java
private static void copyToZipStream(File file, ZipEntry entry,
                            ZipOutputStream zos) throws IOException {
  InputStream is = new FileInputStream(file);
  try {
    zos.putNextEntry(entry);
    byte[] arr = new byte[4096];
    int read = is.read(arr);
    while (read > -1) {
      zos.write(arr, 0, read);
      read = is.read(arr);
    }
  } finally {
    try {
      is.close();
    } finally {
      zos.closeEntry();
    }
  }
}
 
源代码5 项目: tale   文件: ZipUtils.java
public static void zipFile(String filePath, String zipPath) throws Exception{
    byte[] buffer = new byte[1024];
    FileOutputStream fos = new FileOutputStream(zipPath);
    ZipOutputStream zos = new ZipOutputStream(fos);
    ZipEntry ze= new ZipEntry("spy.log");
    zos.putNextEntry(ze);
    FileInputStream in = new FileInputStream(filePath);
    int len;
    while ((len = in.read(buffer)) > 0) {
        zos.write(buffer, 0, len);
    }
    in.close();
    zos.closeEntry();
    //remember close it
    zos.close();
}
 
源代码6 项目: remixed-dungeon   文件: FileSystem.java
private static void addFolderToZip(File rootFolder, File srcFolder, int depth,
                                   ZipOutputStream zip, FileFilter filter) throws IOException {

	for (File file : srcFolder.listFiles(filter)) {

		if (file.isFile()) {
			addFileToZip(rootFolder, file, zip);
			continue;
		}

		if(depth > 0 && file.isDirectory()) {
			zip.putNextEntry(new ZipEntry(getRelativePath(file,rootFolder)));
			addFolderToZip(rootFolder, srcFolder, depth-1, zip, filter);
			zip.closeEntry();
		}
	}
}
 
源代码7 项目: jease   文件: Zipfiles.java
/**
 * Zips the given file.
 */
public static File zip(File file) throws IOException {
	String outFilename = file.getAbsolutePath() + ".zip";
	ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
			outFilename));
	FileInputStream in = new FileInputStream(file);
	out.putNextEntry(new ZipEntry(file.getName()));
	byte[] buf = new byte[4096];
	int len;
	while ((len = in.read(buf)) > 0) {
		out.write(buf, 0, len);
	}
	out.closeEntry();
	in.close();
	out.close();
	return new File(outFilename);
}
 
public String encode(boolean compress, String filename) throws IOException {
	byte[] bytes;
	if(compress) {
		// Zip the content
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ZipOutputStream	zos = new ZipOutputStream(baos);
		zos.putNextEntry(new ZipEntry(filename));
		zos.write(this.content);
		zos.closeEntry();
		zos.close();
		bytes = baos.toByteArray();
	} else {
		bytes = this.content;
	}
	return DatatypeConverter.printBase64Binary(bytes);
}
 
源代码9 项目: spotbugs   文件: ClassFactoryTest.java
private static File createZipFile() throws Exception {
    File zipFile = tempFile();
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
    ZipEntry entry = new ZipEntry("firstEntry");
    out.putNextEntry(entry);
    out.write("fileContents".getBytes(StandardCharsets.UTF_8));
    out.closeEntry();
    out.close();
    return zipFile;
}
 
源代码10 项目: jmbe   文件: ZipUtility.java
/**
 * Adds a file to the current zip output stream
 *
 * @param file the file to be added
 * @param zos the current zip output stream
 * @throws FileNotFoundException
 * @throws IOException
 */
private void zipFile(File file, ZipOutputStream zos) throws FileNotFoundException, IOException
{
    zos.putNextEntry(new ZipEntry(file.getName()));
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    long bytesRead = 0;
    byte[] bytesIn = new byte[BUFFER_SIZE];
    int read = 0;
    while((read = bis.read(bytesIn)) != -1)
    {
        zos.write(bytesIn, 0, read);
        bytesRead += read;
    }
    zos.closeEntry();
}
 
源代码11 项目: packagedrone   文件: AbstractRepositoryProcessor.java
public void write ( final Document doc, final OutputStream stream ) throws IOException
{
    if ( this.compressed )
    {
        final ZipOutputStream zos = new ZipOutputStream ( stream );
        zos.putNextEntry ( new ZipEntry ( this.basename + ".xml" ) );
        writeDoc ( doc, zos );
        zos.closeEntry ();
        zos.finish ();
    }
    else
    {
        writeDoc ( doc, stream );
    }
}
 
源代码12 项目: BetonQuest   文件: Zipper.java
/**
 * Zip it
 *
 * @param zipFile output ZIP file location
 */
public void zipIt(String zipFile) {

    byte[] buffer = new byte[1024];

    try {

        FileOutputStream fos = new FileOutputStream(zipFile);
        ZipOutputStream zos = new ZipOutputStream(fos);

        for (String file : this.fileList) {

            ZipEntry ze = new ZipEntry(file);
            zos.putNextEntry(ze);

            FileInputStream in = new FileInputStream(SOURCE_FOLDER + File.separator + file);

            int len;
            while ((len = in.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }

            in.close();
        }

        zos.closeEntry();
        // remember close it
        zos.close();

    } catch (IOException e) {
        LogUtils.getLogger().log(Level.WARNING, "Couldn't zip the files");
        LogUtils.logThrowable(e);
    }
}
 
private File createZip(ZipEntryContext... zipEntryContexts)
{
    File zipFile = TempFileProvider.createTempFile(getClass().getSimpleName(), ".zip");
    tempFiles.add(zipFile);

    byte[] buffer = new byte[BUFFER_SIZE];
    try
    {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(zipFile), BUFFER_SIZE);
        ZipOutputStream zos = new ZipOutputStream(out);

        for (ZipEntryContext context : zipEntryContexts)
        {
            ZipEntry zipEntry = new ZipEntry(context.getZipEntryName());
            zos.putNextEntry(zipEntry);

            InputStream input = context.getEntryContent();
            int len;
            while ((len = input.read(buffer)) > 0)
            {
                zos.write(buffer, 0, len);
            }
            input.close();
        }
        zos.closeEntry();
        zos.close();
    }
    catch (IOException ex)
    {
        fail("couldn't create zip file.");
    }

    return zipFile;
}
 
源代码14 项目: iaf   文件: DumpIbisConsole.java
public void copyServletResponse(ZipOutputStream zipOutputStream, HttpServletRequest request, HttpServletResponse response, String resource,
		String destinationFileName, Set resources, Set linkSet, String linkFilter) {
		long timeStart = new Date().getTime();
		try {
			IbisServletResponseWrapper ibisHttpServletResponseGrabber =  new IbisServletResponseWrapper(response);
			RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher(resource);
			requestDispatcher.include(request, ibisHttpServletResponseGrabber);
			String htmlString = ibisHttpServletResponseGrabber.getStringWriter().toString();

			ZipEntry zipEntry=new ZipEntry(destinationFileName);
//			if (resourceModificationTime!=0) {
//				zipEntry.setTime(resourceModificationTime);
//			}

			zipOutputStream.putNextEntry(zipEntry);
			
			PrintWriter pw = new PrintWriter(zipOutputStream);
			pw.print(htmlString);
			pw.flush();
			zipOutputStream.closeEntry();

			if (!resource.startsWith("FileViewerServlet")) {
				extractResources(resources, htmlString);
			}
			if (linkSet!=null) {
				followLinks(linkSet, htmlString, linkFilter);
			}
		} catch (Exception e) {
			log.error("Error copying servletResponse", e);
		}
		long timeEnd = new Date().getTime();
		log.debug("dumped file [" + destinationFileName + "] in " + (timeEnd - timeStart) + " msec.");
	}
 
源代码15 项目: spork   文件: Utils.java
private static void zipDir(File dir, String relativePath,
        ZipOutputStream zos, boolean start) throws IOException {
    String[] dirList = dir.list();
    for (String aDirList : dirList) {
        File f = new File(dir, aDirList);
        if (!f.isHidden()) {
            if (f.isDirectory()) {
                if (!start) {
                    ZipEntry dirEntry = new ZipEntry(relativePath
                            + f.getName() + "/");
                    zos.putNextEntry(dirEntry);
                    zos.closeEntry();
                }
                String filePath = f.getPath();
                File file = new File(filePath);
                zipDir(file, relativePath + f.getName() + "/", zos, false);
            } else {
                String path = relativePath + f.getName();
                if (!path.equals(JarFile.MANIFEST_NAME)) {
                    ZipEntry anEntry = new ZipEntry(path);
                    InputStream is = new FileInputStream(f);
                    try {
                        copyToZipStream(is, anEntry, zos);
                    } finally {
                        if (is != null) {
                            is.close();
                        }
                        if (zos != null) {
                            zos.closeEntry();
                        }
                    }
                }
            }
        }
    }
}
 
源代码16 项目: j2objc   文件: ZipInputStreamTest.java
private static byte[] zip(String[] names, byte[] bytes) throws IOException {
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    ZipOutputStream zippedOut = new ZipOutputStream(bytesOut);

    for (String name : names) {
        ZipEntry entry = new ZipEntry(name);
        zippedOut.putNextEntry(entry);
        zippedOut.write(bytes);
        zippedOut.closeEntry();
    }

    zippedOut.close();
    return bytesOut.toByteArray();
}
 
源代码17 项目: spotbugs   文件: AM_CREATES_EMPTY_ZIP_FILE_ENTRY.java
@DesireNoWarning("AM_CREATES_EMPTY_ZIP_FILE_ENTRY")
void notBug(ZipOutputStream any1, ZipOutputStream any2, ZipEntry anyZipEntry) throws IOException {
    any1.putNextEntry(anyZipEntry);
    any2.closeEntry();
}
 
源代码18 项目: JByteMod-Beta   文件: Processor.java
public int process() throws TransformerException, IOException, SAXException {
  ZipInputStream zis = new ZipInputStream(input);
  final ZipOutputStream zos = new ZipOutputStream(output);
  final OutputStreamWriter osw = new OutputStreamWriter(zos);

  Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

  TransformerFactory tf = TransformerFactory.newInstance();
  if (!tf.getFeature(SAXSource.FEATURE) || !tf.getFeature(SAXResult.FEATURE)) {
    return 0;
  }

  SAXTransformerFactory saxtf = (SAXTransformerFactory) tf;
  Templates templates = null;
  if (xslt != null) {
    templates = saxtf.newTemplates(xslt);
  }

  // configuring outHandlerFactory
  // ///////////////////////////////////////////////////////

  EntryElement entryElement = getEntryElement(zos);

  ContentHandler outDocHandler = null;
  switch (outRepresentation) {
  case BYTECODE:
    outDocHandler = new OutputSlicingHandler(new ASMContentHandlerFactory(zos), entryElement, false);
    break;

  case MULTI_XML:
    outDocHandler = new OutputSlicingHandler(new SAXWriterFactory(osw, true), entryElement, true);
    break;

  case SINGLE_XML:
    ZipEntry outputEntry = new ZipEntry(SINGLE_XML_NAME);
    zos.putNextEntry(outputEntry);
    outDocHandler = new SAXWriter(osw, false);
    break;

  }

  // configuring inputDocHandlerFactory
  // /////////////////////////////////////////////////
  ContentHandler inDocHandler;
  if (templates == null) {
    inDocHandler = outDocHandler;
  } else {
    inDocHandler = new InputSlicingHandler("class", outDocHandler, new TransformerHandlerFactory(saxtf, templates, outDocHandler));
  }
  ContentHandlerFactory inDocHandlerFactory = new SubdocumentHandlerFactory(inDocHandler);

  if (inDocHandler != null && inRepresentation != SINGLE_XML) {
    inDocHandler.startDocument();
    inDocHandler.startElement("", "classes", "classes", new AttributesImpl());
  }

  int i = 0;
  ZipEntry ze;
  while ((ze = zis.getNextEntry()) != null) {
    update(ze.getName(), n++);
    if (isClassEntry(ze)) {
      processEntry(zis, ze, inDocHandlerFactory);
    } else {
      OutputStream os = entryElement.openEntry(getName(ze));
      copyEntry(zis, os);
      entryElement.closeEntry();
    }

    i++;
  }

  if (inDocHandler != null && inRepresentation != SINGLE_XML) {
    inDocHandler.endElement("", "classes", "classes");
    inDocHandler.endDocument();
  }

  if (outRepresentation == SINGLE_XML) {
    zos.closeEntry();
  }
  zos.flush();
  zos.close();

  return i;
}
 
源代码19 项目: aion-germany   文件: GameServer.java
private static void initalizeLoggger() {
	new File("./log/backup/").mkdirs();
	File[] files = new File("log").listFiles(new FilenameFilter() {

		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(".log");
		}
	});

	if (files != null && files.length > 0) {
		byte[] buf = new byte[1024];
		try {
			String outFilename = "./log/backup/" + new SimpleDateFormat("yyyy-MM-dd HHmmss").format(new Date()) + ".zip";
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
			out.setMethod(ZipOutputStream.DEFLATED);
			out.setLevel(Deflater.BEST_COMPRESSION);

			for (File logFile : files) {
				FileInputStream in = new FileInputStream(logFile);
				out.putNextEntry(new ZipEntry(logFile.getName()));
				int len;
				while ((len = in.read(buf)) > 0) {
					out.write(buf, 0, len);
				}
				out.closeEntry();
				in.close();
				logFile.delete();
			}
			out.close();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(lc);
		lc.reset();
		configurator.doConfigure("config/slf4j-logback.xml");
	}
	catch (JoranException je) {
		throw new RuntimeException("[LoggerFactory] Failed to configure loggers, shutting down...", je);
	}
}
 
源代码20 项目: Knowage-Server   文件: ZipUtils.java
private static void zip(File input, String destDir, ZipOutputStream z) throws IOException {

		if (!input.isDirectory()) {

			z.putNextEntry(new ZipEntry((destDir + input.getName())));

			FileInputStream inStream = new FileInputStream(input);

			byte[] a = new byte[(int) input.length()];

			int did = inStream.read(a);

			if (did != input.length())
				throw new IOException("Impossibile leggere tutto il file " + input.getPath() + " letti solo " + did + " di " + input.length());

			z.write(a, 0, a.length);

			z.closeEntry();

			inStream.close();

			input = null;

		} else { // recurse

			String newDestDir = destDir + input.getName() + "/";
			String newInpurPath = input.getPath() + "/";

			z.putNextEntry(new ZipEntry(newDestDir));
			z.closeEntry();

			String[] dirlist = (input.list());

			input = null;

			for (int i = 0; i < dirlist.length; i++) {
				zip(new File(newInpurPath + dirlist[i]), newDestDir, z);

			}
		}
	}