Java Byte Array Create toBytes(long... values)

Here you can find the source of toBytes(long... values)

Description

to Bytes

License

Open Source License

Declaration

public static byte[] toBytes(long... values) 

Method Source Code

//package com.java2s;
/**/*from   w w  w.  j  a  v a  2s  .  com*/
 * Copyright (c) 2002-2013 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static byte[] toBytes(long... values) {
        byte[] array = new byte[8 * values.length];
        for (int i = 0; i < values.length; i++) {
            toBytes(values[i], array, 8 * i);
        }
        return array;
    }

    public static byte[] toBytes(long value) {
        return toBytes(value, new byte[8], 0);
    }

    public static byte[] toBytes(long value, byte[] target, int offset) {
        for (int i = 0; i < 8; i++) {
            target[7 - i + offset] = (byte) (value >>> (i * 8));
        }
        return target;
    }
}

Related

  1. toBytes(long val)
  2. toBytes(long value)
  3. toBytes(long value)
  4. toBytes(long value)
  5. toBytes(long value, int numBytes)
  6. toBytes(Object objValue)
  7. toBytes(Object value)
  8. toBytes(short s)
  9. toBytes(short s)