You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2021/03/28 21:53:00 UTC

[jira] [Work logged] (LANG-341) Add number to byte array methods

     [ https://issues.apache.org/jira/browse/LANG-341?focusedWorklogId=573264&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-573264 ]

ASF GitHub Bot logged work on LANG-341:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 28/Mar/21 21:52
            Start Date: 28/Mar/21 21:52
    Worklog Time Spent: 10m 
      Work Description: coveralls edited a comment on pull request #219:
URL: https://github.com/apache/commons-lang/pull/219#issuecomment-263091411


   
   [![Coverage Status](https://coveralls.io/builds/38318037/badge)](https://coveralls.io/builds/38318037)
   
   Coverage decreased (-0.04%) to 94.899% when pulling **fee1f6fb628fc8361ae92687bbaa44044aabb986 on yurelle:LANG-341_AddNumToByteArrayMethods** into **d1e9e598c9bcbf91afa174fa9b6c2ef30bbc8157 on apache:master**.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 573264)
    Time Spent: 20m  (was: 10m)

> 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
>            Priority: Major
>             Fix For: Discussion
>
>         Attachments: 341-v1-src.patch, 341-v1-test.patch, LANG-341-2.patch, LANG-341.patch
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> 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
(v8.3.4#803005)