code: public static byte[] toBinary(Object o) throws PageException {
  	if (o instanceof byte[]) return (byte[]) o;
  	else if (o instanceof ObjectWrap) return toBinary(((ObjectWrap) o).getEmbededObject(""));
  
  	else if (o instanceof InputStream) {
  	    ByteArrayOutputStream barr = new ByteArrayOutputStream();
  	    try {
  		IOUtil.copy((InputStream) o, barr, false, true);
  	    }
  	    catch (IOException e) {
  		throw ExpressionException.newInstance(e);
  	    }
  	    return barr.toByteArray();
  	}
  	// depending on extension Image
  	else if (o != null && o.getClass().getName().equals("org.lucee.extension.image.Image")) {
  	    return ImageUtil.getImageBytes(o, null);
  	}
  	else if (o instanceof BufferedImage) {
  	    return ImageUtil.getImageBytes((BufferedImage) o);
  	}
  	else if (o instanceof ByteArrayOutputStream) {
  	    return ((ByteArrayOutputStream) o).toByteArray();
  	}
  	else if (o instanceof Blob) {
  	    InputStream is = null;
  	    try {
  		is = ((Blob) o).getBinaryStream();
  		return IOUtil.toBytes(is);
  	    }
  	    catch (Exception e) {
  		throw new ExpressionException(e.getMessage());
  	    }
  	    finally {
  		IOUtil.closeEL(is);
  	    }
  	}
  	try {
  	    return Base64Encoder.decode(toString(o));
  	}
  	catch (PageException e) {
  	    throw new CasterException(o, "binary");
  	}
      }
docs: cast a Object to a Binary
  
  @param o Object to cast
  @return casted Binary
  @throws PageException