Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions railo-java/railo-core/src/railo/runtime/coder/HexCoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package railo.runtime.coder;

import org.apache.commons.codec.binary.Hex;

import railo.commons.io.CharsetUtil;


Expand All @@ -14,19 +16,7 @@ public final class HexCoder {
* @return encoed String
*/
public static String encode(byte[] bytes) {
String retorno = "";
if (bytes==null || bytes.length==0) {
return retorno;
}
for (int i=0; i<bytes.length; i++) {
byte valor = bytes[i];
int d1 = valor & 0xF;
d1 += (d1 < 10) ? 48 : 55;
int d2 = (valor & 0xF0) >> 4;
d2 += (d2 < 10) ? 48 : 55;
retorno = retorno + (char)d2 + (char)d1;
}
return retorno;
return Hex.encodeHexString(bytes).toUpperCase();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/testcases/functions/BinaryEncode.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
component extends="org.railo.cfml.test.RailoTestCase" {

public function setUp() {
variables.emptyBinary = CharsetDecode("", "utf-8");
variables.binaryHello = CharsetDecode("Hello", "utf-8");
}

function testHex() {
$assert.isEqualWithCase("", BinaryEncode(variables.emptyBinary, "hex"));
$assert.isEqualWithCase("48656C6C6F", BinaryEncode(variables.binaryHello, "hex"));
}

}