I don't know of a string handling package like that, but here's
code for two of your wish list items. I won't vouch for these being the
fastest possible, but they work.
> Another question: most of the event model stuff I can find seems
> geared towards GUIs.
The Beans property change event model has nothing specific to GUIs.
It works quite well for general event notification. And there's a
level more abstract than that if necessary, just code your own event
objects and event listeners. Those won't cross JVM boundaries
automatically but it's not hard to code.
Rod McChesney, Korobra
/**
* Read the full contents of a file and return them as an array of
* bytes. Length is limited to <code>Integer.MAX_VALUE</code> bytes.
*/
public static byte[] readWholeFile(File file) throws IOException {
long length = file.length();
if (length >= Integer.MAX_VALUE) {
throw new IOException(
"File is too big to read: " + (length / 1024) + " kb");
}
byte buf[] = new byte[(int)length];
FileInputStream in = new FileInputStream(file);
in.read(buf, 0, (int)length);
return buf;
}
/**
* Read the full contents of a file and return them as a string.
* Length is limited to <code>Integer.MAX_VALUE</code> bytes.
*/
public static String readFileIntoString(File file)
throws IOException
{
return new String(TypeUtil.readWholeFile(file));
}
/**
* Replace all occurences of a string with another string.
*/
public static String replace(
String inputString,
String findString,
String replaceWithString
) {
StringBuffer sb = new StringBuffer();
int index = -1;
int start = 0;
int findLength = findString.length();
// Loop over occurrences of string to replace.
while ((index = inputString.indexOf(findString, start)) != -1) {
sb.append(inputString.substring(start, index));
sb.append(replaceWithString);
start = index + findLength;
}
// Add the rest.
sb.append(inputString.substring(start));
return sb.toString();
}
Steven J. Owens wrote:
>
> Hey folks,
>
> I'm wondering what class libraries there are out there, that are
> commonly accepted as useful to have around for servlet programming.
> Specifically, is there any more convenient string class?
>
> I'm aware of the three or so regexp libraries (two under GNU
> license at http://www.cacas.org/~wes/java and
> http://www.crocodile.org/~sts/Rex, and the ORO regexp and perltool
> originally at www.oro.com but that looks gone...). I'm thinking in
> terms of just a generally handier class with various convenience
> methods. For example, one convenience method (and this is a reach,
> but) takes a filename and opens and reads the file into the string.
> Another does simple string substitution. Not rocket science, but
> handy.
>
> Another question: most of the event model stuff I can find seems
> geared towards GUIs. I've found myself wanting to implement some sort
> of "event/listener" scheme for use with servlets, specifically for a
> centralized logging system spanning a servlet engine and several RMI
> servers running on another system. Any pointers to a more general
> event model?
>
> If you needed to implement some sort of general logging system as
> above, how would you go about it?
>
> Steven J. Owens
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html