CFLib.org – Common Function Library Project

createByteArray(string)

Last updated August 17, 2012

author

Marcos Placona

Version: 1 | Requires: CF6 | Library: StrLib

Description:
When using Java classes, you sometimes need to pass in Java byte arrays. ColdFusion can't do it out of the box, but with this UDF, you can turn a string into a Java byte array.

Return Values:
Returns a byte array

Example:

<cfset myString = "CFLib.org">
<cfset myByteArray= createByteArray(myString)>

Parameters:

Name Description Required
string A string to convert to a byte array Yes

Full UDF Source:

/**
 * Converts a ColdFusion string to a Java byte array
 * * version 1.0 by Marcos Placona
 * 
 * @param string      A string to convert to a byte array (Required)
 * @return Returns a byte array 
 * @author Marcos Placona (marcos.placona@gmail.com) 
 * @version 1.0, August 17, 2012 
 */
function createByteArray(string){
    var objString = createObject("Java", "java.lang.String").init(JavaCast("string", string));
    return objString.getBytes();
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson