Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Waging war on electronic junk mail

Put Java on the front line in the war against electronic junk mail

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 2 of 2

In order to provide all of you with workable code, and to show how the APIs have changed, I've provided code in three packages. The energetic among you are encouraged to download them all and compare them. The rest of you should download the package appropriate for your platform.

The first package works with Java 1.0.2. It is available as a gzipped tar file and as a zip file.

The second package works with Java 1.1. Is is also available as a gzipped tar file and as a zip file.

The third package works with both Java 1.0.2 and Java 1.1. This package doesn't use the conflicting parts of the APIs; it does the work itself. Those of you interested in portability might want to look here. Of course, you can download the package as either a gzipped tar file or as a zip file.

The code this month doesn't run as an applet, so you'll need access to the Java Development Kit or a similar command-line environment.

First, using a method appropriate for your system, unpack the downloaded file.

Next, from the command line, execute the Java runtime as follows:

 % java Main [keyword] [keyword] ... < [email file]


You may specify any number of keywords on the command line. The program builds a filter for each of the keywords and links the filters together -- into a stream. The input is expected to arrive on standard input. The program will read from standard input, send the data through the stream, and write to standard output. If any of the filters detect a match on their keyword, they will raise an exception which will stop the program.

Very simple, yet extremely useful and very effective.

Conclusion

Next month we'll dive right in and take a look at the the character-oriented input and output streams: class Reader and class Writer. I'll show you how they work alongside class InputStream and class OutputStream. I'll also talk briefly about character encodings in preparation for a glance at Java internationalization.

See you next month.

About the author

Todd Sundsted has been writing programs since computers became available in convenient desktop models. Though originally interested in building distributed applications in C++, Todd moved to the Java programming language when it became the obvious choice for that sort of thing. Todd is co-author of the Java Language API SuperBible. In addition to writing, Todd is president of Etcee, which offers Java-centric training, mentoring, and consulting.
  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • The InputStream class for Java 1.0.2 http://java.sun.com/products/jdk/1.0.2/api/java.io.InputStream.html
  • The OutputStream class for Java 1.0.2 http://java.sun.com/products/jdk/1.0.2/api/java.io.OutputStream.html
  • The InputStream class for Java 1.1 http://www.javasoft.com/products/jdk/1.1/docs/api/java.io.InputStream.html
  • The OutputStream class for Java 1.1 http://www.javasoft.com/products/jdk/1.1/docs/api/java.io.OutputStream.html
  • I/O Enhancements for Java 1.1 http://www.javasoft.com/products/jdk/1.1/docs/guide/io/index.html
  • Previous How-To Java articles