converting a Java ByteArray to a String and ColdFusion Variable

I have been working a lot with Java and in particular the svnkit java API for SubVersion, this was all started with the cfdiff project from Rick Osborne. One of the things that has had me troubled for a while is viewing the contents of a file at a particular revision. The SVNKit returns a […]

I have been working a lot with Java and in particular the svnkit java API for SubVersion, this was all started with the cfdiff project from Rick Osborne. One of the things that has had me troubled for a while is viewing the contents of a file at a particular revision. The SVNKit returns a Java ByteArray:

I discovered that this will output the contents of the file and that revision. Not a problem. But I need to do some manipulation on it before it goes out, so lets try and replace the < and > with < >.

Amazingly this does nothing at all, the replace doesn’t seem to get fired. Trying the replace on the variable rather than the stream results in a CF error, because it is trying to complete a string operation on a ByteArray

However if you want to actually manipulate that data before its pushed to the browser you would want it in a variable. A suggestion came up on CFaussie to try this:

The result here is that java pushes the stream to the browser where the pageOut.write is, NOT in the Test variable output. Test actually gets set but doesnt contain anything so doesnt throw an error. I didnt have much to go on so set about seeing if Java could convert a ByteArray a String. Thankfully it can, and very easily. Double thanks to cf for making it easy to apply the string to a variable.

Duncan Isaksen-Loxton

Educated as a web developer, with over 20 years of internet based work and experience, Duncan is a Google Workspace Certified Collaboration Engineer and a WordPress expert.
Login
Log in below to access your courses.
Log In With Google
Forgot Password
Enter your email address or username and we’ll send you instructions to reset your password.