More support for offset and length in methods operating on byte arrays
Magnus
magnus.eriksson at gmail.com
Thu Dec 14 06:10:02 UTC 2023
In the java libraries there are many methods that operate on byte arrays
that do not allow you to specify offset and length for the relevant data
instead forcing you to copy the relevant part to new arrays before using
the methods reducing performance - I am for instance struggling with this
in java.util.Base64 where the Encoders and Decoders lack a length parameter
(also an offset would have been great even though I don't need that in my
case).
In my system I adds data of unknown length to large buffers that in many
cases only will be partially filled and when I need to BASE64 encode data
in these buffers I now have to create new "right sized" byte arrays and
copy the relevant data from the larger buffer to the new byte array. This
is a waste of CPU time & memory access that I would be happy to avoid.
In this specific case of the Encoders there exists already internal methods
that accepts a length for the source buffer but these are private rather
than protected preventing me from simply creating a subclass that adds such
methods. Making JDK libraries a bit more subclassing friendly would also be
great :-)
As it stands now I have created by own implementation of the Base64 class
(from the JDK sources) that adds a method with the desired "length"
parameter for use in my project but this is obviously not a good solution
as I from now on needs to maintain this class and also misses out on
improvements made to the original JDK library version...
/Trist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231214/956a6a31/attachment-0001.htm>
More information about the core-libs-dev
mailing list