On Thu, 21 Aug 2025 16:54:56 GMT, Andy Goryachev <ango...@openjdk.org> wrote:
> re: closing stream > > I wonder if we should close the stream in both sync and async variants (and > document that). I would say there should be no reason not to close - > suggesting that if the application wants not to close it's surely a bad > choice for the application. > > For example, one can think of a situation where multiple images are stored > within the same stream, but there should be a reliable way for the > application to specify the size of each image (and then the app can provide a > derived InputStream which EOFs when the end of an image is reached). > > Another alternative is to add another boolean `closeStream`. > > What do you think? It's unusual to close the stream when you're not the owner (although some API's do that, they are often obscure and not used that much). Changing this behavior for the sync variant would be a breaking change, so I'm not sure we want to even go there. Adding another `boolean` is of course an option, but I think that if we're going for that route, going for a `Supplier` would be more clear API and more powerful (in the internal code, we basically already have that abstraction as it can abstract over both the URL and InputStream variants with just one API). If we go the `Supplier` route, we can probably also unify the URL and InputStream constructors to go through the same route, moving the URL opening logic into Image class and removing it from the internal code. ------------- PR Comment: https://git.openjdk.org/jfx/pull/1875#issuecomment-3211476249