Java Guid Convert into Oracle Raw(16) String
Asked Answered
D

1

0

How do I convert a JSON Guid to Oracle Raw(16) String Data Type?

In C# Net, it is Using ToByteArray().

What is the equivalent in Java 8?

The following website will convert, however I need underlying code.

Goal Convert: A0824186-1E9C-AE47-95E1-1431542C2133 to string 864182A09C1E47AE95E11431542C2133

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

  • Standard: A0824186-1E9C-AE47-95E1-1431542C2133
  • Bracketed: {A0824186-1E9C-AE47-95E1-1431542C2133}
  • Oracle RAW(16) format: 864182A09C1E47AE95E11431542C2133
  • Oracle hextoraw HEXTORAW('864182A09C1E47AE95E11431542C2133')
  • SQLServer using Oracle byte order: 0x864182A09C1E47AE95E11431542C2133

Net Solution Reference: Convert from Oracle's RAW(16) to .NET's GUID

Update:

Is there a way to reverse this function? ORACLE RAW in string format to Standard GUID https://mcmap.net/q/831814/-oracle-raw-in-string-format-to-standard-guid

Also, I saw some Javascript source code, maybe find a way to convert into 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
Desrochers answered 23/8, 2021 at 2:33 Comment(0)
D
0

This following code base will work:

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
}
Desrochers answered 24/8, 2021 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.