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();
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson