org.exoplatform.commons.utils
Class OutputStreamPrinter

java.lang.Object
  extended by java.io.Writer
      extended by org.exoplatform.commons.utils.Printer
          extended by org.exoplatform.commons.utils.OutputStreamPrinter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class OutputStreamPrinter
extends Printer

An extension of Printer that encodes the text with a provided encoder and sends the resulting bytes on an OutputStream. The instance can be configured to have different behavior on failure of the output stream.

The ignoreOnFailure property will stop to make further invocations to the output stream if an exception is thrown by the output stream except for the close() method.

The failureFlow property modifies the control flow of the method invocation when the output stream throws an IOException.

Version:
$Revision$
Author:
Julien Viet

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
OutputStreamPrinter(TextEncoder encoder, OutputStream out)
          Builds an instance with the failureFlow being IOFailureFlow.RETHROW and a the ignoreOnFailure property set to false.
OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow failureFlow, boolean ignoreOnFailure)
          Builds a new instance.
 
Method Summary
 void close()
           
 void flush()
           
 IOFailureFlow getFailureFlow()
          Returns the failure flow.
 boolean getIgnoreOnFailure()
          Returns the ignore on failure property.
 boolean isFailed()
           
 void write(char[] cbuf)
           
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 void write(String str)
           
 void write(String str, int off, int len)
           
 
Methods inherited from class org.exoplatform.commons.utils.Printer
print, println, println
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OutputStreamPrinter

public OutputStreamPrinter(TextEncoder encoder,
                           OutputStream out)
                    throws IllegalArgumentException
Builds an instance with the failureFlow being IOFailureFlow.RETHROW and a the ignoreOnFailure property set to false.

Parameters:
encoder - the encoder
out - the output
Throws:
IllegalArgumentException - if any argument is null

OutputStreamPrinter

public OutputStreamPrinter(TextEncoder encoder,
                           OutputStream out,
                           IOFailureFlow failureFlow,
                           boolean ignoreOnFailure)
                    throws IllegalArgumentException
Builds a new instance.

Parameters:
encoder - the encoder
out - the output
failureFlow - the control flow failureFlow
ignoreOnFailure - the behavior on failure
Throws:
IllegalArgumentException - if any argument is null
Method Detail

getFailureFlow

public IOFailureFlow getFailureFlow()
Returns the failure flow.

Returns:
the failure flow

getIgnoreOnFailure

public boolean getIgnoreOnFailure()
Returns the ignore on failure property.

Returns:
the ignore on failure property

isFailed

public boolean isFailed()

write

public void write(int c)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

write

public void write(String str,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class Writer
Throws:
IOException

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 © 2009 eXo Platform SAS. All Rights Reserved.