Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A030C200BD9 for ; Thu, 24 Nov 2016 19:50:03 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9F0D3160AFB; Thu, 24 Nov 2016 18:50:03 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E976E160B20 for ; Thu, 24 Nov 2016 19:50:02 +0100 (CET) Received: (qmail 21791 invoked by uid 500); 24 Nov 2016 18:50:01 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 21184 invoked by uid 99); 24 Nov 2016 18:50:01 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2016 18:50:01 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 6DA452C03E0 for ; Thu, 24 Nov 2016 18:49:58 +0000 (UTC) Date: Thu, 24 Nov 2016 18:49:58 +0000 (UTC) From: "Gary Gregory (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (LANG-341) Add number to byte array methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 24 Nov 2016 18:50:03 -0000 [ https://issues.apache.org/jira/browse/LANG-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15694008#comment-15694008 ] Gary Gregory edited comment on LANG-341 at 11/24/16 6:49 PM: ------------------------------------------------------------- The best way to start moving this ticket forward again is to make sure the patch applies against our Git master branch and that the new code has as close to 100% code coverage. was (Author: garydgregory): The best way to start moving the forward again is to make sure the patch applies against our Git master branch and that the new code has as close to 100% code coverage. > 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)