net.sf.mmm.util.io.base
Class EscapeWriter

java.lang.Object
  extended by java.io.Writer
      extended by net.sf.mmm.util.io.base.EscapeWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class EscapeWriter
extends Writer

This is a wrapper for a writer that allows to map specific characters to a escape sequences given a strings.
The mapping table for escaping is given as string array.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
EscapeWriter(Object, String[], Writer)

Field Summary
private  String[] characterEscapingTable
          A table that maps chars (as index) to escape sequences.
private  Writer writer
          the actual writer
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
EscapeWriter(Object syncLock, String[] charEscapeTable, Writer plainWriter)
          The constructor.
EscapeWriter(String[] charEscapeTable, Writer plainWriter)
          The constructor.
 
Method Summary
 void close()
          
 void flush()
          
 void write(char[] cbuf, int off, int len)
          
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

characterEscapingTable

private final String[] characterEscapingTable
A table that maps chars (as index) to escape sequences.


writer

private final Writer writer
the actual writer

Constructor Detail

EscapeWriter

public EscapeWriter(String[] charEscapeTable,
                    Writer plainWriter)
The constructor.

Parameters:
charEscapeTable - is a String array that maps characters by to escape sequences. If the numeric representation of a character is a legal index for the given array and the String at that index is null that string is written instead of the character. In all other cases, the character is written without change.
plainWriter - is the writer that is wrapped.
See Also:
EscapeWriter(Object, String[], Writer)

EscapeWriter

public EscapeWriter(Object syncLock,
                    String[] charEscapeTable,
                    Writer plainWriter)
The constructor.

Parameters:
syncLock - is an explicit lock object used for synchronization (see Writer.Writer(java.lang.Object)).
charEscapeTable - is a String array that maps characters by to escape sequences. If the numeric representation of a character is a legal index for the given array and the String at that index is NOT null that string is written instead of the character. In all other cases, the character is written without change.
plainWriter - is the writer that is wrapped.
Method Detail

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException

Specified by:
write in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

close

public void close()
           throws IOException

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException


Copyright © 2001-2010 mmm-Team. All Rights Reserved.