|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jaxfront.core.util.io.files.Objects
com.jaxfront.core.util.io.files.Strings
public class Strings
Field Summary | |
---|---|
static int |
_FALSE_
|
static int |
_TRUE_
Three "fuzzy logical" values, _TRUE_, _FALSE_, _UNDEF_ ("Intuitionistic" would be a more correct scientific term for these). |
static int |
_UNDEF_
|
static java.lang.String |
ESCAPED
Characters used in escapes "\\\"\'nrtfb" |
static java.lang.String |
ESCAPEE
Characters that should be escaped in Java or C code "\\\"\'\n\r\t\f\b" |
Method Summary | |
---|---|
static java.util.Properties |
asProperties(java.lang.String[] pairs)
Create Properties from an array of key-value pairs |
static int |
countChar(java.lang.CharSequence s,
char c)
Counts the number of occurrences of char c in CharSequence s. |
static int |
countLeadingSpaces(java.lang.CharSequence s)
Counts leading spaces in a char sequence |
static int |
countTrailingSpaces(java.lang.CharSequence s)
Counts trailing spaces in a char sequence |
static long |
crc32(java.lang.CharSequence data)
Calculates crc32 on a char sequence |
static java.lang.String |
crcreport(byte[] data,
int step)
Returns a crc report on a byte array: a set of partial crc on chunks of data |
static java.lang.String |
crcreport(byte[] data,
int off,
int len,
int step)
Returns a crc report on a byte array: a set of partial crc on chunks of data |
static java.lang.String |
decode(byte[] bytes,
java.lang.String encoding)
Decodes an array of bytes using specified encoding |
static java.lang.String |
decode(java.io.InputStream is,
java.lang.String encoding)
Decodes a stream using specified encoding |
static java.lang.String |
decodeJavaString(java.lang.CharSequence string)
Decodes (and unescapes) a Java string. |
static byte[] |
encode(java.lang.CharSequence s,
java.lang.String encoding)
Encodes a char sequence using specified encoding |
static java.lang.String |
extractValue(java.lang.CharSequence input,
java.lang.CharSequence name)
Extracts value from a char sequence of format NAME="VALUE" |
static java.lang.String |
fill(char c,
int n)
Fills a string with a character |
static int |
findDiff(java.lang.CharSequence s1,
java.lang.CharSequence s2)
Finds index of the first difference between two char sequences |
static java.lang.String |
format(java.lang.String fmtString,
java.lang.Object param1)
Formats string with one parameter |
static java.lang.String |
format(java.lang.String fmtString,
java.lang.Object param1,
java.lang.Object param2)
Formats string with two parameters |
static java.lang.String |
format(java.lang.String fmtString,
java.lang.Object param1,
java.lang.Object param2,
java.lang.Object param3)
Formats string with three parameters |
static java.util.List |
grep(java.lang.CharSequence[] source,
java.lang.CharSequence regexp)
Perl operation grep. |
static java.util.List |
grep(java.lang.CharSequence[] source,
java.util.regex.Pattern regexp)
Perl operation grep. |
static boolean |
hasAlpha(java.lang.CharSequence s)
Checks whether a CharSequence contains any latin letters. |
static java.lang.String |
hexDump(byte[] data)
Hexadecimal dump of a byte array. |
static java.lang.String |
hexDump(char[] data)
Hexadecimal dump of a char array Produces neatly arranged lines of bot hex and ascii representation of bytes from the array. |
static java.lang.String |
hexDump(java.lang.CharSequence data)
Hexadecimal dump of a CharSequence Produces neatly arranged lines of bot hex and ascii representation of bytes from the array. |
static java.lang.String |
htmlEncode(java.lang.CharSequence s)
encodes a CharSequence into an HTML-acceptable format |
static int |
indexOf(java.lang.CharSequence s,
char c)
CharSequence version of indexOf |
static int |
indexOf(java.lang.CharSequence s,
char c,
int fromIndex)
CharSequence version of indexOf |
static int |
indexOf(java.lang.CharSequence sequence,
java.lang.CharSequence subsequence)
CharSequence version of indexOf |
static int |
indexOf(java.lang.CharSequence sequence,
java.lang.CharSequence subsequence,
int fromIndex)
CharSequence version of indexOf |
static boolean |
isAlmostEmpty(java.lang.CharSequence s)
Checks whether a CharSequence does not contain anything except whitespaces and the like. |
static boolean |
isAlpha(char c)
Deprecated. use Character.isJavaIdentifierStart(char) Examples: isAlpha('a'), isAlpha('O'), isAlpha('I'), isAlpha('l') return true;isAlpha('+'), isAlpha('0'), isAlpha('|'), isAlpha('1') return false. |
int |
isTrue(java.lang.String string)
Extracts logical value from a string |
static boolean |
isVowel(char c)
Checks whether a character is a latin vowel. |
static java.lang.String |
join(java.lang.CharSequence separator,
java.util.Collection collection)
Perl operation join. |
static java.lang.String |
join(java.lang.CharSequence separator,
java.lang.Object[] what)
Perl operation join. |
static int |
lastIndexOf(java.lang.CharSequence s,
char c)
CharSequence version of lastIndexOf |
static boolean |
needsEncoding(char c)
Checks whether a character needs encoding in Java |
static boolean |
needsEncoding(java.lang.CharSequence s)
Checks whether a CharSequence needs encoding in Java |
static java.lang.String |
oneOf(java.lang.Object o1,
java.lang.Object o2)
Chooses a string representation of a non-empty object out of two objects. |
static java.lang.String |
oneOf(java.lang.Object o1,
java.lang.Object o2,
java.lang.Object o3)
Chooses a string representation of a non-empty object out of three objects. |
static java.lang.String |
oneOf(java.lang.Object o1,
java.lang.Object o2,
java.lang.Object o3,
java.lang.Object o4)
Chooses a string representation of a non-empty object out of three objects. |
static java.lang.String |
pack(byte[] from)
Packs bytes into a string |
static java.lang.String |
replace(java.lang.CharSequence where,
java.lang.CharSequence oldSubstring,
java.lang.CharSequence newSubstring,
boolean all)
Replaces a subsequence in a char sequence with another subsequence |
static java.lang.String |
sgmlEntity(char c)
Encodes a character by SGML rules It can be a hex representation |
static java.util.List |
split(java.lang.CharSequence separator,
java.lang.CharSequence source)
Perl operation split. |
static boolean |
startsWith(java.lang.CharSequence sequence,
java.lang.CharSequence subsequence)
CharSequence version of startsWith |
static int |
textHeight(java.lang.CharSequence s)
Calculates how many lines the text contains. |
static int |
textWidth(java.lang.CharSequence s)
Calculates how many horizontal lines will the text take in a textarea. |
boolean |
toBoolean(java.lang.String string,
boolean defaultValue)
Extracts Boolean value from a string |
static java.lang.String |
toCEncoding(char c)
Converts a character to its C encoding (hex or escaped or intact) |
static java.lang.String |
toCEncoding(java.lang.CharSequence s)
Converts a CharSequence to its C encoding |
static java.lang.String |
toHex(byte b)
Converts a byte to hex string. |
static java.lang.String |
toHex(char ch)
Converts a char to hex string |
static java.lang.String |
toHex(char ch,
boolean up)
Converts a char to hex string |
static java.lang.String |
toHex(java.lang.CharSequence s,
boolean up)
Converts a CharSequence to hex string (character by character) |
static java.lang.String |
toHex(int i)
Converts an integer to hex string. |
static java.lang.String |
toHexReadable(byte[] data)
Converts an array of bytes to a readable hexadecimal form |
static java.lang.String |
toHexReadable(byte[] data,
int from,
int to)
Converts an array of chars to a readable hexadecimal form |
static java.lang.String |
toHexReadable(char[] data)
Converts an array of chars to a readable hexadecimal form |
static java.lang.String |
toHexReadable(java.lang.CharSequence s)
Converts a CharSequence to a readable hexadecimal string |
static java.lang.String |
toJavaEncoding(char c)
Converts a character to its Java encoding (hex or escaped or intact) |
static java.lang.String |
toJavaEncoding(char c,
boolean up)
Converts a character to its Java encoding (hex or escaped or intact) |
static java.lang.String |
toJavaEncoding(char c,
boolean up,
boolean escape)
Converts a character to its Java encoding (hex or escaped or intact) |
static java.lang.String |
toJavaEncoding(java.lang.CharSequence s)
Converts a CharSequence to its Java encoding (hex or escaped or intact, per char) |
static java.lang.String |
toJavaEncoding(java.lang.CharSequence s,
boolean up)
Converts a CharSequence to its Java encoding (hex or escaped or intact, per char) |
static java.lang.String |
toJavaEncoding(java.lang.CharSequence s,
boolean up,
boolean escape)
Converts a CharSequence to its Java encoding (hex or escaped or intact, per char) |
static java.lang.String |
toJavaHexEncoding(char c)
Converts a character to its Java hex encoding format: \\uxxxx |
static java.lang.String |
toJavaHexEncoding(char c,
boolean up)
Converts a character to its Java hex encoding format: \\uxxxx |
static java.lang.String |
toJavaOctalEncoding(char c)
Converts a character to its Java octal encoding format: \\o[o][o] |
static java.lang.String |
toPropertiesEncoding(char c)
Converts a character to how it should be represented in properties files |
static java.lang.String |
toPropertiesEncoding(char c,
boolean up)
Converts a character to how it should be represented in properties files |
static java.lang.String |
toReadable(char[] data,
int beginIndex,
int endIndex)
Converts a char array to a readable string. |
static java.lang.String |
toReadable(java.lang.CharSequence s)
Converts a CharSequence to a readable string. |
static java.lang.String |
toSgmlEncoding(char c)
Converts a character to its SGML numeric encoding |
static java.lang.String |
toSgmlEncoding(java.lang.CharSequence s)
Encodes a CharSequence by SGML rules (using predefined entities and numeric character encodings when necessary) |
static java.lang.String |
toString(java.lang.Throwable e)
Stringifies a Throwable, together with is stack trace. |
static java.lang.String[] |
toStrings(java.lang.Object object)
Converts an array to string array, per element |
static byte[] |
unpack(java.lang.CharSequence data)
Unpacks bytes packed in the char sequence |
static java.lang.String |
unzip(byte[] zippedBytes)
Unzips an array of bytes. |
static java.lang.String |
unzip(java.lang.CharSequence zipped)
Unzips a char sequence Does this: CharSequence -> High Unicode bytes -> unzip -> bytes -> UTF8 -> String |
static java.lang.String |
unzip(java.io.InputStream zippedStream)
Unzips a stream. |
static int |
wordCount(java.lang.CharSequence s)
Calculates the number of words in the CharSequence. |
static void |
write(java.io.Writer writer,
java.lang.CharSequence cs)
Writes CharSequence to Writer (Hello, Sun! |
static java.lang.String |
zip(java.lang.CharSequence source)
zips a char sequence to a string. |
static byte[] |
zip2bytes(java.lang.CharSequence source)
zip (like in zip files) a string producing an array of bytes |
static java.lang.String |
zip8bit(java.lang.CharSequence source)
zips a char sequence to a string of lower-byte chars. |
Methods inherited from class com.jaxfront.core.util.io.files.Objects |
---|
asMap, compose, crc32, crc32, getMap, getMap, getSet, indexOf, indexOf, indexOf, indexOf, inverse, isEmpty, map, map, map, map, map, reallocate, toBytes, toBytes, toChars, toMap, toMap, toMap, toMap, toSet |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ESCAPEE
public static final java.lang.String ESCAPED
public static final int _TRUE_
public static final int _FALSE_
public static final int _UNDEF_
Method Detail |
---|
public static int indexOf(java.lang.CharSequence s, char c, int fromIndex)
s
- CharSequencec
- charfromIndex
- int
public static int indexOf(java.lang.CharSequence s, char c)
s
- CharSequencec
- char
public static int lastIndexOf(java.lang.CharSequence s, char c)
s
- CharSequencec
- char
public static int indexOf(java.lang.CharSequence sequence, java.lang.CharSequence subsequence, int fromIndex)
sequence
- CharSequencesubsequence
- CharSequencefromIndex
- int
public static int indexOf(java.lang.CharSequence sequence, java.lang.CharSequence subsequence)
sequence
- CharSequencesubsequence
- CharSequence
public static boolean startsWith(java.lang.CharSequence sequence, java.lang.CharSequence subsequence)
sequence
- CharSequencesubsequence
- CharSequence
public static void write(java.io.Writer writer, java.lang.CharSequence cs) throws java.io.IOException
writer
- Writercs
- CharSequence
java.io.IOException
public static boolean isAlmostEmpty(java.lang.CharSequence s)
s
- the sequence to check
isAlmostEmpty(""), isAlmostEmpty(null), isAlmostEmpty("\n \r \n")
all return true;isAlmostEmpty("."), isAlmostEmpty("Contains data!")
returns false.public static java.lang.String oneOf(java.lang.Object o1, java.lang.Object o2)
o1
- the first candidateo2
- the second candidate
oneOf(null, "xyz")
returns "xyz";oneOf("abc", "xyz")
returns "abc";oneOf("", null)
return null;oneOf("abc", null)
returns "abc".public static java.lang.String oneOf(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
o1
- the first candidateo2
- the second candidateo3
- the third candidate
oneOf(null, "", "xyz")
returns "xyz";oneOf("abc", null, "xyz")
returns "abc";oneOf("", "def", null)
returns "def";oneOf("", null, "")
returns "".public static java.lang.String oneOf(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)
o1
- the first candidateo2
- the second candidateo3
- the third candidateo4
- the fourth candidate
oneOf(null, "", null, "xyz")
returns "xyz";oneOf("abc", null, "pqr", "xyz")
returns "abc";oneOf("", "def", null, "xyz")
returns "def";oneOf("", null, "", null)
returns null.public static boolean isAlpha(char c)
isAlpha('a'), isAlpha('O'), isAlpha('I'), isAlpha('l')
return true;isAlpha('+'), isAlpha('0'), isAlpha('|'), isAlpha('1')
return false.
c
- character to check
public static boolean isVowel(char c)
c
- the char to tests
public static boolean hasAlpha(java.lang.CharSequence s)
s
- CharSequence to check
hasAlpha("a"), hasAlpha("2OO2"), hasAlpha("This is a string")
return true;hasAlpha("+"), hasAlpha("1900"), hasAlpha("|1!*")
return false.public static int countChar(java.lang.CharSequence s, char c)
s
- the string to scanc
- the character to count
countChar("Goodness me, the clock has struck", 'o')
returns 3.public static int textHeight(java.lang.CharSequence s)
s
- the CharSequence with text
textHeight("One\nTwo\nThree")
returns 3;textHeight("\nOne\nTwo\nThree\n")
returns 5.public static int textWidth(java.lang.CharSequence s)
s
- the CharSequence with text
textWidth("One\nTwo\nThree")
returns 5.public static int wordCount(java.lang.CharSequence s)
s
- the CharSequence to analyze
wordCount("This is life!")
returns 3;wordCount("C'est la vie !")
returns 4, but for a wrong reason.public static int countLeadingSpaces(java.lang.CharSequence s)
s
-
countLeadingSpaces(" this is a string ")
returns 1.public static int countTrailingSpaces(java.lang.CharSequence s)
s
-
countTrailingSpaces(" this is a string ")
returns 3.public static java.lang.String fill(char c, int n)
c
- n
-
fill("*", 10)
returns "**********".public static java.lang.String toHex(byte b)
b
- the byte
toHex(155)
returns "9b".public static java.lang.String toHex(int i)
i
- the integer
toHex(1234)
returns "4d2".public static java.lang.String toHex(char ch, boolean up)
ch
- the charup
- if true, use upper case, otherwise lower
toHex('\u12bc', true)
returns "12BC";toHex('\u00af', false)
returns "00af".public static java.lang.String toHex(char ch)
ch
- the char
toHex('\u00af')
returns "00af".public static java.lang.String toHex(java.lang.CharSequence s, boolean up)
s
- the CharSequenceup
- if true, use upper case, otherwise lower
toHex("kl\u12bc", true)
returns "006B006C12BC";toHex("kl\u12bc", true)
returns "006b006c12bc".public static java.lang.String toJavaOctalEncoding(char c)
c
- the character
toJavaOctalEncoding('\n')
returns "\\12".public static java.lang.String toJavaHexEncoding(char c)
c
- the character
toJavaHexEncoding('\u00af')
returns "\\u00af".public static java.lang.String toJavaHexEncoding(char c, boolean up)
c
- the characterup
- if true, use upper case, otherwise lower
toJavaHexEncoding('\u00af', false)
returns "\\u00af".public static java.lang.String toPropertiesEncoding(char c, boolean up)
c
- the characterup
- if true, use upper case, otherwise lower
toPropertiesEncoding('\u00af', false)
returns "\\u00af";toPropertiesEncoding('\u00af', true)
returns "\\u00AF";toPropertiesEncoding('a', false)
returns "a".public static java.lang.String toPropertiesEncoding(char c)
c
- the character
toPropertiesEncoding('\u00af')
returns "\\u00af";toPropertiesEncoding('a')
returns "a".public static boolean needsEncoding(char c)
c
- the character
needsEncoding('\u00af')
returns true;needsEncoding('a')
returns false.public static java.lang.String toJavaEncoding(char c, boolean up, boolean escape)
c
- the characterup
- if true, use upper case, otherwise lowerescape
- if true, escape escapable characters
toJavaEncoding('\u00af', false, false)
returns "\\u00af";toJavaEncoding('\u000a', true, true)
returns "\\n";toJavaEncoding('\u000e', true, true)
returns "\\16";toJavaEncoding('a', true, true)
returns "a".public static java.lang.String toJavaEncoding(char c, boolean up)
c
- the characterup
- if true, use upper case, otherwise lower
toJavaEncoding('\u00af', false)
returns "\\u00af";toJavaEncoding('\u00af', true)
returns "\\u00AF";toJavaEncoding('\u000a', true)
returns "\\n";toJavaEncoding('\u000e', true)
returns "\\16";toJavaEncoding('a', true)
returns "a".public static java.lang.String toJavaEncoding(char c)
c
- the character
toJavaEncoding('\u00af')
returns "\\u00af";toJavaEncoding('\u000a')
returns "\\n";toJavaEncoding('\u000e')
returns "\\16";toJavaEncoding('a')
returns "a".public static java.lang.String toCEncoding(char c)
c
- the character
toCEncoding('\uabcd')
returns "\\xabcd";toCEncoding('\u00af')
returns "\\xaf";toCEncoding('\u000a')
returns "\\n";toCEncoding('a')
returns "a".public static boolean needsEncoding(java.lang.CharSequence s)
s
- the CharSequence
needsEncoding("Feliz Aņo Nuevo")
returns true;needsEncoding("Feliz Navedad")
returns false.public static java.lang.String toJavaEncoding(java.lang.CharSequence s, boolean up, boolean escape)
s
- the CharSequenceup
- if true, use upper case, otherwise lowerescape
- if true, escape escapable characters
toJavaEncoding("\nFeliz Aņo Nuevo\n", true, false)
returns "\u000AFeliz \u00A4o Nuevo\u000A";toJavaEncoding("\nFeliz Aņo Nuevo\n", true, true)
returns "\\nFeliz \u00A4o Nuevo\\n";toJavaEncoding("\nFeliz Aņo Nuevo\n\0", false, true)
returns "\\nFeliz \u00a4o Nuevo\\n\\0".public static java.lang.String toJavaEncoding(java.lang.CharSequence s, boolean up)
s
- the CharSequenceup
- if true, use upper case, otherwise lower
toJavaEncoding("\nFeliz Aņo Nuevo\n", true)
returns "\nFeliz \u00A4o Nuevo\n";toJavaEncoding("\nFeliz Aņo Nuevo\n\0", false)
returns "\\nFeliz \u00a4o Nuevo\\n\\0".public static java.lang.String toJavaEncoding(java.lang.CharSequence s)
s
- the CharSequence
toJavaEncoding("\nFeliz Aņo Nuevo\n\0")
returns "\\nFeliz A\u00f1o Nuevo\\n\\0".public static java.lang.String toCEncoding(java.lang.CharSequence s)
s
- the CharSequence
toCEncoding("\nFeliz Aņo Nuevo\n")
returns "\\nFeliz A\\x00f1o Nuevo\\n".public static java.lang.String toSgmlEncoding(char c)
c
- the character
toSgmlEncoding('\n')
returns " ".public static java.lang.String sgmlEntity(char c)
c
- the character
sgmlEntity('\60ab')
returns "悫" (that is, Numeric Character Reference);sgmlEntity('<')
returns "<" (that is, Predefined Entity);sgmlEntity('&')
returns "<" (that is, Predefined Entity);sgmlEntity('X')
returns null";sgmlEntity('\n')
returns null".public static java.lang.String toSgmlEncoding(java.lang.CharSequence s)
s
- the original CharSequence
toSgmlEncoding("Feliz Aņo Nuevo\n")
returns "<i>Feliz A¤o Nuevo</i>\n".public static java.lang.String htmlEncode(java.lang.CharSequence s)
s
- CharSequence original CharSequence
htmlEncode("Feliz Aņo Nuevo\n")
returns "Feliz A¤o Nuevo\n".public static java.lang.String toReadable(char[] data, int beginIndex, int endIndex)
data
- original char arraybeginIndex
- where to startendIndex
- where to end (before this position)
toReadable("\tĄHola seņor!\n".toCharArray(), 2, 12)
will return "..Hola se.or!.".public static java.lang.String toReadable(java.lang.CharSequence s)
s
- original CharSequence
toReadable("\tĄHola seņor!\n")
will return "..Hola se.or!.".public static java.lang.String hexDump(byte[] data)
data
- the data array
hexDump(new byte[] {1, 'a', 'b', '\n', 'c'})
will return
"\r\n01 61 62 0a 63 | . a b . c\r\n".public static java.lang.String hexDump(char[] data)
data
- the data array
hexDump(new char[] {1, 'a', 'b', '\n', 'c'})
will returnpublic static java.lang.String hexDump(java.lang.CharSequence data)
data
- the CharSequence
hexDump("ab\nc")
will return
"\r\n0001 0061 0062 000a 0063 | .ab.c".public static java.lang.String toHexReadable(char[] data)
data
- the data array
toHexReadable(new char[] {1, 'a', 'b', '\n', 'c'})
will return
"0001 0061 0062 000a 0063 \r\n".public static java.lang.String toHexReadable(byte[] data, int from, int to)
data
- the data arrayfrom
- beginning indexto
- ending index (not included)
toHexReadable(new byte[] {1, 2, 48}, 1, 3)
will return
"02 30 \r\n".public static java.lang.String toHexReadable(byte[] data)
data
- the data array
toHexReadable(new byte[] {1, 2, 48})
will return
"01 02 30 ".public static java.lang.String toHexReadable(java.lang.CharSequence s)
s
- the data CharSequence
toHexReadable("ab\nc")
will return
"0001 0061 0062 000a 0063 \r\n".public static java.lang.String join(java.lang.CharSequence separator, java.util.Collection collection)
separator
- the separator CharSequence * @param collection the collection of objects to join
HashSet a = new HashSet();
List b = new ArrayList(); b.add("entry1"); b.add("entry2");
join(", ", a)
returns "";
join(", ", b)
returns "entry1, entry2".
public static java.lang.String join(java.lang.CharSequence separator, java.lang.Object[] what)
separator
- the separatorwhat
- the array of objects to join
join(", ", new Long[] {new Long(1), new Long(555)})
returns "1, 555";join(" and ", new String[] {"Here", "there", "everywhere"})
returns "Here and there and everywhere".public static java.util.List split(java.lang.CharSequence separator, java.lang.CharSequence source)
separator
- separator character sequencesource
- source character sequence
see java.lang.String.split(String)
Example:
split(":", "a:ab:abcde:")
returns a list containing four elements, "a", "ab", "abcde", "".
public static java.util.List grep(java.lang.CharSequence[] source, java.lang.CharSequence regexp) throws java.util.regex.PatternSyntaxException
source
- source arrayregexp
- expression to match
grep(new String[] {"good", "bad", "ugly"}, "g."))
returns a list containing two elements: "good", "ugly".
- Throws:
java.util.regex.PatternSyntaxException
public static java.util.List grep(java.lang.CharSequence[] source, java.util.regex.Pattern regexp)
source
- source arrayregexp
- expression to match
grep(new String[] {"good", "bad", "ugly"}, Pattern.compile("g.")))
returns a list containing two elements: "good", "ugly".
public static java.lang.String replace(java.lang.CharSequence where, java.lang.CharSequence oldSubstring, java.lang.CharSequence newSubstring, boolean all)
where
- the string containing the substrings to replaceoldSubstring
- what to replacenewSubstring
- with what to replaceall
- if true, all (nonintersecting) substrings are replaced,
otherwise only one
replace("God loves you", "love", "hate", true)
returns "God hates you";replace("All you need is love, love!", "me", false)
returns "All you need is me, love!".public static java.lang.String extractValue(java.lang.CharSequence input, java.lang.CharSequence name)
input
- sequence of the aforementioned formatname
- the name on the left side of '='
extractValue("java.home=\"c:\\java\\jdk1.4.1\"\nx=\"abcd\"", "x")
returns "abcd";extractValue("java.home=\|c:\\java\\jdk1.4.1\"\nx=\"abcd\"", "java.home")
returns "c:\\java\\jdk1.4.1".public static java.lang.String pack(byte[] from)
from
- byte array
pack(new byte[] {0x23, 0x67, (byte)0xab, (byte)0xef})
returns "??".public static byte[] unpack(java.lang.CharSequence data)
data
- the packed data
unpack("??")
returns new byte[] {0x23, 0x67, (byte)0xab, (byte)0xef}.pack(byte[])
public static java.lang.String decodeJavaString(java.lang.CharSequence string)
string
- as presented in the source code
decodeJavaString("This is a string")
returns "This is a string";decodeJavaString("\\nFeliz \\u00A4o Nuevo\\n")
returns "\nFeliz Aņo Nuevo\n".public static byte[] encode(java.lang.CharSequence s, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
s
- char sequence to encodeencoding
- the name of encoding
java.io.IOException
- when something goes wrong with bytearray streams
java.io.UnsupportedEncodingException
- when encoding is unknown
encode("Aņo Nuevo", "UTF8")
returns new byte[] {0x41, (byte)0xc3, (byte)0xb1, 0x6f, 0x20, 0x4e, 0x75, 0x65, 0x76, 0x6f};encode("Aņo Nuevo", "MacRoman")
returns new byte[] {0x41, (byte)0x96, 0x6f, 0x20, 0x4e, 0x75, 0x65, 0x76, 0x6f}.public static java.lang.String decode(java.io.InputStream is, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
is
- stream to decodeencoding
- the name of encoding
java.io.IOException
- when something goes wrong with bytearray streams
java.io.UnsupportedEncodingException
- when encoding is unknownpublic static java.lang.String decode(byte[] bytes, java.lang.String encoding) throws java.io.IOException, java.io.UnsupportedEncodingException
bytes
- byte arrayencoding
- the name of encoding
java.io.IOException
- when something goes wrong with bytearray streams
java.io.UnsupportedEncodingException
- when encoding is unknown
decode(new byte[] {0x41, (byte)0xc3, (byte)0xb1, 0x6f, 0x20, 0x4e, 0x75, 0x65, 0x76, 0x6f}, "UTF8")
returns "Aņo Nuevo";encode( new byte[] {0x41, (byte)0x96, 0x6f, 0x20, 0x4e, 0x75, 0x65, 0x76, 0x6f}, "MacRoman")
returns "Aņo Nuevo".public static byte[] zip2bytes(java.lang.CharSequence source) throws java.io.IOException, java.io.UnsupportedEncodingException
source
- the string to zip
java.io.IOException
- when something goes wrong with streams
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
zip2bytes("Hello World")
returns new byte[] {0x78, (byte)0xda, (byte)0xf3, 0x48, (byte)0xcd, (byte)0xc9, (byte)0xc9, 0x57, (byte)0x08, (byte)0xcf, 0x2f, (byte)0xca, 0x49, 0x01, 0x00, 0x18, 0x0b, 0x04, 0x1d, 0x00}.public static java.lang.String zip8bit(java.lang.CharSequence source) throws java.io.IOException, java.io.UnsupportedEncodingException
source
- char sequence to zip
java.io.IOException
- when something goes wrong with streams
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
zip8bit("Hello World")
returns "xÚķHÍÉÉW\bĪ/ĘI ".public static java.lang.String zip(java.lang.CharSequence source) throws java.io.IOException, java.io.UnsupportedEncodingException
source
- char sequence to zip
java.io.IOException
- when something goes wrong with streams
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
zip("Hello World")
returns "?????????".public static java.lang.String unzip(java.io.InputStream zippedStream) throws java.io.IOException, java.io.UnsupportedEncodingException
zippedStream
-
java.io.IOException
- when something goes fishy
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8public static java.lang.String unzip(byte[] zippedBytes) throws java.io.IOException, java.io.UnsupportedEncodingException
zippedBytes
-
java.io.IOException
- when something goes fishy
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
unzip(new byte[] {0x78, (byte)0xda, (byte)0xf3, 0x48, (byte)0xcd, (byte)0xc9, (byte)0xc9, 0x57, 0x08, (byte)0xcf, 0x2f, (byte)0xca, 0x49, 0x01, 0x00, 0x18, 0x0b, 0x04, 0x1d, 0x00})
returns "Hello World".public static java.lang.String unzip(java.lang.CharSequence zipped) throws java.io.IOException, java.io.UnsupportedEncodingException
zipped
-
java.io.IOException
- when something goes fishy
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
unzip("?????????")
returns "Hello World".public static long crc32(java.lang.CharSequence data) throws java.io.IOException, java.io.UnsupportedEncodingException
data
- source char sequence
java.io.IOException
- when something goes wrong with streams
java.io.UnsupportedEncodingException
- when JDK forgets that it knows UTF8
crc32("Hello World")
returns 2178450716l.public static java.lang.String crcreport(byte[] data, int off, int len, int step)
data
- source bytesoff
- offset in the arraylen
- length of the area to crcstep
- chunk size
public static java.lang.String crcreport(byte[] data, int step)
data
- source bytesstep
- chunk size
public static java.lang.String[] toStrings(java.lang.Object object)
object
- the expected array
toStrings(new Object[] { new Integer(22), new Boolean(false), "wow"})
returns new String[] {"22", "false", "wow"}.public static java.lang.String toString(java.lang.Throwable e)
e
- the throwable to convert to string
try {
prints
String s = null;
s.toString();
} catch (Exception e) {
System.out.println(toString(e));
}
java.lang.NullPointerException
at com.myjavatools.util.TestStrings
public static java.lang.String format(java.lang.String fmtString, java.lang.Object param1)
fmtString
- param1
-
format("{0} Monkeys", new Long(12))
returns "12 Monkeys".public static java.lang.String format(java.lang.String fmtString, java.lang.Object param1, java.lang.Object param2)
fmtString
- param1
- param2
-
format("{0} is {1}", "Life", "struggle")
returns "Life is struggle".public static java.lang.String format(java.lang.String fmtString, java.lang.Object param1, java.lang.Object param2, java.lang.Object param3)
fmtString
- param1
- param2
- param3
-
format("{0} + {1} = {2}", new Byte(2), new Byte(2), new Long(5))
returns "2 + 2 = 5".public static java.util.Properties asProperties(java.lang.String[] pairs)
pairs
- the source array
asProperties(new String[] {"1", "one", "2", "two", "3", "three"})
returns properties with three keys ("1", "2", "3"), and guess which values.
public static int findDiff(java.lang.CharSequence s1, java.lang.CharSequence s2)
s1
- s2
-
findDiff("abcd", "abec")
returns 2;findDiff("abc", "abc")
returns -1;findDiff("ab", null)
returns 0.findDiff("", " ")
returns 0.public int isTrue(java.lang.String string)
string
-
isTrue("YeS")
returns _TRUE_;isTrue("false")
returns _FALSE_;isTrue(null)
returns _UNDEF_.public boolean toBoolean(java.lang.String string, boolean defaultValue)
string
- defaultValue
-
toBoolean("YeS", false)
returns true;toBoolean("false", false)
returns false;toBoolean(null, true)
returns true.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |