Changeset: 05c7989eae91 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=05c7989eae91
Modified Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
Branch: default
Log Message:

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.


diffs (70 lines):

diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetBlob.java
--- 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 */
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -559,7 +559,7 @@ public class MonetResultSet
                                return null;
                        }
                        lastReadWasNull = false;
-                       return MonetBlob.create(val);
+                       return new MonetBlob(val);
                } catch (IndexOutOfBoundsException e) {
                        throw newSQLInvalidColumnIndexException(columnIndex);
                }
@@ -901,15 +901,7 @@ public class MonetResultSet
                                case Types.BINARY:
                                case Types.VARBINARY:
                                case Types.LONGVARBINARY:
-                                       // unpack the HEX (BLOB) notation to 
real bytes
-                                       final int len = val.length() / 2;
-                                       final byte[] buf = new byte[len];
-                                       int offset;
-                                       for (int j = 0; j < len; j++) {
-                                               offset = j * 2;
-                                               buf[j] = 
(byte)Integer.parseInt(val.substring(offset, offset + 2), 16);
-                                       }
-                                       return buf;
+                                       return MonetBlob.hexStrToByteArray(val);
                                default:
                                        throw new SQLException("Cannot operate 
on " + types[columnIndex - 1] + " type", "M1M05");
                        }
@@ -1945,7 +1937,7 @@ public class MonetResultSet
                        case Types.CLOB:
                                return new MonetClob(val);
                        case Types.BLOB:
-                               return MonetBlob.create(val);
+                               return new MonetBlob(val);
                        case Types.DATE:
                                return getDate(columnIndex, null);
                        case Types.TIME:
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to