rewrite-migrate-java
rewrite-migrate-java copied to clipboard
Support ByteStreams.toByteArray -> inputStream.readAllBytes()
Instead of Guava's ByteStreams#toByteArray(), InputStream.html#readAllBytes should be used. The latter is available since Java 9.
- String inputStr = new String(ByteStreams. toByteArray(inputStream), Charsets.UJTF_8);
+ String inputStr = new String(inputStream.readAllBytes()), Charsets.UJTF_8);
Should IMHO be doable with Refaster templates?
Indeed looks like a good candidate! I've moved the issue to rewrite-migrate-java since that's where we already have our other Guava recipes and the rewrite-templating dependency. I'm doubting if the recipe would even need the new String(... ) surrounding it. (anyone) welcome to give this a go! :)
I'm doubting if the recipe would even need the
new String(... )surrounding it.
Indeed, better to omit that and make the rule more generally applicable. :+1: I filed PicnicSupermarket/error-prone-support#963, but feel free to copy over to this repo. Sharing is caring ;)
Just be careful, this does not work under Android 9 & 10. I recently had the issue...
I'm doubting if the recipe would even need the
new String(... )surrounding it.Indeed, better to omit that and make the rule more generally applicable. 👍 I filed PicnicSupermarket/error-prone-support#963, but feel free to copy over to this repo. Sharing is caring ;)
Probably good to have our own copy here as well, to fit in with our no guava recipes. Thanks for the reference implementation @Stephan202 ! Would you want to add that here @koppor ? Then we can also run it at scale here.
Longer term we could look at adding Picnicsupermarket/error-prone-support as a dependency here and reference recipes from there in our composite yaml recipes, but that first needs a new release of EPS and some work on correctly attributing those recipes to the authors there. :)
but that first needs a new release of EPS
@rickie and I have started to talk about doing a new release. Could be a few weeks (lots of other stuff going on), but hopefully less!
Turns out we have an interesting challenge when we want to integrate this into rewrite-migrate-java, which still uses Java 8.
We might need to add a second source set of Refaster recipe classes does no make it into the the final jar, but do contribute the generated Java 8 runtime compatible recipes. 🤔 Fun corner case this. /cc @knutwannheden
Yes, this issue has also crossed my mind. And indeed I think we should be able to add a separate source set. Another question would be if this should somehow automatically add a precondition for the required Java version. We should be able to check that somehow. But that would be more of a nice-to-have, I think.
Neat; figured get start with that in https://github.com/openrewrite/rewrite-migrate-java/pull/399; Although come to think of it that might require us to complete https://github.com/openrewrite/rewrite-templating/pull/57 first
- https://github.com/openrewrite/rewrite-templating/pull/57