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: 1.3 $
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)
 Return true if the string starts with the specified prefix, irrespective of case.
static byte[] stringToByteArray(java.lang.String content)
 Convert a string into a byte array using a default encoding DEFAULT_CHARSET.
static byte[] stringToByteArray(java.lang.String content, java.lang.String charset)
 Convert a string into a byte array using the given 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
equals, 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)
Return 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.

stringToByteArray

public static byte[] stringToByteArray(java.lang.String content)
Convert 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)
Convert a string into a byte array using the given 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.

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.


Copyright © 2003-2016 AppPerfect Corporation. All Rights Reserved.