diff src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java @ 329:05c7989eae91

Removed duplicate code for converting a string of hex characters into a byte array, done both in MonetBlob.create() and in MonetResultSet.getBytes(). Extended MonetBlob with utitlity method: hexStrToByteArray(final String hexString) such that it can be called from both places. Also added an extra constructor MonetBlob(String hexString) which replaces the utility method MonetBlob.create(String hexString). This makes it more orthogonal with MonetClob.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 12 Sep 2019 19:51:30 +0200 (2019-09-12)
parents d479475888e3
children 54137aeb1f92
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
@@ -30,11 +30,18 @@ import java.sql.SQLFeatureNotSupportedEx
 public final class MonetBlob implements Blob {
 	private byte[] buf;
 
+	/* constructors */
 	protected MonetBlob(final byte[] data) {
 		buf = data;
 	}
 
-	static final MonetBlob create(final String hexString) {
+	protected MonetBlob(final String hexString) {
+		buf = hexStrToByteArray(hexString);
+	}
+
+
+	/* class utility methods */
+	static final byte[] hexStrToByteArray(final String hexString) {
 		// unpack the HEX (BLOB) notation to real bytes
 		final int len = hexString.length() / 2;
 		final byte[] buf = new byte[len];
@@ -43,7 +50,7 @@ public final class MonetBlob implements 
 			buf[i] = (byte) ((Character.digit(hexString.charAt(2 * i), 16) << 4)
 					+ Character.digit(hexString.charAt((2 * i) +1), 16));
 		}
-		return new MonetBlob(buf);
+		return buf;
 	}
 
 	/* internal utility method */