Java Byte Array Copy copyBytes(byte[] results, int offset, int int32)

Here you can find the source of copyBytes(byte[] results, int offset, int int32)

Description

copy Bytes

License

Open Source License

Declaration

public static void copyBytes(byte[] results, int offset, int int32) 

Method Source Code

//package com.java2s;
/*   Copyright (C) 2011 Marius C. Silaghi
  Author: Marius Silaghi: msilaghi@fit.edu
  Florida Tech, Human Decision Support Systems Laboratory
       //from w w w .j  ava2 s.com
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation; either the current version 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 Affero General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */

public class Main {
    public static void copyBytes(byte[] results, int offset, int int32) {
        //System.err.println("will copy bytes off "+offset);
        byte[] src = new byte[4];
        src[0] = (byte) (int32 & 0xff);
        src[1] = (byte) ((int32 >> 8) & 0xff);
        src[2] = (byte) ((int32 >> 16) & 0xff);
        src[3] = (byte) ((int32 >> 24) & 0xff);
        copyBytes(results, offset, src, 4, 0);
    }

    public static void copyBytes(byte[] results, int offset, short int16) {
        byte[] src = new byte[2];
        src[0] = (byte) (int16 & 0xff);
        src[1] = (byte) ((int16 >> 8) & 0xff);
        copyBytes(results, offset, src, 2, 0);
    }

    public static void copyBytes(byte[] results, int offset, byte[] src, int length) {
        copyBytes(results, offset, src, length, 0);
    }

    public static void copyBytes(byte[] results, int offset, byte[] src, int length, int src_offset) {
        if (results.length < length + offset)
            System.err.println("Destination too short: " + results.length + " vs " + offset + "+" + length);
        if (src.length < length + src_offset)
            System.err.println("Source too short: " + src.length + " vs " + src_offset + "+" + length);

        for (int k = 0; k < length; k++) {
            results[k + offset] = src[src_offset + k];
        }
    }
}

Related

  1. copyBytes(byte[] arr, int length)
  2. copyBytes(byte[] dst, int dstPos, int value)
  3. copyBytes(byte[] dstBytes, int dstFrom, byte[] srcBytes, int srcFrom, int len)
  4. copyBytes(byte[] from, byte[] to, int fromIndex)
  5. copyBytes(byte[] from, int offset, int len)
  6. copyBytes(byte[] source, byte[] dest, int sourceFrom, int copyLength, int destFrom)
  7. copyBytes(byte[] src)
  8. copyBytes(byte[] src, byte[] target)
  9. copyBytes(byte[] src, int start, int end)