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


Java ZipOutputStream.setMethod方法代码示例

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


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

示例1: downloadFiles

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Downloads a collection of files within a directory.
 *
 * @param response The HTTP response.
 * @param status   The download status.
 * @param dir      The directory.
 * @param indexes  Only download files with these indexes within the directory.
 * @throws IOException If an I/O error occurs.
 */
private void downloadFiles(HttpServletResponse response, TransferStatus status, File dir, int[] indexes) throws IOException {
    String zipFileName = dir.getName() + ".zip";
    LOG.info("Starting to download '" + zipFileName + "' to " + status.getPlayer());
    status.setFile(dir);

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

    ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
    out.setMethod(ZipOutputStream.STORED);  // No compression.

    MediaFile parent = mediaFileService.getMediaFile(dir);
    List<MediaFile> allChildren = mediaFileService.getChildrenOf(parent, true, true, true);
    List<MediaFile> mediaFiles = new ArrayList<MediaFile>();
    for (int index : indexes) {
        mediaFiles.add(allChildren.get(index));
    }

    for (MediaFile mediaFile : mediaFiles) {
        zip(out, mediaFile.getParentFile(), mediaFile.getFile(), status, null);
    }

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

示例2: createArchiveOutputStream

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
public ZipOutputStream createArchiveOutputStream(File destination) throws IOException {
    ZipOutputStream outStream = new ZipOutputStream(destination);
    try {
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        IOUtils.closeQuietly(outStream);
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:DefaultZipCompressor.java

示例3: createArchiveOutputStream

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
public ZipOutputStream createArchiveOutputStream(File destination) {
    try {
        ZipOutputStream outStream = new ZipOutputStream(destination);
        outStream.setUseZip64(zip64Mode);
        outStream.setMethod(entryCompressionMethod);
        return outStream;
    } catch (Exception e) {
        String message = String.format("Unable to create ZIP output stream for file %s.", destination);
        throw new UncheckedIOException(message, e);
    }
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:12,代码来源:DefaultZipCompressor.java

示例4: downloadDirectory

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * Downloads all files in a directory (including sub-directories). The files are packed together in an
 * uncompressed zip-file.
 *
 * @param response The HTTP response.
 * @param status   The download status.
 * @param file     The file to download.
 * @param range    The byte range, may be <code>null</code>.
 * @throws IOException If an I/O error occurs.
 */
private void downloadDirectory(HttpServletResponse response, TransferStatus status, File file, LongRange range) throws IOException {
    String zipFileName = file.getName() + ".zip";
    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.

    zip(out, file.getParentFile(), file, status, range);
    out.close();
    LOG.info("Downloaded '" + zipFileName + "' to " + status.getPlayer());
}
 
开发者ID:FutureSonic,项目名称:FutureSonic-Server,代码行数:24,代码来源:DownloadController.java

示例5: zip

import org.apache.tools.zip.ZipOutputStream; //导入方法依赖的package包/类
/**
 * 压缩文件夹或文件
 *
 * @param src
 *            src
 * @param archive
 *            archive
 * @param comment
 *            压缩包注释
 * @throws FileNotFoundException
 *             FileNotFoundException
 * @throws IOException
 *             IOException
 */
public static void zip(String src, String archive, String comment)
        throws FileNotFoundException, IOException {
    // ----压缩文件:
    FileOutputStream f = new FileOutputStream(archive);
    // 使用指定校验和创建输出流
    CheckedOutputStream csum = new CheckedOutputStream(f, new CRC32());

    ZipOutputStream zos = new ZipOutputStream(csum);
    // 支持中文
    zos.setEncoding(encoding);
    BufferedOutputStream out = new BufferedOutputStream(zos);
    // 设置压缩包注释
    zos.setComment(comment);

    // 启用压缩
    zos.setMethod(ZipOutputStream.DEFLATED);
    // 压缩级别为最强压缩,但时间要花得多一点
    zos.setLevel(Deflater.BEST_COMPRESSION);

    File srcFile = new File(src);

    if (!srcFile.exists() || (srcFile.isDirectory() && srcFile.list().length == 0)) {
        out.close();
        throw new FileNotFoundException(
                "File must exist and  ZIP file must have at least one entry.");
    }
    // 获取压缩源所在父目录
    src = src.replaceAll("\\\\", "/");
    String prefixDir = null;
    if (srcFile.isFile()) {
        prefixDir = src.substring(0, src.lastIndexOf("/") + 1);
    } else {
        prefixDir = (src.replaceAll("/$", "") + "/");
    }

    // 如果不是根目录
    if (prefixDir.indexOf("/") != (prefixDir.length() - 1) && isCreateSrcDir) {
        prefixDir = prefixDir.replaceAll("[^/]+/$", "");
    }

    // 开始压缩
    saveZipFile(zos, out, srcFile, prefixDir);

    out.close();
    // 注:校验和要在流关闭后才准备,一定要放在流被关闭后使用
    logger.debug("Checksum: " + csum.getChecksum().getValue());

}
 
开发者ID:jiucai,项目名称:appframework,代码行数:63,代码来源:Zip.java


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