Design Patterns Java™ Workbook

(Michael S) #1
Chapter 27. Decorator

Figure 27.3. The Oozinoz filters can decorate a Writer object with behaviors that
manipulate ad copy text for a Web site.

For example, the WrapFilter class compresses whitespace and wraps text at a specified
line length. (The contents of WrapFilter.java and all the filter classes are available at
oozinoz.com.) The following program line-wraps text in an input file and puts it in title case:


package com.oozinoz.applications;
import java.io.;
import com.oozinoz.io.
;
public class ShowFilters
{
public static void main(String args[])
throws IOException
{
BufferedReader in =
new BufferedReader(new FileReader(args[0]));


Writer out = new FileWriter(args[1]);
out = new WrapFilter(new BufferedWriter(out), 40);
out = new TitleCaseFilter(out);

Free download pdf