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


Java ZipOutputStream.setMethod方法代码示例

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


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

示例1: 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

示例2: 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

示例3: downloadFiles

import java.util.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Downloads the given files.  The files are packed together in an
 * uncompressed zip-file.
 *
 * @param response     The HTTP response.
 * @param status       The download status.
 * @param files        The files to download.
 * @param indexes      Only download songs at these indexes. May be <code>null</code>.
 * @param coverArtFile The cover art file to include, may be {@code null}.
 * @param range        The byte range, may be <code>null</code>.
 * @param zipFileName  The name of the resulting zip file.   @throws IOException If an I/O error occurs.
 */
private void downloadFiles(HttpServletResponse response, TransferStatus status, List<MediaFile> files, int[] indexes, File coverArtFile, HttpRange range, String zipFileName) throws IOException {
    if (indexes != null && indexes.length == 1) {
        downloadFile(response, status, files.get(indexes[0]).getFile(), range);
        return;
    }

    LOG.info("Starting to download '" + zipFileName + "' to " + status.getPlayer());
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodeAsRFC5987(zipFileName));

    ZipOutputStream out = new ZipOutputStream(RangeOutputStream.wrap(response.getOutputStream(), range));
    out.setMethod(ZipOutputStream.STORED);  // No compression.

    Set<MediaFile> filesToDownload = new HashSet<>();
    if (indexes == null) {
        filesToDownload.addAll(files);
    } else {
        for (int index : indexes) {
            try {
                filesToDownload.add(files.get(index));
            } catch (IndexOutOfBoundsException x) { /* Ignored */}
        }
    }

    for (MediaFile mediaFile : filesToDownload) {
        zip(out, mediaFile.getParentFile(), mediaFile.getFile(), status, range);
    }
    if (coverArtFile != null && coverArtFile.exists()) {
        zip(out, coverArtFile.getParentFile(), coverArtFile, status, range);
    }


    out.close();
    LOG.info("Downloaded '" + zipFileName + "' to " + status.getPlayer());
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:48,代码来源:DownloadController.java

示例4: 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


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