[
https://issues.apache.org/jira/browse/LANG-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15698672#comment-15698672
]
ASF GitHub Bot commented on LANG-341:
-------------------------------------
Github user yurelle commented on the issue:
https://github.com/apache/commons-lang/pull/219
I got a little carried away; this PR is 4,500 lines. I'm sure this is
probably going to take quite a while to validate and get accepted into the code
base. I'm just glad I could get the ball rolling. If someone could check on my
big/little endian implementations, I'd appreciate it. I can never keep those
straight. I went off of these references:
https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html
https://en.wikipedia.org/wiki/Endianness
https://en.wikipedia.org/wiki/Bit_numbering
I'm not sure why it's saying that test coverage went down. As far as I can
tell, I've got tests for all my new functions.
One thing to note: in all my new functions that had a pre-existing
alternate implementation, I added a chunk in the unit test to compare my
results with the existing implementation. However, I had some trouble getting
proper data out of the pre-existing hexToPrimitive() functions. The test code
to do this validation is in the JUnit functions, but it's commented out. I'm
probably just not understanding the existing implementation properly.
> Add number to byte array methods
> --------------------------------
>
> Key: LANG-341
> URL: https://issues.apache.org/jira/browse/LANG-341
> Project: Commons Lang
> Issue Type: New Feature
> Components: lang.*
> Reporter: Lilianne E. Blaze
> Fix For: Discussion
>
> Attachments: 341-v1-src.patch, 341-v1-test.patch, LANG-341-2.patch,
> LANG-341.patch
>
>
> Hello,
> I need a set of methods to convert Long to or from a byte[] array, as if
> writing / reading from Data(Input/Output)Stream(
> ByteArray(Input/Output)Stream ).
> First, doing it with Streams seems a bit wasteful, second, it seems a
> pretty general use. Would it be possible to add something like that to,
> for example,
> org.apache.commons.lang.math.NumberUtils?
> Example code:
> {code:java}
> static public long toLong(byte[] b)
> {
> return toLong(b, 0);
> }
>
> static public long toLong(byte[] b, int offset)
> {
> return (((long)b[offset] << 56) +
> ((long)(b[offset + 1] & 255) << 48) +
> ((long)(b[offset + 2] & 255) << 40) +
> ((long)(b[offset + 3] & 255) << 32) +
> ((long)(b[offset + 4] & 255) << 24) +
> ((b[offset + 5] & 255) << 16) +
> ((b[offset + 6] & 255) << 8) +
> ((b[offset + 7] & 255) << 0));
> }
>
> static public byte[] longToByteArray(long l)
> {
> byte b[] = new byte[8];
> longToByteArray(l, b, 0);
> return b;
> }
>
> static public void longToByteArray(long l, byte b[], int offset)
> {
> b[offset] = (byte)(l >>> 56);
> b[offset + 1] = (byte)(l >>> 48);
> b[offset + 2] = (byte)(l >>> 40);
> b[offset + 3] = (byte)(l >>> 32);
> b[offset + 4] = (byte)(l >>> 24);
> b[offset + 5] = (byte)(l >>> 16);
> b[offset + 6] = (byte)(l >>> 8);
> b[offset + 7] = (byte)(l >>> 0);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)