Here you can find the source of leftPadByteArray(byte[] source, int size)
Parameter | Description |
---|---|
source | Source array |
size | The final byte array size |
null
if the source array is to large
public static byte[] leftPadByteArray(byte[] source, int size)
//package com.java2s; /**/*from w w w .j av a 2s. c o m*/ * Copyright (c) 2010-2017 by the respective copyright holders. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Left pad byte array to a byte array with given size. * * @param source Source array * @param size The final byte array size * @return The new byte arrray or <code>null</code> if the source array is to large */ public static byte[] leftPadByteArray(byte[] source, int size) { byte[] bs = new byte[size]; if (size < source.length) { return null; } int startPos = size - source.length; System.arraycopy(source, 0, bs, startPos, source.length); return bs; } }