nizhikov commented on code in PR #11518: URL: https://github.com/apache/ignite/pull/11518#discussion_r1828922325
########## modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcBlob.java: ########## @@ -134,57 +160,113 @@ 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(); + int blobLen = buf.length(); - byte[] dst = arr; - - if (idx + len > arr.length) { - dst = new byte[arr.length + (len - (arr.length - idx))]; - - U.arrayCopy(arr, 0, dst, 0, idx); + if (pos < 1 || pos - 1 > blobLen) + throw new SQLException("Invalid argument. Position can't be less than 1 or " + + "greater than Blob length + 1 [pos=" + pos + ", blobLen=" + blobLen + "]"); - arr = dst; + try { + buf.write((int)pos - 1, bytes, off, len); + } + catch (IOException e) { + throw new SQLException(e); } - - U.arrayCopy(bytes, off, dst, idx, len); return len; } /** {@inheritDoc} */ @Override public OutputStream setBinaryStream(long pos) throws SQLException { - throw new SQLFeatureNotSupportedException(); + ensureNotClosed(); + + int blobLen = buf.length(); + + if (pos < 1 || pos - 1 > blobLen) + throw new SQLException("Invalid argument. Position can't be less than 1 or greater than Blob length + 1 " + + "[pos=" + pos + ", blobLen=" + blobLen + "]"); + + return buf.getOutputStream((int)pos - 1); } /** {@inheritDoc} */ @Override public void truncate(long len) throws SQLException { ensureNotClosed(); - if (len < 0 || len > arr.length) - throw new SQLException("Invalid argument. Length can't be " + - "less than zero or greater than Blob length [len=" + len + ']'); + int blobLen = buf.length(); - arr = Arrays.copyOf(arr, (int)len); + if (len < 0 || len > blobLen) Review Comment: parentess for multiline if. ########## modules/core/src/main/java/org/apache/ignite/internal/jdbc2/JdbcBlob.java: ########## @@ -134,57 +160,113 @@ 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(); + int blobLen = buf.length(); - byte[] dst = arr; - - if (idx + len > arr.length) { - dst = new byte[arr.length + (len - (arr.length - idx))]; - - U.arrayCopy(arr, 0, dst, 0, idx); + if (pos < 1 || pos - 1 > blobLen) + throw new SQLException("Invalid argument. Position can't be less than 1 or " + + "greater than Blob length + 1 [pos=" + pos + ", blobLen=" + blobLen + "]"); - arr = dst; + try { + buf.write((int)pos - 1, bytes, off, len); + } + catch (IOException e) { + throw new SQLException(e); } - - U.arrayCopy(bytes, off, dst, idx, len); return len; } /** {@inheritDoc} */ @Override public OutputStream setBinaryStream(long pos) throws SQLException { - throw new SQLFeatureNotSupportedException(); + ensureNotClosed(); + + int blobLen = buf.length(); + + if (pos < 1 || pos - 1 > blobLen) Review Comment: parentess for multiline if. -- 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