com.gargoylesoftware.htmlunit
Class TextUtil

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.TextUtil

public final class TextUtil
extends java.lang.Object

Utility methods relating to text.

Version:
$Revision: 4676 $
Author:
Mike Bowler, Brad Clarke, Ahmed Ashour

Field Summary
static java.lang.String DEFAULT_CHARSET
          Default encoding used.
 
Method Summary
static boolean startsWithIgnoreCase(java.lang.String stringToCheck, java.lang.String prefix)
          Returns true if the string starts with the specified prefix, irrespective of case.
static byte[] stringToByteArray(java.lang.String content)
          Converts a string into a byte array using a default encoding DEFAULT_CHARSET.
static byte[] stringToByteArray(java.lang.String content, java.lang.String charset)
          Converts a string into a byte array using the specified encoding.
static java.io.InputStream toInputStream(java.lang.String content)
          Convert a string into an input stream.
static java.io.InputStream toInputStream(java.lang.String content, java.lang.String encoding)
          Convert a string into an input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHARSET

public static final java.lang.String DEFAULT_CHARSET
Default encoding used.

See Also:
Constant Field Values
Method Detail

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String stringToCheck,
                                           java.lang.String prefix)
Returns true if the string starts with the specified prefix, irrespective of case.

Parameters:
stringToCheck - the string to check
prefix - the prefix
Returns:
true if the string starts with the prefix

toInputStream

public static java.io.InputStream toInputStream(java.lang.String content)
Convert a string into an input stream.

Parameters:
content - the string
Returns:
the resulting input stream

toInputStream

public static java.io.InputStream toInputStream(java.lang.String content,
                                                java.lang.String encoding)
                                         throws java.io.UnsupportedEncodingException
Convert a string into an input stream.

Parameters:
content - the string
encoding - the encoding to use when converting the string to a stream
Returns:
the resulting input stream
Throws:
java.io.UnsupportedEncodingException - if the encoding is not supported

stringToByteArray

public static byte[] stringToByteArray(java.lang.String content)
Converts a string into a byte array using a default encoding DEFAULT_CHARSET.

Parameters:
content - the string to convert, assumed to be DEFAULT_CHARSET encoded
Returns:
the String as a byte[]; if the default encoding is not supported an empty byte[] will be returned

stringToByteArray

public static byte[] stringToByteArray(java.lang.String content,
                                       java.lang.String charset)
Converts a string into a byte array using the specified encoding.

Parameters:
charset - the name of a supported charset
content - the string to convert
Returns:
the String as a byte[]; if the specified encoding is not supported an empty byte[] will be returned


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.