All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickzetta.client.jdbc.arrow.util.JsonUtils Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.client.jdbc.arrow.util;

import org.apache.arrow.vector.util.Text;

public class JsonUtils {

  public static String printBinary(byte[] value) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    for (int i = 0; i < value.length; ++i) {
      sb.append(String.format("%02x",  (int) value[i] & 0xff));
      if (i != value.length - 1) {
        sb.append(" ");
      }
    }
    sb.append("]");
    return sb.toString();
  }

  public static String convert(Object value) {
    if (value == null) {
      return "null";
    }

    if (value instanceof byte[]) {
      return printBinary((byte[]) value);
    }

    if (value instanceof Text || value instanceof String) {
      StringBuilder sb = new StringBuilder();
      sb.append("\"").append(value).append("\"");
      return sb.toString();
    }

    return value.toString();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy