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

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

Introduction

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

Prototype

public static final String escapeJava(final String input) 

Source Link

Document

Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't' .

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.

Example:

 input string: He didn't say, "Stop!" 

Usage

From source file:org.apache.drill.common.util.DrillStringUtils.java

/**
 * Escapes the characters in a {@code String} using Java String rules.
 *
 * Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
 *
 * So a tab becomes the characters {@code '\\'} and
 * {@code 't'}.//from w  w  w . ja v  a2  s. c o  m
 *
 * Example:
 * <pre>
 * input string: He didn't say, "Stop!"
 * output string: He didn't say, \"Stop!\"
 * </pre>
 *
 * @param input  String to escape values in, may be null
 * @return String with escaped values, {@code null} if null string input
 */
public static final String escapeJava(String input) {
    return StringEscapeUtils.escapeJava(input);
}

From source file:org.apache.hadoop.hive.ql.exec.FetchOperator.java

/**
 * Set context for this fetch operator in to the jobconf.
 * This helps InputFormats make decisions based on the scope of the complete
 * operation./*from  www  .java 2s .c om*/
 * @param conf the configuration to modify
 * @param paths the list of input directories
 */
static void setFetchOperatorContext(JobConf conf, List<Path> paths) {
    if (paths != null) {
        StringBuilder buff = new StringBuilder();
        for (Path path : paths) {
            if (buff.length() > 0) {
                buff.append('\t');
            }
            buff.append(StringEscapeUtils.escapeJava(path.toString()));
        }
        conf.set(FETCH_OPERATOR_DIRECTORY_LIST, buff.toString());
    }
}

From source file:org.apache.hadoop.hive.ql.exec.Utilities.java

/**
 * Copies the storage handler properties configured for a table descriptor to a runtime job
 * configuration.//  w ww .ja  va  2 s  .  c  o m
 *
 * @param tbl
 *          table descriptor from which to read
 *
 * @param job
 *          configuration which receives configured properties
 */
public static void copyTableJobPropertiesToConf(TableDesc tbl, JobConf job) throws HiveException {
    Properties tblProperties = tbl.getProperties();
    for (String name : tblProperties.stringPropertyNames()) {
        if (job.get(name) == null) {
            String val = (String) tblProperties.get(name);
            if (val != null) {
                job.set(name, StringEscapeUtils.escapeJava(val));
            }
        }
    }
    Map<String, String> jobProperties = tbl.getJobProperties();
    if (jobProperties != null) {
        for (Map.Entry<String, String> entry : jobProperties.entrySet()) {
            job.set(entry.getKey(), entry.getValue());
        }
    }

    try {
        Map<String, String> jobSecrets = tbl.getJobSecrets();
        if (jobSecrets != null) {
            for (Map.Entry<String, String> entry : jobSecrets.entrySet()) {
                job.getCredentials().addSecretKey(new Text(entry.getKey()), entry.getValue().getBytes());
                UserGroupInformation.getCurrentUser().getCredentials().addSecretKey(new Text(entry.getKey()),
                        entry.getValue().getBytes());
            }
        }
    } catch (IOException e) {
        throw new HiveException(e);
    }
}

From source file:org.apache.hadoop.hive.ql.exec.Utilities.java

/**
 * Copies the storage handler proeprites configured for a table descriptor to a runtime job
 * configuration.  This differs from {@link #copyTablePropertiesToConf(org.apache.hadoop.hive.ql.plan.TableDesc, org.apache.hadoop.mapred.JobConf)}
 * in that it does not allow parameters already set in the job to override the values from the
 * table.  This is important for setting the config up for reading,
 * as the job may already have values in it from another table.
 * @param tbl//from   ww  w  . j  a va  2  s.  c o  m
 * @param job
 */
public static void copyTablePropertiesToConf(TableDesc tbl, JobConf job) throws HiveException {
    Properties tblProperties = tbl.getProperties();
    for (String name : tblProperties.stringPropertyNames()) {
        String val = (String) tblProperties.get(name);
        if (val != null) {
            job.set(name, StringEscapeUtils.escapeJava(val));
        }
    }
    Map<String, String> jobProperties = tbl.getJobProperties();
    if (jobProperties != null) {
        for (Map.Entry<String, String> entry : jobProperties.entrySet()) {
            job.set(entry.getKey(), entry.getValue());
        }
    }

    try {
        Map<String, String> jobSecrets = tbl.getJobSecrets();
        if (jobSecrets != null) {
            for (Map.Entry<String, String> entry : jobSecrets.entrySet()) {
                job.getCredentials().addSecretKey(new Text(entry.getKey()), entry.getValue().getBytes());
                UserGroupInformation.getCurrentUser().getCredentials().addSecretKey(new Text(entry.getKey()),
                        entry.getValue().getBytes());
            }
        }
    } catch (IOException e) {
        throw new HiveException(e);
    }
}

From source file:org.apache.jackrabbit.oak.run.DataStoreCheckTest.java

@Before
public void setup() throws Exception {
    OakFileDataStore delegate = new OakFileDataStore();
    dsPath = temporaryFolder.newFolder().getAbsolutePath();
    delegate.setPath(dsPath);//ww  w . ja  v a2  s . c om
    delegate.init(null);
    DataStoreBlobStore blobStore = new DataStoreBlobStore(delegate);

    File storeFile = temporaryFolder.newFolder();
    storePath = storeFile.getAbsolutePath();
    FileStore.Builder builder = FileStore.builder(storeFile).withBlobStore(blobStore).withMaxFileSize(256)
            .withCacheSize(64).withMemoryMapping(false);
    FileStore fileStore = builder.build();
    NodeStore store = SegmentNodeStore.builder(fileStore).build();

    /* Create nodes with blobs stored in DS*/
    NodeBuilder a = store.getRoot().builder();
    int numBlobs = 10;
    blobsAdded = Sets.newHashSet();
    for (int i = 0; i < numBlobs; i++) {
        SegmentBlob b = (SegmentBlob) store.createBlob(randomStream(i, 18342));
        Iterator<String> idIter = blobStore.resolveChunks(b.getBlobId());
        while (idIter.hasNext()) {
            String chunk = idIter.next();
            blobsAdded.add(chunk);
        }
        a.child("c" + i).setProperty("x", b);
    }

    store.merge(a, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    log.info("Created blobs : {}", blobsAdded);

    File cfgFile = temporaryFolder.newFile();
    BufferedWriter writer = Files.newWriter(cfgFile, UTF_8);
    FileIOUtils.writeAsLine(writer, "path=\"" + StringEscapeUtils.escapeJava(dsPath) + "\"", false);
    writer.close();
    cfgFilePath = cfgFile.getAbsolutePath();

    fileStore.close();
    blobStore.close();
}

From source file:org.apache.lucene.analysis.kr.test.KoreanAnalyzerTest.java

public void testJavaEscape() throws Exception {

    String str = StringEscapeUtils.unescapeHtml4("&#48085;");
    System.out.println(str);/*from   www  .ja v  a 2s .  com*/

    //??
    String han = StringEscapeUtils.unescapeJava("0x3400");
    han = StringEscapeUtils.escapeJava("?");

    System.out.println(han);

}

From source file:org.apache.streams.neo4j.CypherQueryGraphHelper.java

/**
 * getPropertyValueSetter.// w w w.j av a  2 s .  com
 * @param map paramMap
 * @return PropertyValueSetter string
 */
public static String getPropertyValueSetter(Map<String, Object> map, String symbol) {
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getValue() instanceof String) {
            String propVal = (String) (entry.getValue());
            builder.append("," + symbol + ".`" + entry.getKey() + "` = '"
                    + StringEscapeUtils.escapeJava(propVal) + "'");
        }
    }
    return builder.toString();
}

From source file:org.apache.streams.neo4j.CypherQueryGraphHelper.java

/**
 * getPropertyParamSetter.//from w  ww . ja v a2  s.co  m
 * @param map paramMap
 * @return PropertyParamSetter string
 */
public static String getPropertyParamSetter(Map<String, Object> map, String symbol) {
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getValue() instanceof String) {
            String propVal = (String) (entry.getValue());
            builder.append("," + symbol + ".`" + entry.getKey() + "` = '"
                    + StringEscapeUtils.escapeJava(propVal) + "'");
        }
    }
    return builder.toString();
}

From source file:org.apache.streams.neo4j.CypherQueryGraphHelper.java

/**
 * getPropertyCreater./* w ww  .  j  a  v a 2s  .  c  o  m*/
 * @param map paramMap
 * @return PropertyCreater string
 */
public static String getPropertyCreater(Map<String, Object> map) {
    StringBuilder builder = new StringBuilder();
    builder.append("{ ");
    List<String> parts = new ArrayList<>();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getValue() instanceof String) {
            String propVal = (String) (entry.getValue());
            parts.add("`" + entry.getKey() + "`:'" + StringEscapeUtils.escapeJava(propVal) + "'");
        }
    }
    builder.append(String.join(" ", parts));
    builder.append(" }");
    return builder.toString();
}

From source file:org.apache.streams.neo4j.CypherQueryGraphHelper.java

private String getActorObjectEdgePropertyCreater(Map<String, Object> map) {
    StringBuilder builder = new StringBuilder();
    builder.append("{ ");
    List<String> parts = new ArrayList<>();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getValue() instanceof String) {
            String propVal = (String) (entry.getValue());
            if (!entry.getKey().contains(".")) {
                parts.add("`" + entry.getKey() + "`: '" + StringEscapeUtils.escapeJava(propVal) + "'");
            }//from  w  w  w  . j a  v a  2s.  co m
        }
    }
    builder.append(String.join(", ", parts));
    builder.append(" }");
    return builder.toString();
}