Example usage for org.apache.commons.lang3 StringEscapeUtils ESCAPE_JAVA

List of usage examples for org.apache.commons.lang3 StringEscapeUtils ESCAPE_JAVA

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils ESCAPE_JAVA.

Prototype

CharSequenceTranslator ESCAPE_JAVA

To view the source code for org.apache.commons.lang3 StringEscapeUtils ESCAPE_JAVA.

Click Source Link

Document

Translator object for escaping Java.

Usage

From source file:com.thinkbiganalytics.hive.util.HiveUtils.java

/**
 * Quotes the specified string for use in a Hive query.
 *
 * @param string the string to be quoted
 * @return the quoted string/*from   w w w  .j  a v a2 s.co  m*/
 */
@Nonnull
public static String quoteString(@Nonnull final String string) {
    try {
        final StringWriter writer = new StringWriter(string.length() + 2);
        writer.append('"');
        StringEscapeUtils.ESCAPE_JAVA.translate(string, writer);
        writer.append('"');
        return writer.toString();
    } catch (final IOException e) {
        throw new IllegalArgumentException("String contains invalid characters: " + string, e);
    }
}