簡體   English   中英

意外的Java GZIPOutputStream結果

[英]Unexpected Java GZIPOutputStream results

我們有以下Java方法使用GZIPOutputStream壓縮文件

 private void archive(Path originalFile) {
    Path tempFile = originalFile.resolveSibling(originalFile.toFile().getName() + TEMPORARY_FILE_EXTENSION);
    Path gzippedFile = originalFile.resolveSibling(originalFile.toFile().getName() + ARCHIVED_FILE_EXTENSION);
    try {
        try (FileInputStream input = new FileInputStream(originalFile.toFile());
            BufferedOutputStream output = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(tempFile.toFile())))) {
            IOUtils.copy(input,output);
            output.flush();
        }
        Files.move(tempFile, gzippedFile, StandardCopyOption.REPLACE_EXISTING);
        Files.delete(originalFile);
        LOGGER.info("Archived file {} to {}", originalFile, gzippedFile);
    } catch (IOException e) {
        LOGGER.error("Could not archive file {}: " + e.getMessage(), originalFile, e);
    }
    try {
        Files.deleteIfExists(tempFile);
    } catch (IOException e) {
        LOGGER.error("Could not delete temporary file {}: " + e.getMessage(), tempFile, e);
    }
}

問題是,如果我們手動解壓縮該文件:

gzip -d file_name

生成的解壓縮文件與原始文件不匹配。 文件大小和總行數減少。 例如,從33MB到32MB,損失80萬行。

問題可能與我們正在壓縮的文件的編碼( EBCDIC )有關嗎? https://en.wikipedia.org/wiki/EBCDIC

經過幾次測試后,我們無法重現該問題,它一定與壓縮期間卷上沒有足夠的空間有關。 @SirFartALot感謝您指出這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM