Why doesn't ByteArrayOutputStream overrride the write(byte[]) method?

669 views Asked by At

Why doesn't ByteArrayOutputStream override the OutputStream.write(byte[] b) method? It only overrides the write(byte[] b, int off, int len) version taking an offset and length.

Of course, the existing implementation for the write(byte[] b) method in OutputStream simply delegates to the other method with offset == 0 and len == b.length, so it "works" but not well because now baos.write(byteArray) is declared to throw IOException even though it can never throw such an exception.

For methods that actually take ByteArrayOutputStream (or otherwise have an IOException-free specialized path, perhaps by casting) this means you are stuck using the long-form write(). It's not a fatal flow - but is there any good reason not to have this method overridden? Is there any reason it can't happen in a future JDK (edit: yes, there are good reasons, see the comments)?

0

There are 0 answers