Java Array Truncate truncateData(byte[] data, int numOfBytes)

Here you can find the source of truncateData(byte[] data, int numOfBytes)

Description

Truncates a byte array

License

Open Source License

Parameter

Parameter Description
data a parameter
read a parameter

Return

a shorter byte array

Declaration

private static byte[] truncateData(byte[] data, int numOfBytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w w  w  . ja  va2s  .com*/
     * Truncates a byte array
     * 
     * @param data
     * @param read
     * @return a shorter byte array
     */
    private static byte[] truncateData(byte[] data, int numOfBytes) {
        // shortcut
        if (data.length == numOfBytes) {
            return data;
        } else {
            byte[] truncated = new byte[numOfBytes];
            for (int i = 0; i < truncated.length; i++) {
                truncated[i] = data[i];
            }
            return truncated;
        }
    }
}

Related

  1. truncate(int[] values, int value)
  2. truncate(short[] value, int maxSize)
  3. truncateAndConvertToInt(long[] longArray)
  4. truncateBytes(byte[] inputBytes)
  5. truncateByteSegment(byte[] byteSegment, int toSize)
  6. truncateHashToLong(byte[] bytes)
  7. truncateI(long[] v, int len)
  8. truncateLeft(byte[] b1, int bytes)