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


##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcBlob.java:
##########
@@ -134,57 +150,110 @@ public JdbcBlob(byte[] arr) {
     @Override public int setBytes(long pos, byte[] bytes, int off, int len) 
throws SQLException {
         ensureNotClosed();
 
-        if (pos < 1)
-            throw new SQLException("Invalid argument. Position can't be less 
than 1 [pos=" + pos + ']');
-
-        int idx = (int)(pos - 1);
-
-        if (pos - 1 > arr.length || off < 0 || off >= bytes.length || off + 
len > bytes.length)
-            throw new ArrayIndexOutOfBoundsException();
-
-        byte[] dst = arr;
-
-        if (idx + len > arr.length) {
-            dst = new byte[arr.length + (len - (arr.length - idx))];
-
-            U.arrayCopy(arr, 0, dst, 0, idx);
-
-            arr = dst;
+        if (pos < 1 || pos - 1 > buf.length()) {
+            throw new SQLException("Invalid argument. Position can't be less 
than 1 or " +
+                "greater than Blob length + 1 [pos=" + pos + ", blobLen=" + 
buf.length() + "]");
         }
 
-        U.arrayCopy(bytes, off, dst, idx, len);
+        try {
+            buf.write((int)pos - 1, bytes, off, len);
+        }
+        catch (IOException e) {
+            throw new SQLException(e);
+        }
 
         return len;
     }
 
     /** {@inheritDoc} */
     @Override public OutputStream setBinaryStream(long pos) throws 
SQLException {
-        throw new SQLFeatureNotSupportedException();
+        ensureNotClosed();
+
+        if (pos < 1 || pos - 1 > buf.length()) {
+            throw new SQLException("Invalid argument. Position can't be less 
than 1 or greater than Blob length + 1 " +
+                    "[pos=" + pos + ", blobLen=" + buf.length() + "]");
+        }
+
+        return buf.outputStream((int)pos - 1);
     }
 
     /** {@inheritDoc} */
     @Override public void truncate(long len) throws SQLException {
         ensureNotClosed();
 
-        if (len < 0 || len > arr.length)
+        if (len < 0 || len > buf.length()) {
             throw new SQLException("Invalid argument. Length can't be " +
-                "less than zero or greater than Blob length [len=" + len + 
']');
-
-        arr = Arrays.copyOf(arr, (int)len);
+                "less than zero or greater than Blob length [len=" + len + ", 
blobLen=" + buf.length() + "]");
+        }
 
+        buf.truncate((int)len);
     }
 
     /** {@inheritDoc} */
     @Override public void free() throws SQLException {
-        if (arr != null)
-            arr = null;
+        if (buf != null)
+            buf = null;
+    }
+
+    /**
+     * Actial implementation of the pattern search.
+     *
+     * @param ptrn InputStream containing the pattern.
+     * @param ptrnLen Pattern length.
+     * @param idx 1-based index in Blob to start search from.
+     * @return 1-based position at which the pattern appears, else -1.
+     */
+    private long position(InputStream ptrn, int ptrnLen, int idx) throws 
SQLException {
+        try {
+            InputStream blob = buf.inputStream(idx - 1, buf.length() - idx + 
1);

Review Comment:
   Let's use try with resource here.



-- 
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