Package org.exoplatform.commons.utils
Class OutputStreamPrinter
java.lang.Object
java.io.Writer
org.exoplatform.commons.utils.Printer
org.exoplatform.commons.utils.OutputStreamPrinter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable,BinaryOutput
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.
failureFlow property modifies the control flow of the method invocation when the output stream throws an
IOException.
- The
IOFailureFlow.IGNOREvalue ignores the exception. - The
IOFailureFlow.RETHROWvalue rethrows the exception. - The
IOFailureFlow.THROW_UNDECLAREDvalue throws instead aUndeclaredIOExceptionexception wrapping the original exception.
The class provides direct write access to the underlying output stream when the client of the stream can provides bytes directly.
- Version:
- $Revision$
- Author:
- Julien Viet
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionOutputStreamPrinter(TextEncoder encoder, OutputStream out) Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose) Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose, int bufferSize) Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose, int bufferSize, boolean growing) Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow failureFlow, boolean ignoreOnFailure, boolean flushOnClose, int bufferSize) Builds a new instance with the specified parameters and the delegate output.OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow failureFlow, boolean ignoreOnFailure, boolean flushOnClose, int bufferSize, boolean growing) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()final voidflush()voidFlush the output stream.final Charsetfinal IOFailureFlowReturns the failure flow.final booleanReturns the ignore on failure property.final booleanisFailed()final voidwrite(byte b) final voidwrite(byte[] bytes) final voidwrite(byte[] bytes, int off, int len) final voidwrite(char[] cbuf) final voidwrite(char[] cbuf, int off, int len) final voidwrite(int c) final voidfinal voidMethods inherited from class java.io.Writer
append, append, append, nullWriter
-
Constructor Details
-
OutputStreamPrinter
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose) throws IllegalArgumentException Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.- Parameters:
encoder- the encoderout- the outputflushOnClose- flush when stream is closed- Throws:
IllegalArgumentException- if any argument is null
-
OutputStreamPrinter
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose, int bufferSize) throws IllegalArgumentException Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.- Parameters:
encoder- the encoderout- the outputflushOnClose- flush when stream is closedbufferSize- the size of the buffer- Throws:
IllegalArgumentException- if any argument is null
-
OutputStreamPrinter
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, boolean flushOnClose, int bufferSize, boolean growing) throws IllegalArgumentException Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.- Parameters:
encoder- the encoderout- the outputflushOnClose- flush when stream is closedbufferSize- the initial size of the buffergrowing- if the buffer should grow in size once full- Throws:
IllegalArgumentException- if any argument is null
-
OutputStreamPrinter
Builds an instance with the failureFlow beingIOFailureFlow.RETHROWand a the ignoreOnFailure property set to false.- Parameters:
encoder- the encoderout- the output- Throws:
IllegalArgumentException- if any argument is null
-
OutputStreamPrinter
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow failureFlow, boolean ignoreOnFailure, boolean flushOnClose, int bufferSize) throws IllegalArgumentException Builds a new instance with the specified parameters and the delegate output.- Parameters:
encoder- the encoderout- the outputfailureFlow- the control flow failureFlowignoreOnFailure- the behavior on failureflushOnClose- flush when stream is closedbufferSize- the buffer size- Throws:
IllegalArgumentException- if any argument is null
-
OutputStreamPrinter
public OutputStreamPrinter(TextEncoder encoder, OutputStream out, IOFailureFlow failureFlow, boolean ignoreOnFailure, boolean flushOnClose, int bufferSize, boolean growing) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
-
Method Details
-
getCharset
- Specified by:
getCharsetin interfaceBinaryOutput
-
getFailureFlow
Returns the failure flow.- Returns:
- the failure flow
-
getIgnoreOnFailure
public final boolean getIgnoreOnFailure()Returns the ignore on failure property.- Returns:
- the ignore on failure property
-
isFailed
public final boolean isFailed() -
write
- Specified by:
writein interfaceBinaryOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceBinaryOutput- Throws:
IOException
-
write
- Specified by:
writein interfaceBinaryOutput- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Specified by:
writein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flushOutputStream
Flush the output stream. This allows for the outputstream to be independently flushed regardless of the flushOnClose setting.- Throws:
IOException
-