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


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerUtils.java:
##########
@@ -246,12 +274,61 @@ else if (cls == Timestamp[].class)
             writer.writeTimestampArray((Timestamp[])obj);
         else if (cls == java.util.Date[].class || cls == java.sql.Date[].class)
             writer.writeDateArray((java.util.Date[])obj);
+        else if (obj instanceof SqlInputStreamWrapper)
+            writeInputStreamAsByteArray(writer, (SqlInputStreamWrapper)obj);
+        else if (obj instanceof Blob)
+            writeBlobAsByteArray(writer, (Blob)obj);
         else if (binObjAllow)
             writer.writeObjectDetached(obj);
         else
             throw new BinaryObjectException("Custom objects are not 
supported");
     }
 
+    /**
+     * Write byte array from the InputStream enclosed in the stream wrapper.
+     *
+     * @param writer Writer.
+     * @param wrapper stream wrapper
+     */
+    private static void writeInputStreamAsByteArray(BinaryWriterExImpl writer, 
SqlInputStreamWrapper wrapper)
+            throws BinaryObjectException {
+        InputStream in = wrapper.getInputStream();
+        Integer len = wrapper.getLength();
+
+        if (len == null)
+            writer.writeByteArrayFromInputStream(in);
+        else {
+            int written = writer.writeByteArrayFromInputStream(in, len);
+
+            if (len != written)
+                throw new BinaryObjectException("Input stream length mismatch. 
[declaredLength=" + len + ", " +
+                        "actualLength=" + written + "]");
+        }
+    }
+
+    /**
+     * Write byte array from the Blob instance.
+     *
+     * @param writer Writer.
+     * @param blob Blob.
+     */
+    private static void writeBlobAsByteArray(BinaryWriterExImpl writer, Blob 
blob)
+            throws BinaryObjectException {
+        try {
+            int len = (int)blob.length();
+            InputStream in = blob.getBinaryStream(1, len);

Review Comment:
   `in` variable can be inlined.
   Looks like we can simplify to: 
   ```
   int written = written.writeByteArrayFromInputStream(blob.getBinaryStream(), 
len);
   ```



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