Java Object Create toObject(byte[] byteArray)

Here you can find the source of toObject(byte[] byteArray)

Description

Converts an array of primitive bytes to objects.

License

Open Source License

Parameter

Parameter Description
byteArray a byte array.

Return

a Byte array, null if null array input.

Declaration

public static Byte[] toObject(byte[] byteArray) 

Method Source Code

//package com.java2s;
/**//from   www. j ava  2s .  c o  m
 * Copyright (c) 2011-2014 INRIA.
 * 
 * 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 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 Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 **/

public class Main {
    /**
     * Converts an array of primitive bytes to objects.
     * 
     * This method returns {@code null} for a {@code null} input array.
     * 
     * @param byteArray
     *            a byte array.
     * 
     * @return a {@code Byte} array, {@code null} if null array input.
     */
    public static Byte[] toObject(byte[] byteArray) {
        if (byteArray == null) {
            return null;
        }

        Byte[] box = new Byte[byteArray.length];
        for (int i = 0; i < box.length; i++) {
            box[i] = byteArray[i];
        }
        return box;
    }
}

Related

  1. as(Object obj)
  2. as(Object value, Class c)
  3. as(Object value, Class type)
  4. toObject(boolean[] array)
  5. toObject(byte[] array)
  6. toObject(byte[] primitiveArray)
  7. toObject(Class clazz, String value)
  8. toObject(double[] a)
  9. toObject(final int i)