org.apache.nutch.util

## Class StringUtil

- java.lang.Object
- - org.apache.nutch.util.StringUtil

-     public class StringUtil
      extends Object

  A collection of String processing utility methods.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringUtil()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `cleanField(String value)` Takes in a String value and cleans out any offending "�"
    `static byte[]` | `fromHexString(String text)` Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array.
    `static boolean` | `isEmpty(String str)` Checks if a string is empty (ie is null or empty).
    `static String` | `leftPad(String s, int length)` Returns a copy of `s` padded with leading spaces so that it's length is `length`.
    `static void` | `main(String[] args)`
    `static String` | `rightPad(String s, int length)` Returns a copy of `s` padded with trailing spaces so that it's length is `length`.
    `static String` | `toHexString(byte[] buf)` Convenience call for `toHexString(byte[], String, int)`, where `sep = null; lineLen = Integer.MAX_VALUE`.
    `static String` | `toHexString(byte[] buf, int of, int cb, String sep, int lineLen)` Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
    `static String` | `toHexString(byte[] buf, String sep, int lineLen)` Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
    `static String` | `toHexString(ByteBuffer buf)` Convenience call for `toHexString(ByteBuffer, String, int)`, where `sep = null; lineLen = Integer.MAX_VALUE`.
    `static String` | `toHexString(ByteBuffer buf, String sep, int lineLen)` Get a text representation of a ByteBuffer as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.

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

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

- - ### Constructor Detail

    - #### StringUtil

          public StringUtil()

  - ### Method Detail

    - #### rightPad

          public static String rightPad(String s,
                        int length)

      Returns a copy of `s` padded with trailing spaces so that it's length is `length`. Strings already `length` characters long or longer are not altered.

    - #### leftPad

          public static String leftPad(String s,
                       int length)

      Returns a copy of `s` padded with leading spaces so that it's length is `length`. Strings already `length` characters long or longer are not altered.

    - #### toHexString

          public static String toHexString(ByteBuffer buf)

      Convenience call for `toHexString(ByteBuffer, String, int)`, where `sep = null; lineLen = Integer.MAX_VALUE`.
      Parameters:
        `buf` -

    - #### toHexString

          public static String toHexString(ByteBuffer buf,
                           String sep,
                           int lineLen)

      Get a text representation of a ByteBuffer as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
      Parameters:
        `buf` - input data
        `sep` - separate every pair of hexadecimal digits with this separator, or null if no separation is needed.
        `lineLen` - break the output String into lines containing output for lineLen bytes.

    - #### toHexString

          public static String toHexString(byte[] buf)

      Convenience call for `toHexString(byte[], String, int)`, where `sep = null; lineLen = Integer.MAX_VALUE`.
      Parameters:
        `buf` -

    - #### toHexString

          public static String toHexString(byte[] buf,
                           String sep,
                           int lineLen)

      Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
      Parameters:
        `buf` - input data
        `sep` - separate every pair of hexadecimal digits with this separator, or null if no separation is needed.
        `lineLen` - break the output String into lines containing output for lineLen bytes.

    - #### toHexString

          public static String toHexString(byte[] buf,
                           int of,
                           int cb,
                           String sep,
                           int lineLen)

      Get a text representation of a byte[] as hexadecimal String, where each pair of hexadecimal digits corresponds to consecutive bytes in the array.
      Parameters:
        `buf` - input data
        `of` - the offset into the byte[] to start reading
        `cb` - the number of bytes to read from the byte[]
        `sep` - separate every pair of hexadecimal digits with this separator, or null if no separation is needed.
        `lineLen` - break the output String into lines containing output for lineLen bytes.

    - #### fromHexString

          public static byte[] fromHexString(String text)

      Convert a String containing consecutive (no inside whitespace) hexadecimal digits into a corresponding byte array. If the number of digits is not even, a '0' will be appended in the front of the String prior to conversion. Leading and trailing whitespace is ignored.
      Parameters:
        `text` - input text
      Returns:
        converted byte array, or null if unable to convert

    - #### isEmpty

          public static boolean isEmpty(String str)

      Checks if a string is empty (ie is null or empty).

    - #### cleanField

          public static String cleanField(String value)

      Takes in a String value and cleans out any offending "�"
      Parameters:
        `value` - the dirty String value.
      Returns:
        clean String

    - #### main

          public static void main(String[] args)

Copyright © 2015 The Apache Software Foundation