Here you can find the source of toBytes(Byte[] values)
public static byte[] toBytes(Byte[] values)
//package com.java2s; //License from project: Open Source License public class Main { public static final byte DEFAULT_BYTE = 0; public static byte[] toBytes(Byte[] values) { return toBytes(values, DEFAULT_BYTE); }/*from w w w .ja va 2s .co m*/ public static byte[] toBytes(Byte[] values, int defaultValue) { byte[] results = new byte[0]; if (values != null) { results = new byte[values.length]; for (int i = 0; i < results.length; i++) { Byte element = values[i]; try { results[i] = (element != null ? element.byteValue() : (byte) defaultValue); } catch (Exception ex) { // ex.printStackTrace(); } } } return results; } public static Byte[] toBytes(byte[] values) { return toBytes(values, DEFAULT_BYTE); } public static Byte[] toBytes(byte[] values, int defaultValue) { Byte[] results = new Byte[0]; if (values != null) { results = new Byte[values.length]; for (int i = 0; i < results.length; i++) { byte element = values[i]; try { results[i] = new Byte(element); } catch (Exception ex) { results[i] = (byte) defaultValue; // ex.printStackTrace(); } } } return results; } }