This post is up to 100% helpful to everyone!

I love the expression “up-to”. When marketing folks die and enter the afterlife, presumably it’s up to 100% heaven. The nice thing about “up to” is that it encompasses the null set of whatever range it is cast upon. Up to 99% success rate could very well be 0% success rate since it satisfies the idiomatic condition.

Anyway, so I was coding in Java the other day and ran into a decent candidate for the WTF files.

I was doing this un-encryption thing, where I was reading a file and un-encrypting it using the specified key. Pretty basic stuff.

I was using the CypherInputStream class to read the file stream and decrypt it. I user CypherInputStream.read method and everything was dandy until in my testing I noticed that a portion of the file remained encrypted.

According to the documentation, CypherInputStream.read (…) method takes a byte array as a parameter and “Reads the next b.length bytes from this input stream into buffer b.”

ORLY?!

Well, turns out that documentation excerpt is a lie. What it should read is “Reads the Up To next b.length bytes from this input stream into buffer
b.”

So in my case, I knew I allocated an array sufficient to read the entire file, but the number of bytes read was arbitraritly smaller. The solution, of course, is to use the old-school socket read approach and read the bytes from the buffer while the number of bytes read is >=0 etc.

But you know.. C# called and they want you to implement ReadAllBytes method, because really it’s a rare occasion that someone would want just part of the stream. So why make us write redundant code?

Cheers!