nizhikov commented on code in PR #11518:
URL: https://github.com/apache/ignite/pull/11518#discussion_r1832688096


##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcBlob.java:
##########
@@ -74,55 +101,56 @@ public JdbcBlob(byte[] arr) {
     @Override public InputStream getBinaryStream() throws SQLException {
         ensureNotClosed();
 
-        return new ByteArrayInputStream(arr);
+        return buf.getInputStream();
     }
 
     /** {@inheritDoc} */
     @Override public InputStream getBinaryStream(long pos, long len) throws 
SQLException {
         ensureNotClosed();
 
-        if (pos < 1 || len < 1 || pos > arr.length || len > arr.length - pos + 
1)
+        int blobLen = buf.length();
+
+        if (pos < 1 || len < 1 || pos > blobLen || len > blobLen - (pos - 1)) {
             throw new SQLException("Invalid argument. Position can't be less 
than 1 or " +
-                "greater than size of underlying byte array. Requested length 
can't be negative and can't be " +
-                "greater than available bytes from given position [pos=" + pos 
+ ", len=" + len + ']');
+                "greater than Blob length. Requested length can't be negative 
and can't be " +
+                "greater than available bytes from given position [pos=" + pos 
+ ", len=" + len + ", blobLen=" + blobLen + "]");
+        }
 
-        return new ByteArrayInputStream(arr, (int)(pos - 1), (int)len);
+        return buf.getInputStream((int)pos - 1, (int)len);
     }
 
     /** {@inheritDoc} */
     @Override public long position(byte[] ptrn, long start) throws 
SQLException {
         ensureNotClosed();
 
-        if (start < 1 || start > arr.length || ptrn.length == 0 || ptrn.length 
> arr.length)
-            return -1;
-
-        for (int i = 0, pos = (int)(start - 1); pos < arr.length;) {
-            if (arr[pos] == ptrn[i]) {
-                pos++;
+        int blobLen = buf.length();
 
-                i++;
+        if (start < 1)
+            throw new SQLException("Invalid argument. Start position can't be 
less than 1 [start=" + start + "]");
 
-                if (i == ptrn.length)
-                    return pos - ptrn.length + 1;
-            }
-            else {
-                pos = pos - i + 1;
+        if (start > blobLen || ptrn.length == 0 || ptrn.length > blobLen)
+            return -1;
 
-                i = 0;
-            }
-        }
+        long idx = position(new ByteArrayInputStream(ptrn), ptrn.length, 
(int)start - 1);
 
-        return -1;
+        return idx == -1 ? -1 : idx + 1;
     }
 
     /** {@inheritDoc} */
     @Override public long position(Blob ptrn, long start) throws SQLException {
         ensureNotClosed();
 
-        if (start < 1 || start > arr.length || ptrn.length() == 0 || 
ptrn.length() > arr.length)
+        int blobLen = buf.length();

Review Comment:
   Can you, please, don't introduce `blobLen` variable here and in another 
parts of class as it will reduce changes and simplify review. `buf.length()` 
are simple enough to keep it straight.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to