Java Array Truncate truncateLeft(byte[] b1, int bytes)

Here you can find the source of truncateLeft(byte[] b1, int bytes)

Description

Truncate number of bytes from the left of a byte-array

License

Open Source License

Parameter

Parameter Description
b1 the byte-array
bytes the number of bytes to truncate

Return

the resulting new byte-array (new length is b1.length - bytes)

Declaration

public static byte[] truncateLeft(byte[] b1, int bytes) 

Method Source Code

//package com.java2s;
/**//from  ww  w  .j  av  a  2  s  . c  o  m
 * Hoofprints - An Extensible Testbed for Route-Servers
 * Copyright (C) 2009 Sebastian Spies
 * 
 * This program 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 {
    /**
     * Truncate number of bytes from the left of a byte-array
     * 
     * @param b1 the byte-array
     * @param bytes the number of bytes to truncate
     * @return the resulting new byte-array (new length is b1.length - bytes)
     */
    public static byte[] truncateLeft(byte[] b1, int bytes) {
        int restBytesLength = b1.length - bytes;
        byte[] b2 = new byte[restBytesLength];
        System.arraycopy(b1, bytes, b2, 0, restBytesLength);
        return b2;
    }
}

Related

  1. truncateBytes(byte[] inputBytes)
  2. truncateByteSegment(byte[] byteSegment, int toSize)
  3. truncateData(byte[] data, int numOfBytes)
  4. truncateHashToLong(byte[] bytes)
  5. truncateI(long[] v, int len)