ZipInputStream#readAllBytes should clarify it doesn't read the whole stream?
Jaikiran Pai
jai.forums2013 at gmail.com
Thu Feb 25 15:35:35 UTC 2021
Thank you Lance and Alan. I do have access to JBS, I'll file one
tomorrow with the details.
-Jaikiran
On 25/02/21 9:04 pm, Lance Andersen wrote:
> Hi Jaikiran,
>
> Yes I believe this makes sense.
>
> It would also require a CSR.
>
> I can login a bug if you do not have access to do so.
>
> Best
> Lance
>
>> On Feb 24, 2021, at 10:56 PM, Jaikiran Pai <jai.forums2013 at gmail.com
>> <mailto:jai.forums2013 at gmail.com>> wrote:
>>
>> The javadoc of InputStream#readAllBytes() states[1] that it reads all
>> the remaining bytes of the stream. The java.util.zip.ZipInputStream
>> doesn't override this method and thus "inherits" this javadoc. The
>> implementation of InputStream#readAllBytes() ultimately ends up
>> calling ZipInputStream#read()[2], so the implementation correctly
>> reads only till the end of the current ZipEntry and not the entire
>> ZipInputStream. However, because the javadoc gets inherited, reading
>> any code like the following doesn't make it clear that it's only
>> reading till the end of the current entry:
>>
>> zis = ... // ZipInputStream
>> while ((e = zis.getNextEntry()) != null) {
>> String name = e.getName();
>> zis.readAllBytes(); // gives an impression that all bytes of the
>> stream are read
>> ...
>> }
>>
>> Should the ZipInputStream override the readAllBytes(), just so as to
>> add a very specific javadoc to this method which explains that it
>> reads only till the end of current entry and other related semantics?
>> Perhaps the same should be done for ZipInputStream#readNBytes(...)?
>>
>>
>> [1]
>> https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/InputStream.html#readAllBytes()
>> <https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/InputStream.html#readAllBytes()>
>> [2]
>> https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/zip/ZipInputStream.html#read(byte%5B%5D,int,int)
>> <https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/zip/ZipInputStream.html#read(byte%5B%5D,int,int)>
>>
>> -Jaikiran
>>
>
>
>
>
> Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
> Oracle Java Engineering
> 1 Network Drive
> Burlington, MA 01803
> Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>
>
>
>
More information about the core-libs-dev
mailing list