forked from apache/eventmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
14 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...nector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/common/EnumeratedValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.apache.eventmesh.connector.jdbc.common; | ||
|
||
public interface EnumeratedValue<T> { | ||
|
||
T getValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...onnector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/utils/ByteArrayUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.apache.eventmesh.connector.jdbc.utils; | ||
|
||
public class ByteArrayUtils { | ||
private static final char[] HEX_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; | ||
|
||
/** | ||
* Converts a byte array into a hexadecimal string. | ||
* | ||
* @param bytes the byte array to be converted | ||
* @return the hexadecimal string representation of the byte array | ||
* @throws NullPointerException if the byte array is null | ||
*/ | ||
public static String bytesToHexString(byte[] bytes) { | ||
if (bytes == null) { | ||
throw new NullPointerException("Parameter to be converted can not be null"); | ||
} | ||
|
||
char[] converted = new char[bytes.length * 2]; | ||
for (int i = 0; i < bytes.length; i++) { | ||
byte b = bytes[i]; | ||
converted[i * 2] = HEX_CHARS[b >> 4 & 0x0F]; | ||
converted[i * 2 + 1] = HEX_CHARS[b & 0x0F]; | ||
} | ||
|
||
return String.valueOf(converted); | ||
} | ||
|
||
|
||
/** | ||
* This method converts a hexadecimal string into an array of bytes. | ||
* | ||
* @param str the hexadecimal string to be converted | ||
* @return the resulting byte array | ||
* @throws IllegalArgumentException if the supplied character array contains an odd number of hex characters | ||
*/ | ||
public static byte[] hexStringToBytes(String str) { | ||
final char[] chars = str.toCharArray(); | ||
if (chars.length % 2 != 0) { | ||
throw new IllegalArgumentException("The supplied character array must contain an even number of hex chars."); | ||
} | ||
|
||
byte[] response = new byte[chars.length / 2]; | ||
|
||
for (int i = 0; i < response.length; i++) { | ||
int posOne = i * 2; | ||
response[i] = (byte) (toByte(chars, posOne) << 4 | toByte(chars, posOne + 1)); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
|
||
private static byte toByte(final char[] chars, final int pos) { | ||
int response = Character.digit(chars[pos], 16); | ||
if (response < 0 || response > 15) { | ||
throw new IllegalArgumentException("Non-hex character '" + chars[pos] + "' at index=" + pos); | ||
} | ||
|
||
return (byte) response; | ||
} | ||
|
||
} |