HashingInputStream does not override skip()
See original GitHub issueHashingInputStream does not override FilterInputStream.skip(long)
. Therefore any skipped data is not considered by the hash calculation. I doubt that this is intended, though if it is, can this please be clearly documented in the description of the method?
A usecase where skipping data is important is when working with ZipInputStream
s:
HashingInputStream hashIn = ...;
ZipInputStream zipIn = new ZipInputStream(hashIn);
for (ZipEntry zipEntry; (zipEntry = zipIn.getNextEntry()) != null;) {
// Read entry
...
}
// Skip all remaining data which was not part of the last ZipEntry
while (hashIn.read() != -1) {
hashIn.skip(Long.MAX_VALUE);
}
HashCode hashCode = hashIn.hash();
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
HashingInputStream (Guava: Google Core Libraries for Java ...
Reads the specified bytes of data from the underlying input stream and updates the hasher with the bytes read. void, reset(). reset() is...
Read more >guava/HashingInputStream.java at master - GitHub
mark() is not supported for HashingInputStream. *. * @return {@code false} always. */. @Override. public boolean markSupported() {. return false;. }.
Read more >Error converting InputStream to a BinaryValue| JBoss.org Content ...
In some cases, a non-blocking read (or skip) may appear to be blocked when it is merely slow, for example when reading large...
Read more >Robust skipping of data in a java.io.InputStream and its subtypes
I don't think we can get a really robust implementation because the skip() method contract is rather bizarre. For one thing, the behaviour...
Read more >Java example - HashingInputStreamTest.java ... - Alvin Alexander
This example Java source code file (HashingInputStreamTest.java) is included in ... hashinginputstream, hashinginputstreamtest, nullpointertester, override, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much! The case I described in the description of this issue shows one situation where it is desired that
skip()
hashes the data. Though maybe there are indeed cases where it is not.Regarding
DigestInputStream
, there is JDK-6587699 though there hasn’t been much activity.Our notes (from 2013!) give these points against hashing the skipped data:
Weighing against that was:
Also:
It’s entirely possible that even one user who did care could have shifted the decision.