|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jboss.dna.common.util.StringUtil
public class StringUtil
Utilities for string processing and manipulation.
Field Summary | |
---|---|
static java.lang.String[] |
EMPTY_STRING_ARRAY
|
Method Summary | |
---|---|
static java.lang.String |
createString(char charToRepeat,
int numberOfRepeats)
Create a new string containing the specified character repeated a specific number of times. |
static java.lang.String |
createString(java.lang.String pattern,
java.lang.Object... parameters)
Create a string by substituting the parameters into all key occurrences in the supplied format. |
static java.lang.String |
getStackTrace(java.lang.Throwable t)
Get the stack trace of the supplied exception. |
static java.lang.String |
justifyCenter(java.lang.String str,
int width,
char padWithChar)
Center the contents of the string. |
static java.lang.String |
justifyLeft(java.lang.String str,
int width,
char padWithChar)
Left justify the contents of the string, ensuring that the supplied string begins at the first character and that the resulting string is of the desired length. |
static java.lang.String |
justifyRight(java.lang.String str,
int width,
char padWithChar)
Right justify the contents of the string, ensuring that the string ends at the last character. |
static java.lang.String |
read(java.io.InputStream stream)
Read and return the entire contents of the supplied InputStream . |
static java.lang.String |
read(java.io.Reader reader)
Read and return the entire contents of the supplied Reader . |
static java.lang.String |
readableString(java.lang.Object obj)
Create a human-readable form of the supplied object by choosing the representation format based upon the object type. |
static java.lang.String |
setLength(java.lang.String original,
int length,
char padChar)
Set the length of the string, padding with the supplied character if the supplied string is shorter than desired, or truncating the string if it is longer than desired. |
static java.util.List<java.lang.String> |
splitLines(java.lang.String content)
Split the supplied content into lines, returning each line as an element in the returned list. |
static java.lang.String |
truncate(java.lang.Object obj,
int maxLength)
Truncate the supplied string to be no more than the specified length. |
static java.lang.String |
truncate(java.lang.Object obj,
int maxLength,
java.lang.String suffix)
Truncate the supplied string to be no more than the specified length. |
static void |
write(java.lang.String content,
java.io.OutputStream stream)
Write the entire contents of the supplied string to the given stream. |
static void |
write(java.lang.String content,
java.io.Writer writer)
Write the entire contents of the supplied string to the given writer. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String[] EMPTY_STRING_ARRAY
Method Detail |
---|
public static java.util.List<java.lang.String> splitLines(java.lang.String content)
content
- the string content that is to be split
public static java.lang.String createString(java.lang.String pattern, java.lang.Object... parameters)
{n}
, where n
is an integer starting at 1. Therefore, the first
parameter replaces all occurrences of "{1}", the second parameter replaces all occurrences of "{2}", etc.
If any parameter is null, the corresponding key is replaced with the string "null". Therefore, consider using an empty string when keys are to be removed altogether.
If there are no parameters, this method does nothing and returns the supplied pattern as is.
pattern
- the patternparameters
- the parameters used to replace keys
public static java.lang.String createString(char charToRepeat, int numberOfRepeats)
charToRepeat
- the character to repeatnumberOfRepeats
- the number of times the character is to repeat in the result; must be greater than 0
public static java.lang.String setLength(java.lang.String original, int length, char padChar)
justifyLeft(String, int, char)
, this method does not
remove leading and trailing whitespace.
original
- the string for which the length is to be set; may not be nulllength
- the desired length; must be positivepadChar
- the character to use for padding, if the supplied string is not long enough
justifyLeft(String, int, char)
public static java.lang.String justifyRight(java.lang.String str, int width, char padWithChar)
str
- the string to be right justified; if null, an empty string is usedwidth
- the desired width of the string; must be positivepadWithChar
- the character to use for padding, if needed
public static java.lang.String justifyLeft(java.lang.String str, int width, char padWithChar)
str
- the string to be left justified; if null, an empty string is usedwidth
- the desired width of the string; must be positivepadWithChar
- the character to use for padding, if needed
setLength(String, int, char)
public static java.lang.String justifyCenter(java.lang.String str, int width, char padWithChar)
str
- the string to be left justified; if null, an empty string is usedwidth
- the desired width of the string; must be positivepadWithChar
- the character to use for padding, if needed
setLength(String, int, char)
public static java.lang.String truncate(java.lang.Object obj, int maxLength)
obj
- the object from which the string is to be obtained using Object.toString()
.maxLength
- the maximum length of the string being returned
java.lang.IllegalArgumentException
- if the maximum length is negativepublic static java.lang.String truncate(java.lang.Object obj, int maxLength, java.lang.String suffix)
obj
- the object from which the string is to be obtained using Object.toString()
.maxLength
- the maximum length of the string being returnedsuffix
- the suffix that should be added to the content if the string must be truncated, or null if the default suffix
of "..." should be used
java.lang.IllegalArgumentException
- if the maximum length is negativepublic static java.lang.String read(java.io.Reader reader) throws java.io.IOException
Reader
. This method always closes the reader when finished
reading.
reader
- the reader of the contents; may be null
java.io.IOException
- if there is an error reading the contentpublic static java.lang.String read(java.io.InputStream stream) throws java.io.IOException
InputStream
. This method always closes the stream when
finished reading.
stream
- the streamed contents; may be null
java.io.IOException
- if there is an error reading the contentpublic static void write(java.lang.String content, java.io.OutputStream stream) throws java.io.IOException
content
- the content to write to the stream; may be nullstream
- the stream to which the content is to be written
java.io.IOException
java.lang.IllegalArgumentException
- if the stream is nullpublic static void write(java.lang.String content, java.io.Writer writer) throws java.io.IOException
content
- the content to write to the writer; may be nullwriter
- the writer to which the content is to be written
java.io.IOException
java.lang.IllegalArgumentException
- if the writer is nullpublic static java.lang.String readableString(java.lang.Object obj)
Boolean.toString()
.number
is written using the standard toString()
method.date
is written using the the DateUtil.getDateAsStandardString(java.util.Date)
utility method.SQL date
is written using the the DateUtil.getDateAsStandardString(java.util.Date)
utility method.Calendar instance
is written using the the DateUtil.getDateAsStandardString(Calendar)
utility method.readableString(Object)
and separated by ", ".Collection>
) is written with a leading "[ " and trailing " ]", and
with all objects sent through readableString(Object)
and separated by ", ".Map>
) is written with a leading "{ " and trailing " }", and with all map
entries written in the form "key => value" and separated by ", ". All key and value objects are sent through the
readableString(Object)
method.toString()
method.
This method is capable of generating strings for nested objects. For example, a Map
would be
written in the form:
{ 2008-02-03T14:22:49 => [ "description", 3, [ 003459de7389g23aef, true ] ] }
obj
- the object that is to be converted to a string.
public static java.lang.String getStackTrace(java.lang.Throwable t)
t
- the exception for which the stack trace is to be returned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |