net.sf.asyncobjects.io
Class EncoderTextOutput

java.lang.Object
  extended by net.sf.asyncobjects.AsyncUnicastServer<FacetType>
      extended by net.sf.asyncobjects.util.CloseableWrapper<ATextOutput,AByteOutput>
          extended by net.sf.asyncobjects.io.EncoderTextOutput
All Implemented Interfaces:
ACloseable, AsyncObject, ExplicitSharing, AOutput<TextData>, ATextOutput

public class EncoderTextOutput
extends CloseableWrapper<ATextOutput,AByteOutput>
implements ATextOutput

An output that encodes the text into binary. The encoder uses an instance of BufferProvider for buffer management.

Author:
const

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.asyncobjects.util.CloseableWrapper
CloseableWrapper.InvalidatingWhen<I,R>
 
Field Summary
 
Fields inherited from class net.sf.asyncobjects.util.CloseableWrapper
closeWrapper, requests, wrapped
 
Constructor Summary
EncoderTextOutput(BufferProvider buffers, CharsetEncoder encoder, AByteOutput out, boolean closeStream)
          A constructor
EncoderTextOutput(CharsetEncoder encoder, AByteOutput out, boolean closeStream)
          A constructor
EncoderTextOutput(String encoding, AByteOutput out)
          A constructor
 
Method Summary
protected  Promise<Void> beforeClose()
          Handle close operation
 Promise<Void> flush()
          Flush data in stream, upon return of this method all data will be written out to most underlying layer
 void onMalformedInput(CodingErrorAction newAction)
          Configure encoder to execute specifed action on malformed input
 void onUnmappableCharacter(CodingErrorAction newAction)
          Configure encoder to execute specifed action on unmappable character
 void replaceWith(byte[] newReplacement)
          Specify replacement
 Promise<Void> write(TextData data)
          Encode data
 
Methods inherited from class net.sf.asyncobjects.util.CloseableWrapper
afterInvalidate, close, closed, ensureOpen, ensureValid, invalidate, isValid
 
Methods inherited from class net.sf.asyncobjects.AsyncUnicastServer
dereference, export, isImmediate, myVat, promise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asyncobjects.ACloseable
close
 
Methods inherited from interface net.sf.asyncobjects.AsyncObject
dereference, isImmediate
 

Constructor Detail

EncoderTextOutput

public EncoderTextOutput(String encoding,
                         AByteOutput out)
A constructor

Parameters:
encoding - an encoding id
out - an output stream

EncoderTextOutput

public EncoderTextOutput(CharsetEncoder encoder,
                         AByteOutput out,
                         boolean closeStream)
A constructor

Parameters:
encoder - an encoder
out - an output stream
closeStream - if true the stream must be closed

EncoderTextOutput

public EncoderTextOutput(BufferProvider buffers,
                         CharsetEncoder encoder,
                         AByteOutput out,
                         boolean closeStream)
A constructor

Parameters:
buffers - a buffer provider
encoder - an encoder
out - an output stream
closeStream - if true the stream must be closed
Method Detail

onMalformedInput

public void onMalformedInput(CodingErrorAction newAction)
Configure encoder to execute specifed action on malformed input

Parameters:
newAction - a new action

onUnmappableCharacter

public void onUnmappableCharacter(CodingErrorAction newAction)
Configure encoder to execute specifed action on unmappable character

Parameters:
newAction - a new action

replaceWith

public void replaceWith(byte[] newReplacement)
Specify replacement

Parameters:
newReplacement - a new replacement

flush

public Promise<Void> flush()
Description copied from interface: AOutput
Flush data in stream, upon return of this method all data will be written out to most underlying layer

Specified by:
flush in interface AOutput<TextData>
Returns:
a promise that will resolve when data will be written out
See Also:
AOutput.flush()

write

public Promise<Void> write(TextData data)
Encode data

Specified by:
write in interface AOutput<TextData>
Parameters:
data - a data to encode
Returns:
when encoding and writing is finished
See Also:
AOutput.write(net.sf.asyncobjects.io.BatchedData)

beforeClose

protected Promise<Void> beforeClose()
                             throws Throwable
Description copied from class: CloseableWrapper
Handle close operation

Overrides:
beforeClose in class CloseableWrapper<ATextOutput,AByteOutput>
Returns:
a promise that resolves when handling close is finished
Throws:
Throwable - if there is aproblem during execution
See Also:
CloseableWrapper.beforeClose()


Copyright 2002-2007 Constantine Plotnikov. All Rights Reserved.