-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CharSource.asByteSource(...).openStream() does not implement InputStream.available() #5377
Comments
Additionally I think this check will always be guava/guava/src/com/google/common/io/ReaderInputStream.java Lines 153 to 154 in c9f4b9f
If guava/guava/src/com/google/common/io/ReaderInputStream.java Lines 171 to 173 in c9f4b9f
Therefore that other |
Something you don't explain in this issue that I'm curious about is why you want this stream to implement
Do you have a specific use case for this? |
My rationale was that if an It would be possible to implement a 'lite' version which only covers certain cases but is greatly simplified. However, it might not be worth having an public int available() {
if (draining) {
return byteBuffer.remaining();
}
return 0;
} |
The
InputStream
returned byCharSource.asByteSource(...).openStream()
(i.e. internal classReaderInputStream
) does not implementInputStream.available()
.Example:
Possible implementation:
com.google.common.io.ReaderInputStream.byteBuffer
is non empty, itsremaining()
value can be returnedcom.google.common.io.ReaderInputStream.charBuffer
Though note that even if buffer is not empty it might require more chars, e.g. when it only contains high surrogate and is missing low surrogate
com.google.common.io.ReaderInputStream.reader
isready()
and if so callreader.read()
(otherread(...)
methods might block?); afterwards repeat steps aboveThough the above might be pretty inefficient in case someone repeatedly calls
available()
because it would then only encode one (or at most two) char(s) at a time. However,java.io.Reader.ready()
sadly only guarantees thatread()
won't block. Therefore there might be implementations whose otherread(...)
methods might block so encoding more chars would not be possible.The text was updated successfully, but these errors were encountered: