Java Guid 转换为 Oracle Raw(16) 字符串

Java Guid Convert into Oracle Raw(16) String

如何将 JSON Guid 转换为 Oracle Raw(16) 字符串数据类型?

在 C# Net 中,它是使用 ToByteArray()

Java8 中的等价物是什么?

下面的网站会转换,但是我需要底层代码。

目标转换:A0824186-1E9C-AE47-95E1-1431542C2133 到字符串 864182A09C1E47AE95E11431542C2133

https://robobunny.com/cgi-bin/guid

网络解决方案参考:Convert from Oracle's RAW(16) to .NET's GUID

更新:

有没有办法逆转这个功能?

另外,我看到了一些Java脚本源代码,也许想办法转换成Java

https://github.com/kanekotic/raw-guid-converter/blob/master/lib/guid-to-raw.js

const buffer = require('buffer/').Buffer,
    transform = require('./helpers').transform,
    patterns = require('./helpers').patterns

    
const convert = (raw) => {
    const pattern = /([0-9A-Fa-f]{8})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{12})/i
    let guid_parsed = transform(pattern, raw)
    return `${guid_parsed[0]}${guid_parsed[1]}${guid_parsed[2]}${guid_parsed[3]}${guid_parsed[4]}`.toUpperCase()   
 }
 
module.exports = convert

以下代码库将起作用:

private byte[] convertToOracleRaw(UUID uuid) {
    String uuidString = uuid.toString().replace("-", "").toUpperCase();
    String finalValue = "";
    finalValue += uuidString.substring(6,8);
    finalValue += uuidString.substring(4,6);
    finalValue += uuidString.substring(2,4);
    finalValue += uuidString.substring(0,2);
    finalValue += uuidString.substring(10,12);
    finalValue += uuidString.substring(8,10);
    finalValue += uuidString.substring(14,16);
    finalValue += uuidString.substring(12,14);
    finalValue += uuidString.substring(16,18);

    finalValue += uuidString.substring(18, uuidString.length());  // final string
    return DatatypeConverter.parseHexBinary(finalValue);  // in hex binary
}