Here you can find the source of swapByteArray(byte[] source)
Parameter | Description |
---|---|
source | Byte array to swap. |
Parameter | Description |
---|---|
NullPointerException | if source == null. |
public static byte[] swapByteArray(byte[] source)
//package com.java2s; /**/*from ww w. ja va2s. c o m*/ * Copyright (c) 2014-2016 Digi International Inc., * All rights not expressly granted are reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. * * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 * ======================================================================= */ public class Main { /** * Swaps the given byte array order. * * @param source Byte array to swap. * * @return The swapped byte array. * * @throws NullPointerException if {@code source == null}. */ public static byte[] swapByteArray(byte[] source) { if (source == null) throw new NullPointerException("Source cannot be null."); if (source.length == 0) return new byte[0]; byte[] swapped = new byte[source.length]; for (int i = 0; i < source.length; i++) swapped[source.length - i - 1] = source[i]; return swapped; } }