當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。