com.gargoylesoftware.htmlunit
Class TextUtil

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

public final class TextUtil
extends Object

Utility methods relating to text.

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

Field Summary
static String DEFAULT_CHARSET
          Default encoding used.
 
Method Summary
static boolean startsWithIgnoreCase(String stringToCheck, String prefix)
          Returns true if the string starts with the specified prefix, irrespective of case.
static byte[] stringToByteArray(String content)
          Converts a string into a byte array using a default encoding DEFAULT_CHARSET.
static byte[] stringToByteArray(String content, String charset)
          Converts a string into a byte array using the specified encoding.
static InputStream toInputStream(String content)
          Convert a string into an input stream.
static InputStream toInputStream(String content, 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 String DEFAULT_CHARSET
Default encoding used.

See Also:
Constant Field Values
Method Detail

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String stringToCheck,
                                           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 InputStream toInputStream(String content)
Convert a string into an input stream.

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

toInputStream

public static InputStream toInputStream(String content,
                                        String encoding)
                                 throws 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:
UnsupportedEncodingException - if the encoding is not supported

stringToByteArray

public static byte[] stringToByteArray(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(String content,
                                       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-2010 Gargoyle Software Inc.. All Rights Reserved.