code: public static byte[] toByteArray(Object o, ByteOrder bo) {
      if (o instanceof Byte) return new byte[] { (Byte) o };
      if (o instanceof Short)
        return ByteBuffer.allocate(2).order(bo).putShort((Short) o).array();
      if (o instanceof Integer)
        return ByteBuffer.allocate(4).order(bo).putInt((Integer) o).array();
      if (o instanceof Long)
        return ByteBuffer.allocate(8).order(bo).putLong((Long) o).array();
      if (o instanceof Float)
        return ByteBuffer.allocate(4).order(bo).putFloat((Float) o).array();
      if (o instanceof Double)
        return ByteBuffer.allocate(8).order(bo).putDouble((Double) o).array();
      if (o instanceof Boolean)
        return (Boolean) o ? new byte[] { '\1' } : new byte[] { '\0' };
      if (o instanceof Character)
        return ByteBuffer.allocate(2).order(bo).putChar((Character) o).array();
  
      try {
        Class<?> c = o.getClass();
        Method mothod = null;
        for (Method m : c.getMethods()) {
          if (m.getReturnType() == byte[].class
              && m.getParameterTypes().length == 0)
            mothod = m;
        }
        return (byte[]) mothod.invoke(o);
      } catch (Exception e) {
        logger.log(Level.SEVERE, null, e);
        throw new TypeConstraintException("TypeError: no implicit conversion of "
            + (o == null ? null : o.getClass().getName()) + " into byte[]");
      }
    }
docs: Converts an Object into a byte array. ByteOrder only affects on Java
  Number. If this Object is not a Java primitive wrapper Object, a reflection
  will be performed to search any method which returns a byte[] and call it
  directly. Under this circumstance, the ByteOrder won't take effect too.
  
  @param o
  an Object
  @param bo
  a ByteOrder
  @return byte array
  @throws TypeConstraintException
  if the Object can't be converted into bytes