[
https://issues.apache.org/jira/browse/OAK-4057?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15166983#comment-15166983
]
Alex Parvulescu commented on OAK-4057:
--------------------------------------
I don't mean to stir up an old debate about the streams again (OAK-1188 and
OAK-956 were enjoyable reads), but in the case of the SegmentStream, the length
of the stream is known _in advance_ so returning the real available value is
_very_ cheap. [0]
Looking at the code, it seem the {{available}} method is really not on par with
{{read}} for example, plus the stream impl always tracks the current position.
So without making this a generic oak thing, I think we could provide better
support for the {{available}} method in the SegmentMk, with a simple change:
{code}
return (int) (length - position);
{code}
[~mduerig] thoughts? I can also provide a unit test, if that helps :)
the patch was also proposed in OAK-956, but I came to the same conclusion in
parallel before knowing about the mentioned issues.
[0]
https://github.com/apache/jackrabbit-oak/blob/trunk/oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentStream.java#L65
> available() in SegmentStream returning 0 for large files
> ---------------------------------------------------------
>
> Key: OAK-4057
> URL: https://issues.apache.org/jira/browse/OAK-4057
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: segmentmk
> Affects Versions: 1.3.15
> Reporter: Mandeep Gandhi
>
> Suppose I have a file in repository. I try to get input stream from the file
> as
> InputStream is =
> jcrContent.getProperty("jcr:data").getBinary().getStream();
> Now before building the document I want to check if the file is not empty by
> using using available API.
> Ideally this API is expected to return an estimate of the number of bytes
> that can be read (or skipped over) from this input stream without blocking by
> the next invocation of a method for this input
> streamfhttps://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#available()
> The API works fine for small files but for large ones it returns 0.
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)