org.apache.commons.lang3.text.translate

## Class CharSequenceTranslator

- java.lang.Object
- - org.apache.commons.lang3.text.translate.CharSequenceTranslator

- Direct Known Subclasses:
    AggregateTranslator, CodePointTranslator, LookupTranslator, NumericEntityUnescaper, OctalUnescaper, UnicodeUnescaper

      public abstract class CharSequenceTranslator
      extends Object

  An API for translating text. Its core use is to escape and unescape text. Because escaping and unescaping is completely contextual, the API does not present two separate signatures.
  Since:
    3.0
  Version:
    $Id: CharSequenceTranslator.java 1666535 2015-03-13 18:18:59Z britter $

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CharSequenceTranslator()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `hex(int codepoint)` Returns an upper case hexadecimal `String` for the given character.
    `String` | `translate(CharSequence input)` Helper for non-Writer usage.
    `abstract int` | `translate(CharSequence input, int index, Writer out)` Translate a set of codepoints, represented by an int index into a CharSequence, into another set of codepoints.
    `void` | `translate(CharSequence input, Writer out)` Translate an input onto a Writer.
    `CharSequenceTranslator` | `with(CharSequenceTranslator... translators)` Helper method to create a merger of this translator with another set of translators.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CharSequenceTranslator

          public CharSequenceTranslator()

  - ### Method Detail

    - #### translate

          public abstract int translate(CharSequence input,
                      int index,
                      Writer out)
                                 throws IOException

      Translate a set of codepoints, represented by an int index into a CharSequence, into another set of codepoints. The number of codepoints consumed must be returned, and the only IOExceptions thrown must be from interacting with the Writer so that the top level API may reliably ignore StringWriter IOExceptions.
      Parameters:
        `input` - CharSequence that is being translated
        `index` - int representing the current point of translation
        `out` - Writer to translate the text to
      Returns:
        int count of codepoints consumed
      Throws:
        `IOException` - if and only if the Writer produces an IOException

    - #### translate

          public final String translate(CharSequence input)

      Helper for non-Writer usage.
      Parameters:
        `input` - CharSequence to be translated
      Returns:
        String output of translation

    - #### translate

          public final void translate(CharSequence input,
                       Writer out)
                               throws IOException

      Translate an input onto a Writer. This is intentionally final as its algorithm is tightly coupled with the abstract method of this class.
      Parameters:
        `input` - CharSequence that is being translated
        `out` - Writer to translate the text to
      Throws:
        `IOException` - if and only if the Writer produces an IOException

    - #### with

          public final CharSequenceTranslator with(CharSequenceTranslator... translators)

      Helper method to create a merger of this translator with another set of translators. Useful in customizing the standard functionality.
      Parameters:
        `translators` - CharSequenceTranslator array of translators to merge with this one
      Returns:
        CharSequenceTranslator merging this translator with the others

    - #### hex

          public static String hex(int codepoint)

      Returns an upper case hexadecimal `String` for the given character.

      Parameters:
        `codepoint` - The codepoint to convert.
      Returns:
        An upper case hexadecimal `String`

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.