From 425ef0685c584abec80454fbcccdcc6db6558f93 Mon Sep 17 00:00:00 2001 From: Eirik Bjorsnos Date: Wed, 12 Apr 2023 21:44:21 +0000 Subject: [PATCH] 8303923: ZipOutStream::putEntry should include an apiNote to indicate that the STORED compression method should be used when writing directory entries Reviewed-by: lancea, alanb --- .../classes/java/util/zip/ZipOutputStream.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/zip/ZipOutputStream.java b/src/java.base/share/classes/java/util/zip/ZipOutputStream.java index 54d48f6ea92..84174ea3380 100644 --- a/src/java.base/share/classes/java/util/zip/ZipOutputStream.java +++ b/src/java.base/share/classes/java/util/zip/ZipOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -191,6 +191,21 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant *

* The current time will be used if the entry has no set modification time. * + * @apiNote When writing a directory entry, the STORED compression method + * should be used and the size and CRC-32 values should be set to 0: + * + * {@snippet lang = "java": + * ZipEntry e = new ZipEntry(entryName); + * if (e.isDirectory()) { + * e.setMethod(ZipEntry.STORED); + * e.setSize(0); + * e.setCrc(0); + * } + * stream.putNextEntry(e); + *} + * + * This allows optimal performance when processing directory entries. + * * @param e the ZIP entry to be written * @throws ZipException if a ZIP format error has occurred * @throws IOException if an I/O error has occurred