当前位置: 首页>>代码示例>>Java>>正文


Java ZipOutputStream.setLevel方法代码示例

本文整理汇总了Java中java.util.zip.ZipOutputStream.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Java ZipOutputStream.setLevel方法的具体用法?Java ZipOutputStream.setLevel怎么用?Java ZipOutputStream.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.zip.ZipOutputStream的用法示例。


在下文中一共展示了ZipOutputStream.setLevel方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: openJarOutputStream

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private ZipOutputStream openJarOutputStream(File outputJar) {
    try {
        ZipOutputStream outputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputJar), BUFFER_SIZE));
        outputStream.setLevel(0);
        return outputStream;
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:RuntimeShadedJarCreator.java

示例2: generateZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Generates a zip file.
 *
 * @param source      source file or directory to compress.
 * @param destination destination of zipped file.
 * @return the zipped file.
 */
private void generateZip (File source, File destination) throws IOException
{
   if (source == null || !source.exists ())
   {
      throw new IllegalArgumentException ("source file should exist");
   }
   if (destination == null)
   {
      throw new IllegalArgumentException (
            "destination file should be not null");
   }

   FileOutputStream output = new FileOutputStream (destination);
   ZipOutputStream zip_out = new ZipOutputStream (output);
   zip_out.setLevel (
         cfgManager.getDownloadConfiguration ().getCompressionLevel ());

   List<QualifiedFile> file_list = getFileList (source);
   byte[] buffer = new byte[BUFFER_SIZE];
   for (QualifiedFile qualified_file : file_list)
   {
      ZipEntry entry = new ZipEntry (qualified_file.getQualifier ());
      InputStream input = new FileInputStream (qualified_file.getFile ());

      int read;
      zip_out.putNextEntry (entry);
      while ((read = input.read (buffer)) != -1)
      {
         zip_out.write (buffer, 0, read);
      }
      input.close ();
      zip_out.closeEntry ();
   }
   zip_out.close ();
   output.close ();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:44,代码来源:FileSystemDataStore.java

示例3: writeToFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
@Override
protected void writeToFile(List<ExportEntry> csvEntries) throws IOException {
    // Setup compression stuff
    ZipOutputStream zos = new ZipOutputStream(fileOutpuStream);
    zos.setMethod(ZipOutputStream.DEFLATED);
    zos.setLevel(9);

    // Setup signature stuff
    MessageDigest md;
    try {
        md = MessageDigest.getInstance("SHA-512");
    } catch (NoSuchAlgorithmException ex) {
        LOG.log(Level.SEVERE, "Missing hash algorithm for signature. No file exported!", ex);
        throw new IOException("Missing hash algorithm for signature.");
    }
    DigestOutputStream dos = new DigestOutputStream(zos, md);

    // write data        
    zos.putNextEntry(new ZipEntry(DATA_ZIP_ENTRY));
    CsvWriter cwriter = new CsvWriter(dos, VaultCsvEntry.CSV_DELIMITER,
            Charset.forName("UTF-8"));

    cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
    for (ExportEntry item : csvEntries) {
        cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
    }
    cwriter.flush();

    // add signature file
    zos.putNextEntry(new ZipEntry(SIGNATURE_ZIP_ENTRY));
    String sigString = (new HexBinaryAdapter()).marshal(md.digest());
    zos.write(sigString.getBytes(), 0, sigString.getBytes().length);

    // close everything
    cwriter.close();
    dos.close();
    zos.close();
    fileOutpuStream.close();
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:40,代码来源:VaultOdvExporter.java

示例4: createZip

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
protected String createZip(String key) throws IOException {
    File zip = new File(PATH_PICTURES + "zip" + File.separator + key + ".zip");
    if (zip.createNewFile()) {
        ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zip));
        zout.setLevel(Deflater.BEST_COMPRESSION);
        List<Folder> folderOfPictures = folderService.get(key);
        for (Folder folder : folderOfPictures) {
            addFileToZip(zout, new File(PATH_PICTURES + folder.getImage().getKeyFile() + ("octet-stream".equals(folder.getImage().getMimeType()) ? "" : ("." + folder.getImage().getMimeType()))));
        }
        zout.close();
    }

    return zip.getPath();
}
 
开发者ID:MrChebik,项目名称:OSPicture,代码行数:15,代码来源:ZipUtils.java

示例5: btnBackupClicked

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
private void btnBackupClicked() {
      String backuppath=txtpath.getText();
 String Database =txtdatabase.getText();
 String Password =txtpass.getText();
 String user=txtusername.getText();
 Backup b = new Backup();
 try
{
     if(txtusername.getText().equals("") || txtpath.getText().equals("") || txtdatabase.getText().equals(""))
     {
  	   ErrorMessage.display("Incomplete Details", "Please fill all the fields first");
     }
     else
     {
  	   byte[] data = b.getData("localhost", "3306", user,   Password, Database).getBytes();
         File filedst = new File(backuppath+"\\"+Database+".zip");
         FileOutputStream dest = new FileOutputStream(filedst);
         ZipOutputStream zip = new ZipOutputStream(
         new BufferedOutputStream(dest));
         zip.setMethod(ZipOutputStream.DEFLATED);
         zip.setLevel(Deflater.BEST_COMPRESSION);
         zip.putNextEntry(new ZipEntry(Database+".sql"));
         zip.write(data);
         zip.close();
         dest.close();
    SuccessMessage.display("Database BackUp Wizard", "Back Up Successfully for Database: " +
  		""+Database+"\n"+"On Dated: "+date);
     }
 }catch (Exception ex){
  ErrorMessage.display("Database BackUp Wizard", ex.getMessage()+" \nBack Up Failed for Database: "+Database+"\n "+"On Dated: ");
}

  }
 
开发者ID:mikemacharia39,项目名称:gatepass,代码行数:34,代码来源:Back.java

示例6: zipFiles

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
public String zipFiles()
{
	byte[] buffer = new byte[1024];
	int length;
	try
	{
		if(filelist.size() != 0)
		{
			if(zipname.contains("."))
			{
				zipname = zipname.split(".")[0] + ".zip";
			}
			else
			{
				zipname = zipname + ".zip";
			}
			
			File output = new File(zipname);
			ZipOutputStream out = new ZipOutputStream(new FileOutputStream(output));
		
			//Set the level of compression
			out.setLevel(Deflater.BEST_COMPRESSION);
			
			for(int i = 0; i < filelist.size(); i++)
			{
				//Load a new file to the input stream
				FileInputStream in = new FileInputStream(filelist.get(i));
				
				//Add ZIP entry to the output stream
				String filename = filelist.get(i).getName();
				out.putNextEntry(new ZipEntry(filename));
			
				//Transfer bytes from the current file to the ZIP file
				while ((length = in.read(buffer)) > 0)
					out.write(buffer, 0, length);
			
				//Close the current entry
				out.closeEntry();
				
				//Close input stream
				in.close();
			}
			//Close the ZIP file
			out.close();
			
			return "Zipping has been successful!";
		}
		else
			return "There is no file and/or destination selected!";
	}
	catch(Exception e)
	{
		return "An exception has occured during the zipping process " + e;
	}
}
 
开发者ID:vilihegyi,项目名称:ZIPIt,代码行数:56,代码来源:ZIPIt.java

示例7: writeToFile

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Writes the data to a CSV file and generates a signature hash.
 * Then it puts both of this into a ZIP archive file.
 *
 * @param csvEntries The {@link ExportEntry} to be exported.
 * @throws IOException Thrown if the SHA-512 hash algorithm is missing.
 */
@Override
protected void writeToFile(final List<ExportEntry> csvEntries) throws IOException {
    // Setup compression stuff
    FileOutputStream fileOutputStream = getFileOutputStream();
    final int zipCompressionLevel = 9;

    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
    zipOutputStream.setMethod(ZipOutputStream.DEFLATED);
    zipOutputStream.setLevel(zipCompressionLevel);

    // Setup signature
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-512");
    } catch (NoSuchAlgorithmException exception) {
        LOG.log(Level.SEVERE, "Missing hash algorithm for signature. No file exported!", exception);
        throw new IOException("Missing hash algorithm for signature.");
    }
    DigestOutputStream digestOutputStream = new DigestOutputStream(zipOutputStream, digest);

    // write data
    zipOutputStream.putNextEntry(new ZipEntry(DATA_ZIP_ENTRY));
    CsvWriter cwriter = new CsvWriter(digestOutputStream, VaultCsvEntry.CSV_DELIMITER,
            Charset.forName("UTF-8"));

    cwriter.writeRecord(((CsvEntry) csvEntries.get(0)).getCsvHeaderRecord());
    for (ExportEntry item : csvEntries) {
        cwriter.writeRecord(((CsvEntry) item).toCsvRecord());
    }
    cwriter.flush();

    // add signature file
    zipOutputStream.putNextEntry(new ZipEntry(SIGNATURE_ZIP_ENTRY));
    String sigString = (new HexBinaryAdapter()).marshal(digest.digest());
    zipOutputStream.write(sigString.getBytes("UTF-8"), 0, sigString.getBytes("UTF-8").length);

    // Closing the streams
    cwriter.close();
    digestOutputStream.close();
    zipOutputStream.close();
    fileOutputStream.close();
}
 
开发者ID:lucasbuschlinger,项目名称:BachelorPraktikum,代码行数:50,代码来源:VaultODVExporter.java


注:本文中的java.util.zip.ZipOutputStream.setLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。