Closed GoogleCodeExporter closed 9 years ago
Revision: added Preconditions.checkNotNull() at the top of all methods
accepting a reference argument, so that those don't get converted to
ClosedChannelException.
I did not add this to the ctors, as that's arguably a valid use case (the
stream is closed already at constructor time). That check could be added if
desired, though.
Original comment by tv@duh.org
on 5 Apr 2011 at 5:39
Attachments:
I don't know if the ByteBufferDataInputStream is the way we want to address the
problem or not, but we do want to make sure that *something* is covering this
use case properly.
Original comment by kevinb@google.com
on 13 Jul 2011 at 7:43
Original comment by cpov...@google.com
on 13 Jul 2011 at 7:43
It seemed to be the natural place to offer this conversion. Channels are
already convertible to stream via the static methods in
java.nio.channel.Channels, but there's no prefab way to convert a buffer (such
as would be obtained when mmap'ing a file).
Nobody is required to use the DataInput/DataOutput interfaces; I added them as
a logical-to-me extension, because a ByteBuffer already has notions of
endianness and data conversion built-in. They function fine as bare
{Input,Output}Stream instances too.
Original comment by tv@duh.org
on 13 Jul 2011 at 7:50
Original comment by fry@google.com
on 10 Dec 2011 at 4:04
Original comment by kevinb@google.com
on 30 May 2012 at 7:43
A few things about the implementation of the InputStream as given.
First, it is trivial to support the mark/reset/markSupported operations. Might
as well throw them in.
Also, it might be nice to have the classes extend Buffered{Input,Output}Stream.
Because they are in fact buffered.
There is an issue with those pesky superclass fields, though. If you don't mind
extra ints/null references hanging around, then you can use this constructor:
ByteBufferInputStream(ByteBuffer buffer) {
super(null, 1);
this.buf = buffer;
super.buf = null;
}
Original comment by michael....@gmail.com
on 24 Dec 2012 at 11:48
As for mark/reset, I actually have no idea why I didn't implement those.
Probably an oversight. Yes, they can be implemented.
On subclassing: I chose Data{Input,Output}Stream as those classes are
well-known to a lot of third party code, and are actually used in the method
signatures of some methods. (Sure, in theory they should use generics, e.g. <?
extends DataInput & Flushable & Closeable>, but that's still not commonplace.
Plenty of code directly requests a Data*Stream.)
I've yet to see any code that actually cares about seeing a BufferedInputStream
or BufferedOutputStream -- these seem only useful as add-in layers to implement
buffering under the hood, not as a capability-marking class. I think it would
be a bit of a mistake to extend those, since the superclass's buffering isn't
going to be used anyway.
Original comment by tv@duh.org
on 24 Dec 2012 at 9:17
I'm not sold on the BufferedInputStream either, I was just implementing a
ByteSource based on an array of ByteBuffers and had just coded up
BufferInputStream when I noticed ByteSource has openBufferedStream(). I was
just throwing the idea out there.
I think good use would check for markSupported() instead of instanceof
BufferedInputStream; but then again, ByteSource doesn't.
Original comment by michael....@gmail.com
on 24 Dec 2012 at 10:07
I find it strange that these classes don't do more to manager the mark, e.g., I
would have expected the byte buffer to be exactly as it was, mark and all,
after closing the input stream
Original comment by pjul...@gmail.com
on 2 Feb 2013 at 4:54
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
tv@duh.org
on 5 Apr 2011 at 5:34Attachments: