Java Long to Byte Array longToBytes(long l, byte[] data, int[] offset)

Here you can find the source of longToBytes(long l, byte[] data, int[] offset)

Description

Write the bytes representing l into the byte array data, starting at index offset [0], and increment offset [0] by the number of bytes written; if data == null, increment offset [0] by the number of bytes that would have been written otherwise.

License

Open Source License

Parameter

Parameter Description
l the <code>long</code> to encode
data The byte array to store into, or <code>null</code>.
offset A single element array whose first element is the index in data to begin writing at on function entry, and which on function exit has been incremented by the number of bytes written.

Declaration

public static final void longToBytes(long l, byte[] data, int[] offset) 

Method Source Code

//package com.java2s;
/*//from  ww w  .ja  v a2 s.c o m
 * JGrass - Free Open Source Java GIS http://www.jgrass.org 
 * (C) HydroloGIS - www.hydrologis.com 
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Library General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 * 
 * This library 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 Library General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Library General Public License
 * along with this library; if not, write to the Free Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

public class Main {
    public static final int SIZE_LONG = 8;

    /**
     * Write the bytes representing <code>l</code> into the byte array
     * <code>data</code>, starting at index <code>offset [0]</code>, and
     * increment <code>offset [0]</code> by the number of bytes written; if
     * <code>data == null</code>, increment <code>offset [0]</code> by the
     * number of bytes that would have been written otherwise.
     *
     * @param l the <code>long</code> to encode
     * @param data The byte array to store into, or <code>null</code>.
     * @param offset A single element array whose first element is the index in
     *         data to begin writing at on function entry, and which on
     *         function exit has been incremented by the number of bytes
     *         written.
     */
    public static final void longToBytes(long l, byte[] data, int[] offset) {
        /**
         * TODO: We use network-order within OceanStore, but temporarily
         * supporting intel-order to work with some JNI code until JNI code is
         * set to interoperate with network-order.
         */
        if (data != null) {
            for (int j = (offset[0] + SIZE_LONG) - 1; j >= offset[0]; --j) {
                data[j] = (byte) l;
                l >>= 8;
            }
        }

        offset[0] += SIZE_LONG;
    }
}

Related

  1. longToBytes(long l)
  2. longToBytes(long l)
  3. longToBytes(long l, byte[] arr, int startIdx)
  4. longToBytes(long l, byte[] b)
  5. longToBytes(long l, byte[] bytes, int offset)
  6. longToBytes(long l, byte[] result)
  7. longToBytes(long ldata, int n)
  8. longToBytes(long lnum, byte[] bytes, int startIndex)
  9. longToBytes(long n)