@Override
  public InputStream getBinaryStream(int columnIndex) throws SQLException {
    final Object obj = getObject(columnIndex);
    if (obj == null) {
      return null;
    }
    if (obj instanceof InputStream) {
      return (InputStream) obj;
    }
    if (obj instanceof byte[]) {
      byte[] byteArray = (byte[]) obj;
      return new ByteArrayInputStream(byteArray);
    }
    if (obj instanceof String) {
      final String str = (String) obj;
      return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
    }
    throw new SQLException("Illegal conversion to binary stream from column " + columnIndex + " [" + obj + "]");
  }
Data independent base class which implements the common part of all Hive
result sets.
jdbc/src/java/org/apache/hive/jdbc/HiveBaseResultSet.java