Converts an object to byte array.

@param val The object to convert.
@return The byte array representation of the object.
@throws IOException If the buffer is not enough to make the conversion.
965377
protected final synchronized byte[] objectToArray(Object val) throws IOException {
        final ByteArrayOutputStream bos = new InitiallyReusableByteArrayOutputStream(getReusableByteBuffer());
        final ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(val);

        return bos.toByteArray();
    }
1103220
public static byte[] serialize( Object obj ) throws IOException {
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            ObjectOutputStream out = new ObjectOutputStream(bos);
            out.writeObject(obj);
            out.close();
            return bos.toByteArray();
        }
    }
445771
public static byte[] serialize(final Serializable object) {
        val outBytes = new ByteArrayOutputStream();
        serialize(object, outBytes);
        return outBytes.toByteArray();
    }
1182540
public static byte[] serialize(Object obj) throws IOException {
    if (obj == null) {
      return null;
    }
    try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
      try (ObjectOutputStream o = new ObjectOutputStream(b)) {
        o.writeObject(obj);
      }
      return b.toByteArray();
    }
  }
696176
private int[] toArray(int val) {
        int[] ret = new int[4];
        for (int j = 3; j >= 0; --j) {
            ret[j] |= ((val >>> 8*(3-j)) & (0xff));
        }
        return ret;
    }
601543
private int getByteLength(final Object val) {
		if (val == null) {
			return 4;
		}
		String str = val.toString();
		try {
			int len = str.getBytes(ENCODING_SHIFT_JIS).length;
			return len <= 200 ? len : 200;
		} catch (UnsupportedEncodingException ex) {
			return 1;
		}
	}
196773
private static Object[] toObjectArray(Object val){
        if (val instanceof Object[])
            return (Object[])val;
        int arrayLength = java.lang.reflect.Array.getLength(val);
        Object[] outputArray = new Object[arrayLength];
        for(int i = 0; i < arrayLength; ++i){
            outputArray[i] = java.lang.reflect.Array.get(val, i);
        }
        return outputArray;
    }
1214393
public static void fill(byte[] a, byte val) {
        for (int i = 0, len = a.length; i < len; i++)
            a[i] = val;
    }
380378
public static String fromISODateTimeUTCtoRfc822(final String val) throws BadDateException {
    try {
      synchronized (isoDateTimeUTCFormat) {
        return rfc822Date(isoDateTimeUTCFormat.parse(val));
      }
    } catch (Throwable t) {
      throw new BadDateException();
    }
  }
1089751
public static void addString(ByteBuffer buffer, String val)
  {
    addBytes(buffer, StringUtils.toUtf8(val));
  }
557203
public void
writeU16(int val) {
	check(val, 16);
	need(2);
	array[pos++] = (byte)((val >>> 8) & 0xFF);
	array[pos++] = (byte)(val & 0xFF);
}
1323113
public static Object toPrimitiveArray(Object val) {
        if (val instanceof Boolean[]) {
            int len = Array.getLength(val);
            boolean[] arr = new boolean[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Boolean)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Byte[]) {
            int len = Array.getLength(val);
            byte[] arr = new byte[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Byte)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Character[]) {
            int len = Array.getLength(val);
            char[] arr = new char[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Character)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Short[]) {
            int len = Array.getLength(val);
            short[] arr = new short[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Short)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Integer[]) {
            int len = Array.getLength(val);
            int[] arr = new int[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Integer)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Long[]) {
            int len = Array.getLength(val);
            long[] arr = new long[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Long)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Float[]) {
            int len = Array.getLength(val);
            float[] arr = new float[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Float)Array.get(val, i);
            }
            return arr;
        } else if (val instanceof Double[]) {
            int len = Array.getLength(val);
            double[] arr = new double[len];
            for (int i = 0; i < len; i++) {
                arr[i] = (Double)Array.get(val, i);
            }
            return arr;
        } else {
            return null;
        }
    }
1323954
private void write(final int val)
		throws EncodingException
	{

		if (val < 0 || val > 255) {
			throw ErrorFactory.createEncodingException(
					ErrorKeys.DIFFTOOL_ENCODING_VALUE_OUT_OF_RANGE,
					"byte value out of range: " + val);
		}

		this.stream.write(val);
	}
1355172
@Override
    public byte[] toBytes(Object object)
    {
        Short s = null;
        if (object != null)
        {

            if (object.getClass().isAssignableFrom(String.class))
            {
                s = Short.valueOf(object.toString());
            }
            else
            {
                s = (Short) object;
            }
            return new byte[] { (byte) ((s >> 8) & 0xff), (byte) ((s >> 0) & 0xff), };
        }
        return null;
    }
72165
function castBuffer (val) {
  if (Buffer.isBuffer(val)) {
    return val
  }

  val = toJSON(val)
  var args = assertArgs([val], {
    val: ['string', 'array', 'object', 'number', 'boolean']
  })
  val = args.val

  var str

  if (Array.isArray(val)) {
    val = val.map(toJSON)
    str = JSON.stringify(val)
  } else if (isObject(val)) {
    val = toJSON(val)
    str = JSON.stringify(val)
  } else { // val is a string, number, or boolean
    str = val + ''
  }

  return new Buffer(str)
}
265298
def array_to_binary(val)
      saved_object_count = @written_object_count
      @written_object_count += 1
      #@object_refs += val.value.size

      values = val.value.map { |v| v.to_binary(self) }
      bdata = Binary.type_bytes(0b1010, val.value.size) <<
        Binary.pack_int_array_with_size(object_ref_size(@object_refs),
                                        values)

      @object_table[saved_object_count] = bdata
      saved_object_count
    end
457833
public static final byte[] serializeToBytes(final Object object) {
    if (object == null)
      throw new IllegalArgumentException("Object was null");
    try {
      return jsonMapper.writeValueAsBytes(object);
    } catch (JsonProcessingException e) {
      throw new JSONException(e);
    }
  }