Class DrillStringUtils

java.lang.Object
org.apache.drill.common.util.DrillStringUtils

public class DrillStringUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Escapes the characters in a String according to Java string literal rules.
    static String
     
    static String
    Copied form commons-lang 2.x code as common-lang 3.x has this API removed.
    static int
    parseBinaryString(io.netty.buffer.ByteBuf str, int strStart, int strEnd, io.netty.buffer.ByteBuf out)
    parsing a hex encoded binary string and write to an output buffer.
    static String
    readable(long bytes)
    Converts the long number into more human readable string.
    static String
    Removes all leading slash characters from specified string.
    static String
    Removes extra spaces and empty values in a CSV String
    static String
    toBinaryString(byte[] buf)
    Return a printable representation of a byte array, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes.
    static String
    toBinaryString(byte[] buf, int strStart, int strEnd)
    Return a printable representation of a byte array, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes.
    static String
    toBinaryString(io.netty.buffer.ByteBuf buf, int strStart, int strEnd)
    Return a printable representation of a byte buffer, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes.
    static String
    Unescapes any Java literals found in the String.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DrillStringUtils

      public DrillStringUtils()
  • Method Details

    • readable

      public static String readable(long bytes)
      Converts the long number into more human readable string.
    • unescapeJava

      public static String unescapeJava(String input)
      Unescapes any Java literals found in the String. For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.
      Parameters:
      input - the String to unescape, may be null
      Returns:
      a new unescaped String, null if null string input
    • escapeJava

      public static String escapeJava(String input)
      Escapes the characters in a String according to Java string literal rules. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.) so, for example, a tab becomes the characters '\\' and 't'. Example:
       input string: He didn't say, "Stop!"
       output string: He didn't say, \"Stop!\"
       
      Parameters:
      input - String to escape values in, may be null
      Returns:
      String with escaped values, null if null string input
    • escapeNewLines

      public static String escapeNewLines(String input)
    • escapeSql

      public static String escapeSql(String str)
      Copied form commons-lang 2.x code as common-lang 3.x has this API removed. (http://commons.apache.org/proper/commons-lang/article3_0.html#StringEscapeUtils.escapeSql)
      Parameters:
      str -
      Returns:
    • toBinaryString

      public static String toBinaryString(io.netty.buffer.ByteBuf buf, int strStart, int strEnd)
      Return a printable representation of a byte buffer, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes. This function does not modify the readerIndex and writerIndex of the byte buffer.
    • toBinaryString

      public static String toBinaryString(byte[] buf)
      Return a printable representation of a byte array, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes.
    • toBinaryString

      public static String toBinaryString(byte[] buf, int strStart, int strEnd)
      Return a printable representation of a byte array, escaping the non-printable bytes as '\\xNN' where NN is the hexadecimal representation of such bytes.
    • parseBinaryString

      public static int parseBinaryString(io.netty.buffer.ByteBuf str, int strStart, int strEnd, io.netty.buffer.ByteBuf out)
      parsing a hex encoded binary string and write to an output buffer. This function does not modify the readerIndex and writerIndex of the byte buffer.
      Returns:
      Index in the byte buffer just after the last written byte.
    • sanitizeCSV

      public static String sanitizeCSV(String csv)
      Removes extra spaces and empty values in a CSV String
      Parameters:
      csv - The CSV string to be sanitized
      Returns:
      The sanitized CSV string
    • removeLeadingSlash

      public static String removeLeadingSlash(String path)
      Removes all leading slash characters from specified string.
      Parameters:
      path - string to remove all leading slash characters
      Returns:
      string with removed leading slash characters